From: Jeff King <peff@peff.net>
To: Adam Megacz <adam@megacz.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Display author and committer after "git commit"
Date: Tue, 12 Jan 2010 09:24:06 -0500 [thread overview]
Message-ID: <20100112142405.GA13369@coredump.intra.peff.net> (raw)
In-Reply-To: <xuu2zl4kks3s.fsf@nowhere.com>
On Tue, Jan 12, 2010 at 01:51:51AM +0000, Adam Megacz wrote:
> Junio C Hamano <gitster@pobox.com> writes:
> > Why isn't the "# Author:" and "# Committer:" information you see along
> > with "git status" output in the editor "git commit" gives you sufficient
> > if it is to avoid unconfigured/misconfigured names and e-mail
> > addresses?
>
> It is sufficient! But, as others have mentioned, it is not displayed
> when "git commit -m" is used. The patch in this thread rectifies that
> omission.
I think it is sensible to reiterate the information in the summary for
the "interesting" cases, as it does make it available to people who do
not see the template, and as the uncommon case, is not usually
cluttering the output.
But I don't understand why the original patch needed to touch anything
outside of builtin-commit.c:print_summary. Something like this should
work (though see below for why it isn't ready for inclusion):
diff --git a/builtin-commit.c b/builtin-commit.c
index 1e353f6..6ee6b10 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -1054,9 +1054,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)
@@ -1064,6 +1067,22 @@ 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");
+
+ format_commit_message(commit, "%an <%ae>", &author_ident, &pctx);
+ format_commit_message(commit, "%cn <%ce>", &committer_ident, &pctx);
+ if (strbuf_cmp(&author_ident, &committer_ident)) {
+ int i;
+ strbuf_addstr(&format, "\n Author: ");
+ for (i = 0; i < author_ident.len; i++) {
+ if (author_ident.buf[i] == '%')
+ strbuf_addch(&format, '%');
+ strbuf_addch(&format, author_ident.buf[i]);
+ }
+ }
+ strbuf_release(&author_ident);
+ strbuf_release(&committer_ident);
+
init_revisions(&rev, prefix);
setup_revisions(0, NULL, &rev, NULL);
@@ -1074,7 +1093,8 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
rev.verbose_header = 1;
rev.show_root_diff = 1;
- 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;
@@ -1093,7 +1113,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);
strbuf_release(&buf);
}
It's not appropriate for inclusion because:
- I didn't actually test it beyond "GIT_AUTHOR_NAME=Foo git commit
-m". I think what the code does is correct, but it may be breaking
output in the test suite.
- It tries to quote any percents in the author name, but user formats
don't actually have a quoting mechanism! Probably we should
interpret "%%" as "%". Even though it's a behavior change, I
consider the current behavior buggy.
Side note: it feels a little hack-ish that I have to actually use a
user-format to get the author and committer. But we don't seem to
have any infrastructure for something as simple as "give me a string
with the author name of this commit".
- It only handles author != committer as interesting. We should also
check user_ident_explicitly_given and show the committer in that
case, as the editor template does.
-Peff
next prev parent reply other threads:[~2010-01-12 14:24 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-03 23:32 edit Author/Date metadata as part of 'git commit' $EDITOR invocation? Adam Megacz
2010-01-04 20:32 ` Sverre Rabbelier
2010-01-04 21:08 ` Adam Megacz
2010-01-04 22:52 ` Sverre Rabbelier
2010-01-05 20:22 ` David Aguilar
2010-01-05 22:38 ` Nanako Shiraishi
2010-01-06 17:04 ` Junio C Hamano
2010-01-08 7:35 ` Adam Megacz
2010-01-08 16:02 ` Junio C Hamano
2010-01-08 16:03 ` [PATCH 1/3] ident.c: remove unused variables Junio C Hamano
2010-01-08 16:04 ` [PATCH 2/3] ident.c: check explicit identity for name and email separately Junio C Hamano
2010-01-08 22:33 ` Santi Béjar
2010-01-08 16:08 ` [RFC PATCH 3/3] ident.c: treat $EMAIL as giving user.email identity explicitly Junio C Hamano
2010-01-11 4:37 ` [PATCH] Display author and committer after "git commit" Adam Megacz
2010-01-11 4:53 ` Adam Megacz
2010-01-11 7:28 ` Junio C Hamano
2010-01-12 1:51 ` Adam Megacz
2010-01-12 14:24 ` Jeff King [this message]
2010-01-12 14:52 ` Jeff King
2010-01-12 15:36 ` Jeff King
2010-01-12 15:41 ` [PATCH 1/3] strbuf_expand: convert "%%" to "%" Jeff King
2010-01-12 15:41 ` [PATCH 2/3] strbuf: add strbuf_percentquote_buf Jeff King
2010-01-12 16:19 ` Johannes Schindelin
2010-01-12 16:18 ` Jeff King
2010-01-13 6:55 ` Junio C Hamano
2010-01-13 17:06 ` Jeff King
2010-01-13 19:47 ` Junio C Hamano
2010-01-13 19:56 ` Jeff King
2010-01-12 15:46 ` [PATCH 3/3] commit: show interesting ident information in summary Jeff King
2010-01-13 6:57 ` Junio C Hamano
2010-01-13 17:30 ` Jeff King
2010-01-13 19:48 ` Junio C Hamano
2010-01-13 20:17 ` Jeff King
2010-01-13 20:18 ` Jeff King
2010-01-13 20:50 ` Junio C Hamano
2010-01-13 17:34 ` [PATCH] Display author and committer after "git commit" Jeff King
2010-01-13 17:35 ` [PATCH v2 1/3] strbuf_expand: convert "%%" to "%" Jeff King
2010-01-14 11:47 ` Chris Johnsen
2010-01-14 14:32 ` Jeff King
2010-01-13 17:36 ` [PATCH v2 2/3] strbuf: add strbuf_addbuf_percentquote Jeff King
2010-01-13 17:39 ` [PATCH v2 3/3] commit: show interesting ident information in summary Jeff King
2010-01-13 18:39 ` Wincent Colaiuta
2010-01-13 18:45 ` Jeff King
2010-01-13 18:50 ` Wincent Colaiuta
2010-01-14 15:02 ` Thomas Rast
2010-01-14 19:04 ` Felipe Contreras
2010-01-14 19:15 ` Junio C Hamano
2010-01-14 19:36 ` Felipe Contreras
2010-01-14 19:44 ` Junio C Hamano
2010-01-15 1:21 ` Felipe Contreras
2010-01-16 2:56 ` Adam Megacz
2010-01-17 11:31 ` Matthieu Moy
2010-01-17 8:59 ` Junio C Hamano
2010-01-17 16:18 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100112142405.GA13369@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=adam@megacz.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).