[POC PATCH 4/9] pretty: refactor add_merge_info() into parts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



pp_commit_list() will be reused later.

Signed-off-by: Thomas Rast <tr@xxxxxxxxxxxxx>
---

Necessary only for the next patch, which may be of dubious value.

 commit.h |  1 +
 pretty.c | 40 ++++++++++++++++++++++++++--------------
 2 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/commit.h b/commit.h
index 16d9c43..b51817b 100644
--- a/commit.h
+++ b/commit.h
@@ -101,6 +101,7 @@ struct pretty_print_context {
 	struct string_list *mailmap;
 	int color;
 	struct ident_split *from_ident;
+	struct commit_list *merge_bases;
 
 	/*
 	 * Fields below here are manipulated internally by pp_* functions and
diff --git a/pretty.c b/pretty.c
index 87db08b..5e44cf8 100644
--- a/pretty.c
+++ b/pretty.c
@@ -517,6 +517,31 @@ static const char *skip_empty_lines(const char *msg)
 	return msg;
 }
 
+static const char *pp_sha1_to_hex(const struct pretty_print_context *pp,
+				  const unsigned char *sha1)
+{
+	const char *hex = NULL;
+	if (pp->abbrev)
+		hex = find_unique_abbrev(sha1, pp->abbrev);
+	if (!hex)
+		hex = sha1_to_hex(sha1);
+	return hex;
+}
+
+static void pp_commit_list(const struct pretty_print_context *pp,
+			   struct strbuf *sb,
+			   const char *prefix,
+			   const struct commit_list *list)
+{
+	strbuf_addstr(sb, prefix);
+	while (list) {
+		struct commit *commit = list->item;
+		strbuf_addf(sb, " %s", pp_sha1_to_hex(pp, commit->object.sha1));
+		list = list->next;
+	}
+	strbuf_addch(sb, '\n');
+}
+
 static void add_merge_info(const struct pretty_print_context *pp,
 			   struct strbuf *sb, const struct commit *commit)
 {
@@ -526,20 +551,7 @@ static void add_merge_info(const struct pretty_print_context *pp,
 	    !parent || !parent->next)
 		return;
 
-	strbuf_addstr(sb, "Merge:");
-
-	while (parent) {
-		struct commit *p = parent->item;
-		const char *hex = NULL;
-		if (pp->abbrev)
-			hex = find_unique_abbrev(p->object.sha1, pp->abbrev);
-		if (!hex)
-			hex = sha1_to_hex(p->object.sha1);
-		parent = parent->next;
-
-		strbuf_addf(sb, " %s", hex);
-	}
-	strbuf_addch(sb, '\n');
+	pp_commit_list(pp, sb, "Merge:", parent);
 }
 
 static char *get_header(const struct commit *commit, const char *msg,
-- 
1.9.rc2.232.gdd31389

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]