summaryrefslogtreecommitdiff
path: root/builtin-for-each-ref.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2007-10-02 22:09:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2007-10-02 22:12:05 (GMT)
commit9e1a2acfb2198e29c90b59eef84eb0370ef9f03f (patch)
tree02e3abd35eeb189a0b1f728ed570ff099106d4d7 /builtin-for-each-ref.c
parentc8f203255bc7a782e3a54e73d5801009bb7f0319 (diff)
downloadgit-9e1a2acfb2198e29c90b59eef84eb0370ef9f03f.zip
git-9e1a2acfb2198e29c90b59eef84eb0370ef9f03f.tar.gz
git-9e1a2acfb2198e29c90b59eef84eb0370ef9f03f.tar.bz2
for-each-ref: fix %(numparent) and %(parent)
The string value of %(numparent) was not returned correctly. Also %(parent) misbehaved for the root commits (returned garbage) and merge commits (returned first parent, followed by a space). Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-for-each-ref.c')
-rw-r--r--builtin-for-each-ref.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index 0afa1c5..29f70aa 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -43,7 +43,7 @@ static struct {
{ "objectsize", FIELD_ULONG },
{ "objectname" },
{ "tree" },
- { "parent" }, /* NEEDSWORK: how to address 2nd and later parents? */
+ { "parent" },
{ "numparent", FIELD_ULONG },
{ "object" },
{ "type" },
@@ -262,24 +262,26 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object
}
if (!strcmp(name, "numparent")) {
char *s = xmalloc(40);
+ v->ul = num_parents(commit);
sprintf(s, "%lu", v->ul);
v->s = s;
- v->ul = num_parents(commit);
}
else if (!strcmp(name, "parent")) {
int num = num_parents(commit);
int i;
struct commit_list *parents;
- char *s = xmalloc(42 * num);
+ char *s = xmalloc(41 * num + 1);
v->s = s;
for (i = 0, parents = commit->parents;
parents;
- parents = parents->next, i = i + 42) {
+ parents = parents->next, i = i + 41) {
struct commit *parent = parents->item;
strcpy(s+i, sha1_to_hex(parent->object.sha1));
if (parents->next)
s[i+40] = ' ';
}
+ if (!i)
+ *s = '\0';
}
}
}