diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-03-03 13:19:02 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-03-03 13:19:02 -0800 |
commit | 505c99fdd4ba69195fcce0fc8822522cc8af0c72 (patch) | |
tree | 200514cd5973e4a882935c6ee66b33703b411a28 | |
parent | c34c9a9db65a0839a11657cf7073fa1c946fb149 (diff) | |
parent | bfee614a2f5838e03378888d78e8247b8400d5ce (diff) | |
download | git-505c99fdd4ba69195fcce0fc8822522cc8af0c72.tar.gz |
Merge branch 'jc/index-pack' into jc/bundle
* jc/index-pack:
index-pack: add a helper function to derive .idx/.keep filename
index-pack: correct --keep[=<msg>]
-rw-r--r-- | builtin/index-pack.c | 35 | ||||
-rwxr-xr-x | t/t5300-pack-object.sh | 6 |
2 files changed, 23 insertions, 18 deletions
diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 193908a619..a5588a24d1 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1598,6 +1598,18 @@ static void show_pack_info(int stat_only) } } +static const char *derive_filename(const char *pack_name, const char *suffix, + struct strbuf *buf) +{ + size_t len; + if (!strip_suffix(pack_name, ".pack", &len)) + die(_("packfile name '%s' does not end with '.pack'"), + pack_name); + strbuf_add(buf, pack_name, len); + strbuf_addstr(buf, suffix); + return buf->buf; +} + int cmd_index_pack(int argc, const char **argv, const char *prefix) { int i, fix_thin_pack = 0, verify = 0, stat_only = 0; @@ -1706,24 +1718,11 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) usage(index_pack_usage); if (fix_thin_pack && !from_stdin) die(_("--fix-thin cannot be used without --stdin")); - if (!index_name && pack_name) { - size_t len; - if (!strip_suffix(pack_name, ".pack", &len)) - die(_("packfile name '%s' does not end with '.pack'"), - pack_name); - strbuf_add(&index_name_buf, pack_name, len); - strbuf_addstr(&index_name_buf, ".idx"); - index_name = index_name_buf.buf; - } - if (keep_msg && !keep_name && pack_name) { - size_t len; - if (!strip_suffix(pack_name, ".pack", &len)) - die(_("packfile name '%s' does not end with '.pack'"), - pack_name); - strbuf_add(&keep_name_buf, pack_name, len); - strbuf_addstr(&keep_name_buf, ".idx"); - keep_name = keep_name_buf.buf; - } + if (!index_name && pack_name) + index_name = derive_filename(pack_name, ".idx", &index_name_buf); + if (keep_msg && !keep_name && pack_name) + keep_name = derive_filename(pack_name, ".keep", &keep_name_buf); + if (verify) { if (!index_name) die(_("--verify with no packfile name given")); diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index fc2be63e02..899e52d50f 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -284,6 +284,12 @@ test_expect_success \ git index-pack test-3.pack && cmp test-3.idx test-3-${packname_3}.idx && + cat test-1-${packname_1}.pack >test-4.pack && + rm -f test-4.keep && + git index-pack --keep=why test-4.pack && + cmp test-1-${packname_1}.idx test-4.idx && + test -f test-4.keep && + :' test_expect_success 'unpacking with --strict' ' |