Skip to content

Commit 34e02de

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 00b6c17 commit 34e02de

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

builtin/name-rev.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,15 @@ static void name_rev(struct commit *commit,
5555
parents;
5656
parents = parents->next, parent_number++) {
5757
if (parent_number > 1) {
58-
int len = strlen(tip_name);
58+
size_t len;
5959
char *new_name;
6060

61-
if (len > 2 && !strcmp(tip_name + len - 2, "^0"))
62-
len -= 2;
61+
strip_suffix(tip_name, "^0", &len);
6362
if (generation > 0)
64-
new_name = xstrfmt("%.*s~%d^%d", len, tip_name,
63+
new_name = xstrfmt("%.*s~%d^%d", (int)len, tip_name,
6564
generation, parent_number);
6665
else
67-
new_name = xstrfmt("%.*s^%d", len, tip_name,
66+
new_name = xstrfmt("%.*s^%d", (int)len, tip_name,
6867
parent_number);
6968

7069
name_rev(parents->item, new_name, 0,

0 commit comments

Comments
 (0)