Re: [PATCH v2 3/3] commit: show interesting ident information in summary
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 17, 2010, 08:59 UTC
- Message-ID
- <7vhbql85ti.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <20100113173951.GC16786@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 37 quoted lines
> @@ -1046,9 +1058,12 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
> {
> struct rev_info rev;
> struct commit *commit;
> - static const char *format = "format:%h] %s";
> + struct strbuf format = STRBUF_INIT;
> unsigned char junk_sha1[20];
> const char *head = resolve_ref("HEAD", junk_sha1, 0, NULL);
> + struct pretty_print_context pctx = {0};
> + struct strbuf author_ident = STRBUF_INIT;
> + struct strbuf committer_ident = STRBUF_INIT;
>
> commit = lookup_commit(sha1);
> if (!commit)
> @@ -1056,6 +1071,23 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
> if (!commit || parse_commit(commit))
> die("could not parse newly created commit");
>
> + strbuf_addstr(&format, "format:%h] %s");
> + ...
> + if (strbuf_cmp(&author_ident, &committer_ident)) {
> + strbuf_addstr(&format, "\n Author: ");
> + strbuf_addbuf_percentquote(&format, &author_ident);
> + }
> + if (!user_ident_explicitly_given) {
> + strbuf_addstr(&format, "\n Committer: ");
> + strbuf_addbuf_percentquote(&format, &committer_ident);
> + strbuf_addch(&format, '\n');
> + strbuf_addstr(&format, implicit_ident_advice);
> + }
> + ...
> - get_commit_format(format, &rev);
> + get_commit_format(format.buf, &rev);
> + strbuf_release(&format);
> rev.always_show_header = 0;
> rev.diffopt.detect_rename = 1;
> rev.diffopt.rename_limit = 100;This prepares the user format for log_tree_commit(); get_commit_format() copies it away in its userformat, so it appears we are done with format strbuf we built, and we release...
Show 7 quoted lines
> @@ -1085,7 +1118,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
> struct pretty_print_context ctx = {0};
> struct strbuf buf = STRBUF_INIT;
> ctx.date_mode = DATE_NORMAL;
> - format_commit_message(commit, format + 7, &buf, &ctx);
> + format_commit_message(commit, format.buf + 7, &buf, &ctx);
> printf("%s\n", buf.buf);But sometimes log_tree_commit() doesn't show the header. Most notably for merges. What string are we using for format_commit_message()? Oops.
diff --git a/builtin-commit.c b/builtin-commit.c index a73a532..7f61e87 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -1013,7 +1013,6 @@ static void print_summary(const char *prefix, const unsigned char *sha1) rev.verbose_header = 1; rev.show_root_diff = 1; get_commit_format(format.buf, &rev); - strbuf_release(&format); rev.always_show_header = 0; rev.diffopt.detect_rename = 1; rev.diffopt.rename_limit = 100; @@ -1036,6 +1035,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1) printf("%s\n", buf.buf); strbuf_release(&buf); } + strbuf_release(&format); } static int git_commit_config(const char *k, const char *v, void *cb)