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

[PATCH 4/7] fmt-merge-msg: use pretty.c routines

From
Stephen Boyd <bebarino@gmail.com>
Date
Mar 24, 2010, 07:16 UTC
Message-ID
<1269414964-9518-5-git-send-email-bebarino@gmail.com>
In-Reply-To
<1269414964-9518-1-git-send-email-bebarino@gmail.com>

This command duplicates functionality of the '%s' pretty format. Simplify the code a bit by using the pretty printing routine instead of open-coding it here.

Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---
 builtin/fmt-merge-msg.c |   29 ++++++++---------------------
 1 files changed, 8 insertions(+), 21 deletions(-)
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 9bb2625..44b74f4 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -185,6 +185,7 @@ static void shortlog(const char *name, unsigned char *sha1,
 	struct object *branch;
 	struct list subjects = { NULL, NULL, 0, 0 };
 	int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
+	struct strbuf sb = STRBUF_INIT;
 
 	branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40);
 	if (!branch || branch->type != OBJ_COMMIT)
@@ -198,7 +199,7 @@ static void shortlog(const char *name, unsigned char *sha1,
 	if (prepare_revision_walk(rev))
 		die("revision walk setup failed");
 	while ((commit = get_revision(rev)) != NULL) {
-		char *oneline, *bol, *eol;
+		struct pretty_print_context ctx = {0};
 
 		/* ignore merges */
 		if (commit->parents && commit->parents->next)
@@ -208,30 +209,16 @@ static void shortlog(const char *name, unsigned char *sha1,
 		if (subjects.nr > limit)
 			continue;
 
-		bol = strstr(commit->buffer, "\n\n");
-		if (bol) {
-			unsigned char c;
-			do {
-				c = *++bol;
-			} while (isspace(c));
-			if (!c)
-				bol = NULL;
-		}
+		format_commit_message(commit, "%s", &sb, &ctx);
+		strbuf_ltrim(&sb);
 
-		if (!bol) {
+		if (!sb.len)
 			append_to_list(&subjects, xstrdup(sha1_to_hex(
 							commit->object.sha1)),
 					NULL);
-			continue;
-		}
-
-		eol = strchr(bol, '\n');
-		if (eol) {
-			oneline = xmemdupz(bol, eol - bol);
-		} else {
-			oneline = xstrdup(bol);
-		}
-		append_to_list(&subjects, oneline, NULL);
+		else
+			append_to_list(&subjects, strbuf_detach(&sb, NULL),
+					NULL);
 	}
 
 	if (count > limit)
-- 
1.7.0.3.254.g4503b
Previous: Stephen BoydNext: Stephen Boyd
Message 7 of 17 in “fmt-merge-msg improvements”
  1. 0/7 fmt-merge-msg improvementsStephen Boyd, Mar 24, 2010
  2. 1/7 fmt-merge-msg: be quiet if nothing to mergeStephen Boyd, Mar 24, 2010
  3. Junio C HamanoMar 25, 2010
  4. Stephen BoydMar 25, 2010
  5. 2/7 t6200: modernize with test_tickStephen Boyd, Mar 24, 2010
  6. 3/7 t6200: test fmt-merge-msg moreStephen Boyd, Mar 24, 2010
  7. 4/7 fmt-merge-msg: use pretty.c routinesStephen Boyd, Mar 24, 2010
  8. 5/7 string-list: add unsorted_string_list_lookup()Stephen Boyd, Mar 24, 2010
  9. 6/7 fmt-merge-msg: remove custom string_list implementationStephen Boyd, Mar 24, 2010
  10. Junio C HamanoMar 30, 2010
  11. Stephen BoydApr 1, 2010
  12. 8/7 Make string_list_append() consistent with everything elseStephen Boyd, Apr 1, 2010
  13. Julian PhillipsApr 1, 2010
  14. 7/7 fmt-merge-msg: hide summary optionStephen Boyd, Mar 24, 2010
  15. Junio C HamanoMar 25, 2010
  16. Stephen BoydMar 25, 2010
  17. Junio C HamanoMar 26, 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.