diff options
Diffstat (limited to 'builtin/fmt-merge-msg.c')
-rw-r--r-- | builtin/fmt-merge-msg.c | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index e2e27b2c40..3906eda877 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -109,7 +109,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents) if (len < 43 || line[40] != '\t') return 1; - if (!prefixcmp(line + 41, "not-for-merge")) + if (starts_with(line + 41, "not-for-merge")) return 0; if (line[41] != '\t') @@ -155,16 +155,16 @@ static int handle_line(char *line, struct merge_parents *merge_parents) if (pulling_head) { origin = src; src_data->head_status |= 1; - } else if (!prefixcmp(line, "branch ")) { + } else if (starts_with(line, "branch ")) { origin_data->is_local_branch = 1; origin = line + 7; string_list_append(&src_data->branch, origin); src_data->head_status |= 2; - } else if (!prefixcmp(line, "tag ")) { + } else if (starts_with(line, "tag ")) { origin = line; string_list_append(&src_data->tag, origin + 4); src_data->head_status |= 2; - } else if (!prefixcmp(line, "remote-tracking branch ")) { + } else if (starts_with(line, "remote-tracking branch ")) { origin = line + strlen("remote-tracking branch "); string_list_append(&src_data->r_branch, origin); src_data->head_status |= 2; @@ -232,8 +232,9 @@ static void record_person(int which, struct string_list *people, { char *name_buf, *name, *name_end; struct string_list_item *elem; - const char *field = (which == 'a') ? "\nauthor " : "\ncommitter "; + const char *field; + field = (which == 'a') ? "\nauthor " : "\ncommitter "; name = strstr(commit->buffer, field); if (!name) return; @@ -286,10 +287,10 @@ static void credit_people(struct strbuf *out, const char *me; if (kind == 'a') { - label = "\n# By "; + label = "By"; me = git_author_info(IDENT_NO_DATE); } else { - label = "\n# Via "; + label = "Via"; me = git_committer_info(IDENT_NO_DATE); } @@ -299,7 +300,7 @@ static void credit_people(struct strbuf *out, (me = skip_prefix(me, them->items->string)) != NULL && skip_prefix(me, " <"))) return; - strbuf_addstr(out, label); + strbuf_addf(out, "\n%c %s ", comment_line_char, label); add_people_count(out, them); } @@ -323,7 +324,8 @@ static void add_people_info(struct strbuf *out, static void shortlog(const char *name, struct origin_data *origin_data, struct commit *head, - struct rev_info *rev, int limit, + struct rev_info *rev, + struct fmt_merge_msg_opts *opts, struct strbuf *out) { int i, count = 0; @@ -335,6 +337,7 @@ static void shortlog(const char *name, int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED; struct strbuf sb = STRBUF_INIT; const unsigned char *sha1 = origin_data->sha1; + int limit = opts->shortlog_len; branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40); if (!branch || branch->type != OBJ_COMMIT) @@ -351,13 +354,15 @@ static void shortlog(const char *name, if (commit->parents && commit->parents->next) { /* do not list a merge but count committer */ - record_person('c', &committers, commit); + if (opts->credit_people) + record_person('c', &committers, commit); continue; } - if (!count) + if (!count && opts->credit_people) /* the 'tip' committer */ record_person('c', &committers, commit); - record_person('a', &authors, commit); + if (opts->credit_people) + record_person('a', &authors, commit); count++; if (subjects.nr > limit) continue; @@ -372,7 +377,8 @@ static void shortlog(const char *name, string_list_append(&subjects, strbuf_detach(&sb, NULL)); } - add_people_info(out, &authors, &committers); + if (opts->credit_people) + add_people_info(out, &authors, &committers); if (count > limit) strbuf_addf(out, "\n* %s: (%d commits)\n", name, count); else @@ -464,7 +470,7 @@ static void fmt_tag_signature(struct strbuf *tagbuf, strbuf_complete_line(tagbuf); if (sig->len) { strbuf_addch(tagbuf, '\n'); - strbuf_add_lines(tagbuf, "# ", sig->buf, sig->len); + strbuf_add_commented_lines(tagbuf, sig->buf, sig->len); } } @@ -486,7 +492,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out) if (size == len) ; /* merely annotated */ - else if (verify_signed_buffer(buf, len, buf + len, size - len, &sig)) { + else if (verify_signed_buffer(buf, len, buf + len, size - len, &sig, NULL)) { if (!sig.len) strbuf_addstr(&sig, "gpg verification failed.\n"); } @@ -497,14 +503,18 @@ static void fmt_merge_msg_sigs(struct strbuf *out) } else { if (tag_number == 2) { struct strbuf tagline = STRBUF_INIT; - strbuf_addf(&tagline, "\n# %s\n", - origins.items[first_tag].string); + strbuf_addch(&tagline, '\n'); + strbuf_add_commented_lines(&tagline, + origins.items[first_tag].string, + strlen(origins.items[first_tag].string)); strbuf_insert(&tagbuf, 0, tagline.buf, tagline.len); strbuf_release(&tagline); } - strbuf_addf(&tagbuf, "\n# %s\n", - origins.items[i].string); + strbuf_addch(&tagbuf, '\n'); + strbuf_add_commented_lines(&tagbuf, + origins.items[i].string, + strlen(origins.items[i].string)); fmt_tag_signature(&tagbuf, &sig, buf, len); } strbuf_release(&sig); @@ -595,7 +605,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out, resolve_refdup("HEAD", head_sha1, 1, NULL); if (!current_branch) die("No current branch"); - if (!prefixcmp(current_branch, "refs/heads/")) + if (starts_with(current_branch, "refs/heads/")) current_branch += 11; find_merge_parents(&merge_parents, in, head_sha1); @@ -635,7 +645,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out, for (i = 0; i < origins.nr; i++) shortlog(origins.items[i].string, origins.items[i].util, - head, &rev, opts->shortlog_len, out); + head, &rev, opts, out); } strbuf_complete_line(out); @@ -690,6 +700,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix) memset(&opts, 0, sizeof(opts)); opts.add_title = !message; + opts.credit_people = 1; opts.shortlog_len = shortlog_len; ret = fmt_merge_msg(&input, &output, &opts); |