public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Adam Megacz <adam@megacz•com>
To: git@vger•kernel.org
Subject: [PATCH] Display author and committer after "git commit"
Date: Mon, 11 Jan 2010 04:37:44 +0000	[thread overview]
Message-ID: <xuu2fx6d9rzb.fsf_-_@nowhere.com> (raw)
In-Reply-To: 7vskagh9fg.fsf@alter.siamese.dyndns.org


Display author (name, email, date) and committer (name, email, date)
after creating a new commit to ensure that the user is alerted in the
event that they are set in an undesirable manner.

This patch seeks to accomplish the following goal: all data included
in the commit which are sha1-protected (and therefore immutable) are
either taken from the working tree or else displayed to the user for
sanity checking purposes.  Since the author/committer information is
immutable and not taken from the working tree, achieving the goal
above requires printing out the author/committer.  The short window of
time after committing a patch and before propagating it is the last
opportunity to modify the data (by deleting and recreating the commit).

This patch is not necessarily meant for inclusion verbatim; it's more
of a starting point for discussion.
---
 commit.h   |    2 ++
 log-tree.c |   15 +++++++++++++++
 pretty.c   |   23 ++++++++++++++++++-----
 3 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/commit.h b/commit.h
index e5332ef..e4222b0 100644
--- a/commit.h
+++ b/commit.h
@@ -59,6 +59,8 @@ enum cmit_fmt {
 	CMIT_FMT_ONELINE,
 	CMIT_FMT_EMAIL,
 	CMIT_FMT_USERFORMAT,
+        CMIT_FMT_COMMITTER_AND_DATE,
+        CMIT_FMT_AUTHOR_AND_DATE,
 
 	CMIT_FMT_UNSPECIFIED,
 };
diff --git a/log-tree.c b/log-tree.c
index 0fdf159..7b399b8 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -160,6 +160,20 @@ static void append_signoff(struct strbuf *sb, const char *signoff)
 	strbuf_addch(sb, '\n');
 }
 
+static void append_metadata(struct strbuf *sb,
+                            struct commit *commit,
+                            const struct pretty_print_context *ctx)
+{
+
+	strbuf_addch(sb, '\n');
+	strbuf_addstr(sb, " Author:     ");
+        pretty_print_commit(CMIT_FMT_AUTHOR_AND_DATE, commit, sb, ctx);
+
+	strbuf_addch(sb, '\n');
+	strbuf_addstr(sb, " Committer:  ");
+        pretty_print_commit(CMIT_FMT_COMMITTER_AND_DATE, commit, sb, ctx);
+}
+
 static unsigned int digits_in_number(unsigned int number)
 {
 	unsigned int i = 10, result = 1;
@@ -414,6 +428,7 @@ void show_log(struct rev_info *opt)
 	ctx.reflog_info = opt->reflog_info;
 	pretty_print_commit(opt->commit_format, commit, &msgbuf, &ctx);
 
+        append_metadata(&msgbuf, commit, &ctx);
 	if (opt->add_signoff)
 		append_signoff(&msgbuf, opt->add_signoff);
 	if (opt->show_log_size) {
diff --git a/pretty.c b/pretty.c
index 8f5bd1a..2458509 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1028,16 +1028,26 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
 	int need_8bit_cte = context->need_8bit_cte;
 
 	if (fmt == CMIT_FMT_USERFORMAT) {
-		format_commit_message(commit, user_format, sb, context);
+                format_commit_message(commit, user_format, sb, context);
 		return;
 	}
+        if (fmt == CMIT_FMT_COMMITTER_AND_DATE) {
+                format_commit_message(commit, "%cn <%ce> %cd", sb, context);
+                return;
+        }
+        if (fmt == CMIT_FMT_AUTHOR_AND_DATE) {
+                format_commit_message(commit, "%an <%ae> %ad", sb, context);
+                return;
+        }
 
 	reencoded = reencode_commit_message(commit, &encoding);
 	if (reencoded) {
 		msg = reencoded;
 	}
 
-	if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)
+
+	if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL ||
+            fmt == CMIT_FMT_COMMITTER_AND_DATE || CMIT_FMT_AUTHOR_AND_DATE)
 		indent = 0;
 
 	/*
@@ -1078,12 +1088,14 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
 			      context->after_subject, encoding, need_8bit_cte);
 
 	beginning_of_body = sb->len;
-	if (fmt != CMIT_FMT_ONELINE)
+	if (fmt != CMIT_FMT_ONELINE &&
+            fmt != CMIT_FMT_COMMITTER_AND_DATE && fmt != CMIT_FMT_AUTHOR_AND_DATE)
 		pp_remainder(fmt, &msg, sb, indent);
 	strbuf_rtrim(sb);
 
 	/* Make sure there is an EOLN for the non-oneline case */
-	if (fmt != CMIT_FMT_ONELINE)
+	if (fmt != CMIT_FMT_ONELINE &&
+            fmt != CMIT_FMT_COMMITTER_AND_DATE && fmt != CMIT_FMT_AUTHOR_AND_DATE)
 		strbuf_addch(sb, '\n');
 
 	/*
@@ -1094,7 +1106,8 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
 	if (fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
 		strbuf_addch(sb, '\n');
 
-	if (fmt != CMIT_FMT_ONELINE)
+	if (fmt != CMIT_FMT_ONELINE &&
+            fmt != CMIT_FMT_COMMITTER_AND_DATE && fmt != CMIT_FMT_AUTHOR_AND_DATE)
 		get_commit_notes(commit, sb, encoding,
 				 NOTES_SHOW_HEADER | NOTES_INDENT);
 
-- 
1.6.4.4

  parent reply	other threads:[~2010-01-11  4:38 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             ` Adam Megacz [this message]
2010-01-11  4:53               ` [PATCH] Display author and committer after "git commit" Adam Megacz
2010-01-11  7:28               ` Junio C Hamano
2010-01-12  1:51                 ` Adam Megacz
2010-01-12 14:24                   ` Jeff King
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=xuu2fx6d9rzb.fsf_-_@nowhere.com \
    --to=adam@megacz$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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