Code

Fix "--pretty=format:" for parent related items.
authorJunio C Hamano <junkio@cox.net>
Wed, 28 Mar 2007 20:33:37 +0000 (13:33 -0700)
committerJunio C Hamano <junkio@cox.net>
Wed, 28 Mar 2007 20:44:04 +0000 (13:44 -0700)
There are two breakages in the %P/%p interpolation.  It appended
an excess SP at the end of the list, and it gave uninitialized
contents of a buffer on the stack for root commits.

This fixes it, while updating the t6006 test which expected the
wrong output.

Signed-off-by: Junio C Hamano <junkio@cox.net>
commit.c
t/t6006-rev-list-format.sh [changed mode: 0644->0755]

index a92958cfacbfa88eee4cc52fef0f85308ddfc372..9ac533c85ab25f54cda97a0976f21a3232cf72ca 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -849,19 +849,23 @@ static long format_commit_message(const struct commit *commit,
        interp_set_entry(table, ITREE_ABBREV,
                        find_unique_abbrev(commit->tree->object.sha1,
                                DEFAULT_ABBREV));
+
+       parents[1] = 0;
        for (i = 0, p = commit->parents;
                        p && i < sizeof(parents) - 1;
                        p = p->next)
-               i += snprintf(parents + i, sizeof(parents) - i - 1, "%s ",
+               i += snprintf(parents + i, sizeof(parents) - i - 1, " %s",
                        sha1_to_hex(p->item->object.sha1));
-       interp_set_entry(table, IPARENTS, parents);
+       interp_set_entry(table, IPARENTS, parents + 1);
+
+       parents[1] = 0;
        for (i = 0, p = commit->parents;
                        p && i < sizeof(parents) - 1;
                        p = p->next)
-               i += snprintf(parents + i, sizeof(parents) - i - 1, "%s ",
+               i += snprintf(parents + i, sizeof(parents) - i - 1, " %s",
                        find_unique_abbrev(p->item->object.sha1,
                                DEFAULT_ABBREV));
-       interp_set_entry(table, IPARENTS_ABBREV, parents);
+       interp_set_entry(table, IPARENTS_ABBREV, parents + 1);
 
        for (i = 0, state = HEADER; msg[i] && state < BODY; i++) {
                int eol;
old mode 100644 (file)
new mode 100755 (executable)
index cf096c3..ce9c7dc
@@ -39,11 +39,11 @@ EOF
 
 test_format parents %P%n%p <<'EOF'
 commit 131a310eb913d107dd3c09a65d1651175898735d
-86c75cfd708a0e5868dc876ed5b8bb66c80b4873 
-86c75cf 
+86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+86c75cf
 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
-86c75cf 
-86c75cf 
+
+
 EOF
 
 # we don't test relative here