Skip to content

Commit eb6431b

Browse files
jeffhostetlerdscho
authored andcommitted
index-pack: disable rev-index if index file has non .idx suffix
Teach index-pack to silently omit the reverse index if the index file does not have the standard ".idx" suffix. In e37d0b8 (builtin/index-pack.c: write reverse indexes, 2021-01-25) we learned to create `.rev` reverse indexes in addition to `.idx` index files. The `.rev` file pathname is constructed by replacing the suffix on the `.idx` file. The code assumes a hard-coded "idx" suffix. In a8dd7e0 (config: enable `pack.writeReverseIndex` by default, 2023-04-12) reverse indexes were enabled by default. If the `-o <idx-path>` argument is used, the index file may have a different suffix. This causes an error when it tries to create the reverse index pathname. Since we do not know why the user requested a non-standard suffix for the index, we cannot guess what the proper corresponding suffix should be for the reverse index. So we disable it. The t5300 test has been updated to verify that we no longer error out and that the .rev file is not created. Signed-off-by: Jeff Hostetler <jeffhostetler@github.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 19d951f commit eb6431b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

builtin/index-pack.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
17441744
unsigned foreign_nr = 1; /* zero is a "good" value, assume bad */
17451745
int report_end_of_input = 0;
17461746
int hash_algo = 0;
1747+
int dash_o = 0;
17471748

17481749
/*
17491750
* index-pack never needs to fetch missing objects except when
@@ -1837,6 +1838,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
18371838
if (index_name || (i+1) >= argc)
18381839
usage(index_pack_usage);
18391840
index_name = argv[++i];
1841+
dash_o = 1;
18401842
} else if (starts_with(arg, "--index-version=")) {
18411843
char *c;
18421844
opts.version = strtoul(arg + 16, &c, 10);
@@ -1879,6 +1881,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
18791881
index_name = derive_filename(pack_name, "pack", "idx", &index_name_buf);
18801882

18811883
opts.flags &= ~(WRITE_REV | WRITE_REV_VERIFY);
1884+
if (rev_index && dash_o && !ends_with(index_name, ".idx"))
1885+
rev_index = 0;
18821886
if (rev_index) {
18831887
opts.flags |= verify ? WRITE_REV_VERIFY : WRITE_REV;
18841888
if (index_name)

t/t5300-pack-object.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,10 @@ test_expect_success 'complain about index name' '
372372
test -f test-complain-0.idx &&
373373
test -f test-complain-0.rev &&
374374
375-
# Non .idx suffix
375+
# Non .idx suffix -- implicitly omits the .rev
376376
cat test-1-${packname_1}.pack >test-complain-1.pack &&
377-
test_must_fail git index-pack -o test-complain-1.idx-suffix --rev-index test-complain-1.pack 2>err &&
378-
grep "does not end" err &&
379-
! test -f test-complain-1.idx-suffix &&
377+
git index-pack -o test-complain-1.idx-suffix --rev-index test-complain-1.pack &&
378+
test -f test-complain-1.idx-suffix &&
380379
! test -f test-complain-1.rev
381380
'
382381

0 commit comments

Comments
 (0)