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>
This commit is contained in:

committed by
Junio C Hamano

parent
00b6c178c3
commit
34e02deb60
@ -55,16 +55,15 @@ copy_data:
|
|||||||
parents;
|
parents;
|
||||||
parents = parents->next, parent_number++) {
|
parents = parents->next, parent_number++) {
|
||||||
if (parent_number > 1) {
|
if (parent_number > 1) {
|
||||||
int len = strlen(tip_name);
|
size_t len;
|
||||||
char *new_name;
|
char *new_name;
|
||||||
|
|
||||||
if (len > 2 && !strcmp(tip_name + len - 2, "^0"))
|
strip_suffix(tip_name, "^0", &len);
|
||||||
len -= 2;
|
|
||||||
if (generation > 0)
|
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);
|
generation, parent_number);
|
||||||
else
|
else
|
||||||
new_name = xstrfmt("%.*s^%d", len, tip_name,
|
new_name = xstrfmt("%.*s^%d", (int)len, tip_name,
|
||||||
parent_number);
|
parent_number);
|
||||||
|
|
||||||
name_rev(parents->item, new_name, 0,
|
name_rev(parents->item, new_name, 0,
|
||||||
|
Reference in New Issue
Block a user