Skip to content

Commit 29cdb90

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. TODO We could warn the user that we skipped it (perhaps only if they TODO explicitly requested `--rev-index` on the command line). TODO TODO Ideally, we should add an `--rev-index-path=<path>` argument TODO or change `--rev-index` to take a pathname. TODO TODO I'll leave these questions for a future series. Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
1 parent b924ab9 commit 29cdb90

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
@@ -1897,6 +1897,7 @@ int cmd_index_pack(int argc,
18971897
unsigned foreign_nr = 1; /* zero is a "good" value, assume bad */
18981898
int report_end_of_input = 0;
18991899
int hash_algo = 0;
1900+
int dash_o = 0;
19001901

19011902
/*
19021903
* index-pack never needs to fetch missing objects except when
@@ -1981,6 +1982,7 @@ int cmd_index_pack(int argc,
19811982
if (index_name || (i+1) >= argc)
19821983
usage(index_pack_usage);
19831984
index_name = argv[++i];
1985+
dash_o = 1;
19841986
} else if (starts_with(arg, "--index-version=")) {
19851987
char *c;
19861988
opts.version = strtoul(arg + 16, &c, 10);
@@ -2034,6 +2036,8 @@ int cmd_index_pack(int argc,
20342036
repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
20352037

20362038
opts.flags &= ~(WRITE_REV | WRITE_REV_VERIFY);
2039+
if (rev_index && dash_o && !ends_with(index_name, ".idx"))
2040+
rev_index = 0;
20372041
if (rev_index) {
20382042
opts.flags |= verify ? WRITE_REV_VERIFY : WRITE_REV;
20392043
if (index_name)

t/t5300-pack-object.sh

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

0 commit comments

Comments
 (0)