git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Boyd <bebarino@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 4/7] fmt-merge-msg: use pretty.c routines
Date: Wed, 24 Mar 2010 00:16:01 -0700	[thread overview]
Message-ID: <1269414964-9518-5-git-send-email-bebarino@gmail.com> (raw)
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

  parent reply	other threads:[~2010-03-24  7:17 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-24  7:15 [PATCH 0/7] fmt-merge-msg improvements Stephen Boyd
2010-03-24  7:15 ` [PATCH 1/7] fmt-merge-msg: be quiet if nothing to merge Stephen Boyd
2010-03-25  2:39   ` Junio C Hamano
2010-03-25  3:48     ` Stephen Boyd
2010-03-24  7:15 ` [PATCH 2/7] t6200: modernize with test_tick Stephen Boyd
2010-03-24  7:16 ` [PATCH 3/7] t6200: test fmt-merge-msg more Stephen Boyd
2010-03-24  7:16 ` Stephen Boyd [this message]
2010-03-24  7:16 ` [PATCH 5/7] string-list: add unsorted_string_list_lookup() Stephen Boyd
2010-03-24  7:16 ` [PATCH 6/7] fmt-merge-msg: remove custom string_list implementation Stephen Boyd
2010-03-30  5:18   ` Junio C Hamano
2010-04-01  6:08     ` Stephen Boyd
2010-04-01  6:29     ` [PATCH 8/7] Make string_list_append() consistent with everything else Stephen Boyd
2010-04-01 20:07       ` Julian Phillips
2010-03-24  7:16 ` [PATCH 7/7] fmt-merge-msg: hide summary option Stephen Boyd
2010-03-25  2:45   ` Junio C Hamano
2010-03-25  5:19     ` Stephen Boyd
2010-03-26 19:30       ` Junio C Hamano

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=1269414964-9518-5-git-send-email-bebarino@gmail.com \
    --to=bebarino@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).