Skip to content

Commit

Permalink
Merge branch 'js/name-rev-fix'
Browse files Browse the repository at this point in the history
* js/name-rev-fix:
  name-rev: avoid "^0" when unneeded
  • Loading branch information
Junio C Hamano committed Feb 21, 2007
2 parents 1968d77 59d3f54 commit 5ead60e
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions builtin-name-rev.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 57,17 @@ static void name_rev(struct commit *commit,
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);
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5ead60e

Please sign in to comment.