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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jun 30, 2014 at 13:02 UTC
d6cd00c76866a6412e0c13da91a022acdd187a47
1 file changed
+3
-4
builtin/verify-pack.c
+3
-4
@@ -27,10 +27,9 @@ static int verify_one_pack(const char *path, unsigned int flags)
27
* normalize these forms to "foo.pack" for "index-pack --verify".
28
*/
29
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");
33
argv[2] = arg.buf;
34
35
memset(&index_pack, 0, sizeof(index_pack));