Skip to content

Commit 6fc9a84

Browse files
jeffhostetlerdscho
authored andcommitted
Fix rev index in 2.42.0 series (#600)
Cherry-pick rev-index fixes from v2.41.0.vfs.0.5 into v2.42.0.*
2 parents 349314f + 133fc3f commit 6fc9a84

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
@@ -1734,6 +1734,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
17341734
unsigned foreign_nr = 1; /* zero is a "good" value, assume bad */
17351735
int report_end_of_input = 0;
17361736
int hash_algo = 0;
1737+
int dash_o = 0;
17371738

17381739
/*
17391740
* index-pack never needs to fetch missing objects except when
@@ -1827,6 +1828,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
18271828
if (index_name || (i+1) >= argc)
18281829
usage(index_pack_usage);
18291830
index_name = argv[++i];
1831+
dash_o = 1;
18301832
} else if (starts_with(arg, "--index-version=")) {
18311833
char *c;
18321834
opts.version = strtoul(arg + 16, &c, 10);
@@ -1869,6 +1871,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
18691871
index_name = derive_filename(pack_name, "pack", "idx", &index_name_buf);
18701872

18711873
opts.flags &= ~(WRITE_REV | WRITE_REV_VERIFY);
1874+
if (rev_index && dash_o && !ends_with(index_name, ".idx"))
1875+
rev_index = 0;
18721876
if (rev_index) {
18731877
opts.flags |= verify ? WRITE_REV_VERIFY : WRITE_REV;
18741878
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 'build pack index for an existing pack' '
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)