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 <l.s.r@web.de> Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Nov 12, 2019 at 11:38 UTC
c3794d4ccb70c6b36be3fd4981682f422b04de05
1 file changed
+3
-4
builtin/name-rev.c
+3
-4
@@ -321,11 +321,10 @@ static const char *get_rev_name(const struct object *o, struct strbuf *buf)
321
if (!n->generation)
322
return n->tip_name;
323
else {
324
- int len = strlen(n->tip_name);
325
- if (len > 2 && !strcmp(n->tip_name + len - 2, "^0"))
326
- len -= 2;
324
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);
328
return buf->buf;
329
}
330
}