Skip to content

Commit 64840d1

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 9c910a1 + 3f3b1cf commit 64840d1

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

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

18701872
opts.flags &= ~(WRITE_REV | WRITE_REV_VERIFY);
1873+
if (rev_index && dash_o && !ends_with(index_name, ".idx"))
1874+
rev_index = 0;
18711875
if (rev_index) {
18721876
opts.flags |= verify ? WRITE_REV_VERIFY : WRITE_REV;
18731877
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)