summaryrefslogtreecommitdiff
path: root/builtin/name-rev.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-09-24 21:08:37 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-10-05 18:08:06 (GMT)
commit34e02deb60b4db22243d47846eb926de9e0d1cf9 (patch)
treedac7d0fd96ad4086e9dfdf301c21a21922df916b /builtin/name-rev.c
parent00b6c178c3ab475098f7a0bc63b2df2da508020c (diff)
downloadgit-34e02deb60b4db22243d47846eb926de9e0d1cf9.zip
git-34e02deb60b4db22243d47846eb926de9e0d1cf9.tar.gz
git-34e02deb60b4db22243d47846eb926de9e0d1cf9.tar.bz2
name-rev: use strip_suffix to avoid magic numbers
The manual size computations here are correct, but using strip_suffix makes that obvious, and hopefully communicates the intent of the code more clearly. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/name-rev.c')
-rw-r--r--builtin/name-rev.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 8a3a0cd..0377fc1 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -55,16 +55,15 @@ copy_data:
parents;
parents = parents->next, parent_number++) {
if (parent_number > 1) {
- int len = strlen(tip_name);
+ size_t len;
char *new_name;
- if (len > 2 && !strcmp(tip_name + len - 2, "^0"))
- len -= 2;
+ strip_suffix(tip_name, "^0", &len);
if (generation > 0)
- new_name = xstrfmt("%.*s~%d^%d", len, tip_name,
+ new_name = xstrfmt("%.*s~%d^%d", (int)len, tip_name,
generation, parent_number);
else
- new_name = xstrfmt("%.*s^%d", len, tip_name,
+ new_name = xstrfmt("%.*s^%d", (int)len, tip_name,
parent_number);
name_rev(parents->item, new_name, 0,