aboutsummaryrefslogtreecommitdiff
path: root/builtin-name-rev.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2007-02-20 22:24:03 -0800
committerJunio C Hamano <junkio@cox.net>2007-02-20 22:24:03 -0800
commit5ead60e61987ec7a9ca18050838bb47aa51d3665 (patch)
treef72ca128c286aba1dd22a4aa51523f093f4365ce /builtin-name-rev.c
parent1968d77dd632a9a9e5c6f5681649e5e65ed13088 (diff)
parent59d3f541cfe48345d708330bc19d8a880c80c595 (diff)
downloadgit-5ead60e61987ec7a9ca18050838bb47aa51d3665.tar.gz
git-5ead60e61987ec7a9ca18050838bb47aa51d3665.tar.xz
Merge branch 'js/name-rev-fix'
* js/name-rev-fix: name-rev: avoid "^0" when unneeded
Diffstat (limited to 'builtin-name-rev.c')
-rw-r--r--builtin-name-rev.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/builtin-name-rev.c b/builtin-name-rev.c
index 2c3d14c1b..c02222436 100644
--- a/builtin-name-rev.c
+++ b/builtin-name-rev.c
@@ -57,13 +57,17 @@ copy_data:
parents;
parents = parents->next, parent_number++) {
if (parent_number > 1) {
- char *new_name = xmalloc(strlen(tip_name)+8);
+ int len = strlen(tip_name);
+ char *new_name = xmalloc(len + 8);
+ if (len > 2 && !strcmp(tip_name + len - 2, "^0"))
+ len -= 2;
if (generation > 0)
- sprintf(new_name, "%s~%d^%d", tip_name,
+ sprintf(new_name, "%.*s~%d^%d", len, tip_name,
generation, parent_number);
else
- sprintf(new_name, "%s^%d", tip_name, parent_number);
+ sprintf(new_name, "%.*s^%d", len, tip_name,
+ parent_number);
name_rev(parents->item, new_name,
merge_traversals + 1 , 0, 0);
@@ -127,10 +131,15 @@ static const char* get_rev_name(struct object *o)
if (!n->generation)
return n->tip_name;
-
- snprintf(buffer, sizeof(buffer), "%s~%d", n->tip_name, n->generation);
-
- return buffer;
+ else {
+ int len = strlen(n->tip_name);
+ if (len > 2 && !strcmp(n->tip_name + len - 2, "^0"))
+ len -= 2;
+ snprintf(buffer, sizeof(buffer), "%.*s~%d", len, n->tip_name,
+ n->generation);
+
+ return buffer;
+ }
}
int cmd_name_rev(int argc, const char **argv, const char *prefix)