Skip to content

Commit 8dd0850

Browse files
rscharfegitster
authored andcommitted
name-rev: use strbuf_strip_suffix() in get_rev_name()
get_name_rev() basically open-codes strip_suffix() before adding a string to a strbuf. Let's use the strbuf right from the beginning, i.e. add the whole string to the strbuf and then use strbuf_strip_suffix(), making the code more idiomatic. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 300e096 commit 8dd0850

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

builtin/name-rev.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,10 @@ static const char *get_rev_name(const struct object *o, struct strbuf *buf)
321321
if (!n->generation)
322322
return n->tip_name;
323323
else {
324-
int len = strlen(n->tip_name);
325-
if (len > 2 && !strcmp(n->tip_name + len - 2, "^0"))
326-
len -= 2;
327324
strbuf_reset(buf);
328-
strbuf_addf(buf, "%.*s~%d", len, n->tip_name, n->generation);
325+
strbuf_addstr(buf, n->tip_name);
326+
strbuf_strip_suffix(buf, "^0");
327+
strbuf_addf(buf, "~%d", n->generation);
329328
return buf->buf;
330329
}
331330
}

0 commit comments

Comments
 (0)