git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 5/5] pretty: Respect --abbrev option

From
Jonathan Nieder <jrnieder@gmail.com>
Date
May 4, 2010, 08:34 UTC
Message-ID
<20100504083421.GA8338@progeny.tock>
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);
Previous: Jonathan NiederNext: Clemens Buchacher
Message 15 of 16 in “What's cooking in git.git (May 2010, #01; Sun, 2)”
  1. Junio C HamanoMay 2, 2010
  2. Johannes SixtMay 2, 2010
  3. 1/2 Have set_try_to_free_routine return the previous routineJohannes Sixt, May 8, 2010
  4. 2/2 Do not call release_pack_memory in malloc wrappers when GIT_TRACE is usedJohannes Sixt, May 8, 2010
  5. Jakub NarebskiMay 3, 2010
  6. Will PalmerMay 3, 2010
  7. jn/shortlog (Re: What's cooking in git.git (May 2010, #01; Sun, 2))Jonathan Nieder, May 4, 2010
  8. Jonathan NiederMay 4, 2010
  9. 0/5 jn/shortlogJonathan Nieder, May 4, 2010
  10. 1/5 Documentation/shortlog: scripted users should not rely on implicit HEADJonathan Nieder, May 4, 2010
  11. 2/5 t4201 (shortlog): guard setup with test_expect_successJonathan Nieder, May 4, 2010
  12. 3/5 t4201 (shortlog): Test output format with multiple authorsJonathan Nieder, May 4, 2010
  13. 4/5 shortlog: Document and test --format optionJonathan Nieder, May 4, 2010
  14. 5/5 pretty: Respect --abbrev optionJonathan Nieder, May 4, 2010
  15. Jonathan NiederMay 4, 2010
  16. Clemens BuchacherMay 8, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.