Skip to content

Commit 304f0a3

Browse files
Fix rev index (#599)
`git index-pack` fails when the `-o` argument is used and the requested IDX file does not have the standard `.idx` suffix. The reverse index code assumes the `.idx` suffix when it generates the `.rev` pathname. Silently disable the reverse index when the suffix is different. Added a test to confirm the breakage and then updated it to confirm the fix. This is being patched into vfs-2.41.0.5 directly, but the fixes should be backported to upstream Git and to vfs-2.42.0.
2 parents 908c6e5 + 728d78d commit 304f0a3

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

builtin/index-pack.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
17401740
unsigned foreign_nr = 1; /* zero is a "good" value, assume bad */
17411741
int report_end_of_input = 0;
17421742
int hash_algo = 0;
1743+
int dash_o = 0;
17431744

17441745
/*
17451746
* index-pack never needs to fetch missing objects except when
@@ -1832,6 +1833,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
18321833
if (index_name || (i+1) >= argc)
18331834
usage(index_pack_usage);
18341835
index_name = argv[++i];
1836+
dash_o = 1;
18351837
} else if (starts_with(arg, "--index-version=")) {
18361838
char *c;
18371839
opts.version = strtoul(arg + 16, &c, 10);
@@ -1874,6 +1876,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
18741876
index_name = derive_filename(pack_name, "pack", "idx", &index_name_buf);
18751877

18761878
opts.flags &= ~(WRITE_REV | WRITE_REV_VERIFY);
1879+
if (rev_index && dash_o && !ends_with(index_name, ".idx"))
1880+
rev_index = 0;
18771881
if (rev_index) {
18781882
opts.flags |= verify ? WRITE_REV_VERIFY : WRITE_REV;
18791883
if (index_name)

t/t5300-pack-object.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,30 @@ test_expect_success \
355355
356356
:'
357357

358+
# The `--rev-index` option of `git index-pack` is now the default, so
359+
# a `foo.rev` REV file will be created when a `foo.idx` IDX file is
360+
# created. Normally, these pathnames are based upon the `foo.pack`
361+
# PACK file pathname.
362+
#
363+
# However, the `-o` option lets you set the pathname of the IDX file
364+
# indepdent of the PACK file.
365+
#
366+
# Verify what happens if these suffixes are changed.
367+
#
368+
test_expect_success 'complain about index name' '
369+
# Normal case { .pack, .idx, .rev }
370+
cat test-1-${packname_1}.pack >test-complain-0.pack &&
371+
git index-pack -o test-complain-0.idx --rev-index test-complain-0.pack &&
372+
test -f test-complain-0.idx &&
373+
test -f test-complain-0.rev &&
374+
375+
# Non .idx suffix -- implicitly omits the .rev
376+
cat test-1-${packname_1}.pack >test-complain-1.pack &&
377+
git index-pack -o test-complain-1.idx-suffix --rev-index test-complain-1.pack &&
378+
test -f test-complain-1.idx-suffix &&
379+
! test -f test-complain-1.rev
380+
'
381+
358382
test_expect_success 'unpacking with --strict' '
359383
360384
for j in a b c d e f g

0 commit comments

Comments
 (0)