git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Will Palmer <wmpalmer@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH 5/5] pretty: Respect --abbrev option
Date: Tue, 4 May 2010 03:34:21 -0500	[thread overview]
Message-ID: <20100504083421.GA8338@progeny.tock> (raw)
In-Reply-To: <20100504031856.GF7322@progeny.tock>

Jonathan Nieder wrote:

> Subject: [PATCH 5/5] pretty: Respect --abbrev option
[...]
> Signed-off-by: Will Palmer <wmpalmer@gmail.com>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>

This patch was by Will Palmer <wmpalmer@gmail.com> (except two
of the tests).  Since I don’t use ‘git send-email’, I keep
forgetting to include the From: pseudo-header.

Sorry for the trouble,
Jonathan

diff --git a/pretty.c b/pretty.c
index 1430616..e5dea91 100644
--- a/pretty.c
+++ b/pretty.c
@@ -908,6 +908,7 @@ static void pp_header(enum cmit_fmt fmt,
 		      const char *encoding,
 		      const struct commit *commit,
 		      const char **msg_p,
+		      const char **author_p,
 		      struct strbuf *sb)
 {
 	int parents_shown = 0;
@@ -954,6 +955,8 @@ static void pp_header(enum cmit_fmt fmt,
 		 * FULLER shows both authors and dates.
 		 */
 		if (!memcmp(line, "author ", 7)) {
+			if (author_p)
+				*author_p = line + 7;
 			strbuf_grow(sb, linelen + 80);
 			pp_user_info("Author", fmt, sb, line + 7, dmode, encoding);
 		}
@@ -1004,6 +1007,22 @@ void pp_title_line(enum cmit_fmt fmt,
 	strbuf_release(&title);
 }
 
+static void pp_in_body_author(struct strbuf *sb,
+			      const char *author_line)
+{
+	const char *author_end, *sender;
+
+	author_end = strchr(author_line, '>') + 1;
+	sender = git_author_info(IDENT_NO_DATE);
+	if (!strncmp(author_line, sender, author_end - author_line))
+		return;
+
+	strbuf_addstr(sb, "From: ");
+	strbuf_add(sb, author_line, author_end - author_line);
+	strbuf_addch(sb, '\n');
+	strbuf_addch(sb, '\n');
+}
+
 void pp_remainder(enum cmit_fmt fmt,
 		  const char **msg_p,
 		  struct strbuf *sb,
@@ -1057,6 +1076,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
 	unsigned long beginning_of_body;
 	int indent = 4;
 	const char *msg = commit->buffer;
+	const char *author = NULL;
 	char *reencoded;
 	const char *encoding;
 	int need_8bit_cte = context->need_8bit_cte;
@@ -1082,15 +1102,13 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
 		int i, ch, in_body;
 
 		for (in_body = i = 0; (ch = msg[i]); i++) {
-			if (!in_body) {
-				/* author could be non 7-bit ASCII but
-				 * the log may be so; skip over the
-				 * header part first.
-				 */
-				if (ch == '\n' && msg[i+1] == '\n')
-					in_body = 1;
-			}
-			else if (non_ascii(ch)) {
+			/*
+			 * If the author is non 7-bit ASCII but
+			 * the log is 7bit, we still need a
+			 * Content-type field, in case an in-body
+			 * From: line is required.
+			 */
+			if (non_ascii(ch)) {
 				need_8bit_cte = 1;
 				break;
 			}
@@ -1098,7 +1116,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
 	}
 
 	pp_header(fmt, context->abbrev, context->date_mode, encoding,
-		  commit, &msg, sb);
+		  commit, &msg, &author, sb);
 	if (fmt != CMIT_FMT_ONELINE && !context->subject) {
 		strbuf_addch(sb, '\n');
 	}
@@ -1111,6 +1129,9 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
 		pp_title_line(fmt, &msg, sb, context->subject,
 			      context->after_subject, encoding, need_8bit_cte);
 
+	if (fmt == CMIT_FMT_EMAIL)
+		pp_in_body_author(sb, author);
+
 	beginning_of_body = sb->len;
 	if (fmt != CMIT_FMT_ONELINE)
 		pp_remainder(fmt, &msg, sb, indent);
-- 

  reply	other threads:[~2010-05-04  8:34 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-02 16:12 What's cooking in git.git (May 2010, #01; Sun, 2) Junio C Hamano
2010-05-02 20:01 ` Johannes Sixt
2010-05-08 15:13   ` [PATCH 1/2] Have set_try_to_free_routine return the previous routine Johannes Sixt
2010-05-08 15:18     ` [PATCH 2/2] Do not call release_pack_memory in malloc wrappers when GIT_TRACE is used Johannes Sixt
2010-05-03 12:48 ` What's cooking in git.git (May 2010, #01; Sun, 2) Jakub Narebski
2010-05-03 18:54 ` Will Palmer
2010-05-04  0:25   ` jn/shortlog (Re: What's cooking in git.git (May 2010, #01; Sun, 2)) Jonathan Nieder
2010-05-04  1:56     ` jn/shortlog Jonathan Nieder
2010-05-04  2:52       ` [PATCH v2 0/5] jn/shortlog Jonathan Nieder
2010-05-04  2:57         ` [PATCH 1/5] Documentation/shortlog: scripted users should not rely on implicit HEAD Jonathan Nieder
2010-05-04  2:57         ` [PATCH 2/5] t4201 (shortlog): guard setup with test_expect_success Jonathan Nieder
2010-05-04  2:58         ` [PATCH 3/5] t4201 (shortlog): Test output format with multiple authors Jonathan Nieder
2010-05-04  2:59         ` [PATCH 4/5] shortlog: Document and test --format option Jonathan Nieder
2010-05-04  3:18         ` [PATCH 5/5] pretty: Respect --abbrev option Jonathan Nieder
2010-05-04  8:34           ` Jonathan Nieder [this message]
2010-05-08 16:43 ` What's cooking in git.git (May 2010, #01; Sun, 2) Clemens Buchacher

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=20100504083421.GA8338@progeny.tock \
    --to=jrnieder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=wmpalmer@gmail.com \
    /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).