Skip to content

Commit 1b13a22

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 2321ad9 + f27fd55 commit 1b13a22

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
@@ -1890,6 +1890,7 @@ int cmd_index_pack(int argc,
18901890
unsigned foreign_nr = 1; /* zero is a "good" value, assume bad */
18911891
int report_end_of_input = 0;
18921892
int hash_algo = 0;
1893+
int dash_o = 0;
18931894

18941895
/*
18951896
* index-pack never needs to fetch missing objects except when
@@ -1983,6 +1984,7 @@ int cmd_index_pack(int argc,
19831984
if (index_name || (i+1) >= argc)
19841985
usage(index_pack_usage);
19851986
index_name = argv[++i];
1987+
dash_o = 1;
19861988
} else if (starts_with(arg, "--index-version=")) {
19871989
char *c;
19881990
opts.version = strtoul(arg + 16, &c, 10);
@@ -2036,6 +2038,8 @@ int cmd_index_pack(int argc,
20362038
repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
20372039

20382040
opts.flags &= ~(WRITE_REV | WRITE_REV_VERIFY);
2041+
if (rev_index && dash_o && !ends_with(index_name, ".idx"))
2042+
rev_index = 0;
20392043
if (rev_index) {
20402044
opts.flags |= verify ? WRITE_REV_VERIFY : WRITE_REV;
20412045
if (index_name)

t/t5300-pack-object.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,30 @@ test_expect_success 'build pack index for an existing pack' '
357357
:
358358
'
359359

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

0 commit comments

Comments
 (0)