@matheusbsbs / matheus-bagliano / commits / 542e165cdc
Fork 0

Fix "--pretty=format:" for parent related items.

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>

Junio C Hamano committed Mar 28, 2007 at 13:33 UTC 542e165cdc4fbebbfe7c8954ca1aa1d4162e38cb
2 files changed +12 -8
commit.c
+8 -4
@@ -849,19 +849,23 @@ static long format_commit_message(const struct commit *commit,
849 interp_set_entry(table, ITREE_ABBREV,
850 find_unique_abbrev(commit->tree->object.sha1,
851 DEFAULT_ABBREV));
852 +
853 + parents[1] = 0;
854 for (i = 0, p = commit->parents;
855 p && i < sizeof(parents) - 1;
856 p = p->next)
855 - i += snprintf(parents + i, sizeof(parents) - i - 1, "%s ",
857 + i += snprintf(parents + i, sizeof(parents) - i - 1, " %s",
858 sha1_to_hex(p->item->object.sha1));
857 - interp_set_entry(table, IPARENTS, parents);
859 + interp_set_entry(table, IPARENTS, parents + 1);
860 +
861 + parents[1] = 0;
862 for (i = 0, p = commit->parents;
863 p && i < sizeof(parents) - 1;
864 p = p->next)
861 - i += snprintf(parents + i, sizeof(parents) - i - 1, "%s ",
865 + i += snprintf(parents + i, sizeof(parents) - i - 1, " %s",
866 find_unique_abbrev(p->item->object.sha1,
867 DEFAULT_ABBREV));
864 - interp_set_entry(table, IPARENTS_ABBREV, parents);
868 + interp_set_entry(table, IPARENTS_ABBREV, parents + 1);
869
870 for (i = 0, state = HEADER; msg[i] && state < BODY; i++) {
871 int eol;
t/t6006-rev-list-format.sh
+4 -4
@@ -39,11 +39,11 @@ EOF
39
40 test_format parents %P%n%p <<'EOF'
41 commit 131a310eb913d107dd3c09a65d1651175898735d
42 -86c75cfd708a0e5868dc876ed5b8bb66c80b4873
43 -86c75cf
42 +86c75cfd708a0e5868dc876ed5b8bb66c80b4873
43 +86c75cf
44 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
45 -86c75cf
46 -86c75cf
45 +
46 +
47 EOF
48
49 # we don't test relative here