Skip to content

Commit d6cd00c

Browse files
peffgitster
authored andcommitted
verify-pack: use strbuf_strip_suffix
In this code, we try to convert both "foo.idx" and "foo" into "foo.pack". By stripping the suffix, we can avoid a confusing use of strbuf_splice, and make it clear that both cases are adding ".pack" to the end. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6dda4e6 commit d6cd00c

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

builtin/verify-pack.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ static int verify_one_pack(const char *path, unsigned int flags)
2727
* normalize these forms to "foo.pack" for "index-pack --verify".
2828
*/
2929
strbuf_addstr(&arg, path);
30-
if (ends_with(arg.buf, ".idx"))
31-
strbuf_splice(&arg, arg.len - 3, 3, "pack", 4);
32-
else if (!ends_with(arg.buf, ".pack"))
33-
strbuf_add(&arg, ".pack", 5);
30+
if (strbuf_strip_suffix(&arg, ".idx") ||
31+
!ends_with(arg.buf, ".pack"))
32+
strbuf_addstr(&arg, ".pack");
3433
argv[2] = arg.buf;
3534

3635
memset(&index_pack, 0, sizeof(index_pack));

0 commit comments

Comments
 (0)