]> git.ipfire.org Git - thirdparty/git.git/commitdiff
name-rev: use strbuf_strip_suffix() in get_rev_name()
authorRené Scharfe <l.s.r@web.de>
Tue, 12 Nov 2019 10:38:11 +0000 (11:38 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 6 Dec 2019 21:29:04 +0000 (13:29 -0800)
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>
builtin/name-rev.c

index b0f0776947f05e551f5bd06a4a0e291aa19a56f3..15919adbdbe48a4126af0ed62630a5738105c4ed 100644 (file)
@@ -321,11 +321,10 @@ static const char *get_rev_name(const struct object *o, struct strbuf *buf)
        if (!n->generation)
                return n->tip_name;
        else {
-               int len = strlen(n->tip_name);
-               if (len > 2 && !strcmp(n->tip_name + len - 2, "^0"))
-                       len -= 2;
                strbuf_reset(buf);
-               strbuf_addf(buf, "%.*s~%d", len, n->tip_name, n->generation);
+               strbuf_addstr(buf, n->tip_name);
+               strbuf_strip_suffix(buf, "^0");
+               strbuf_addf(buf, "~%d", n->generation);
                return buf->buf;
        }
 }