summaryrefslogtreecommitdiff
path: root/builtin/name-rev.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2019-11-12 10:38:11 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-12-06 21:29:04 (GMT)
commitc3794d4ccb70c6b36be3fd4981682f422b04de05 (patch)
treed9101420ff7e83a13140f21b8d08d5beaa1e752a /builtin/name-rev.c
parentc593a2634837234c91afc875cb569a53fbaadbfb (diff)
downloadgit-c3794d4ccb70c6b36be3fd4981682f422b04de05.zip
git-c3794d4ccb70c6b36be3fd4981682f422b04de05.tar.gz
git-c3794d4ccb70c6b36be3fd4981682f422b04de05.tar.bz2
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>
Diffstat (limited to 'builtin/name-rev.c')
-rw-r--r--builtin/name-rev.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index b0f0776..15919ad 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -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;
}
}