| 4092 | } |
| 4093 | |
| 4094 | static int commit_match(struct commit *commit, struct rev_info *opt) |
| 4095 | { |
| 4096 | int retval; |
| 4097 | const char *encoding; |
| 4098 | const char *message; |
| 4099 | struct strbuf buf = STRBUF_INIT; |
| 4100 | |
| 4101 | if (!opt->grep_filter.pattern_list && !opt->grep_filter.header_list) |
| 4102 | return 1; |
| 4103 | |
| 4104 | /* Prepend "fake" headers as needed */ |
| 4105 | if (opt->grep_filter.use_reflog_filter) { |
| 4106 | strbuf_addstr(&buf, "reflog "); |
| 4107 | get_reflog_message(&buf, opt->reflog_info); |
| 4108 | strbuf_addch(&buf, '\n'); |
| 4109 | } |
| 4110 | |
| 4111 | /* |
| 4112 | * We grep in the user's output encoding, under the assumption that it |
| 4113 | * is the encoding they are most likely to write their grep pattern |
| 4114 | * for. In addition, it means we will match the "notes" encoding below, |
| 4115 | * so we will not end up with a buffer that has two different encodings |
| 4116 | * in it. |
| 4117 | */ |
| 4118 | encoding = get_log_output_encoding(); |
| 4119 | message = repo_logmsg_reencode(the_repository, commit, NULL, encoding); |
| 4120 | |
| 4121 | /* Copy the commit to temporary if we are using "fake" headers */ |
| 4122 | if (buf.len) |
| 4123 | strbuf_addstr(&buf, message); |
| 4124 | |
| 4125 | if (opt->grep_filter.header_list && opt->mailmap) { |
| 4126 | const char *commit_headers[] = { "author ", "committer ", NULL }; |
| 4127 | |
| 4128 | if (!buf.len) |
| 4129 | strbuf_addstr(&buf, message); |
| 4130 | |
| 4131 | apply_mailmap_to_header(&buf, commit_headers, opt->mailmap); |
| 4132 | } |
| 4133 | |
| 4134 | /* Append "fake" message parts as needed */ |
| 4135 | if (opt->show_notes) { |
| 4136 | if (!buf.len) |
| 4137 | strbuf_addstr(&buf, message); |
| 4138 | format_display_notes(&commit->object.oid, &buf, encoding, 1); |
| 4139 | } |
| 4140 | |
| 4141 | /* |
| 4142 | * Find either in the original commit message, or in the temporary. |
| 4143 | * Note that we cast away the constness of "message" here. It is |
| 4144 | * const because it may come from the cached commit buffer. That's OK, |
| 4145 | * because we know that it is modifiable heap memory, and that while |
| 4146 | * grep_buffer may modify it for speed, it will restore any |
| 4147 | * changes before returning. |
| 4148 | */ |
| 4149 | if (buf.len) |
| 4150 | retval = grep_buffer(&opt->grep_filter, buf.buf, buf.len); |
| 4151 | else |
no test coverage detected