]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5325-reverse-index.sh
config: enable `pack.writeReverseIndex` by default
[thirdparty/git.git] / t / t5325-reverse-index.sh
CommitLineData
e37d0b87
TB
1#!/bin/sh
2
3test_description='on-disk reverse index'
b77919ed
TB
4
5TEST_PASSES_SANITIZE_LEAK=true
e37d0b87
TB
6. ./test-lib.sh
7
35a8a354
TB
8# The below tests want control over the 'pack.writeReverseIndex' setting
9# themselves to assert various combinations of it with other options.
10sane_unset GIT_TEST_WRITE_REV_INDEX
11
e37d0b87
TB
12packdir=.git/objects/pack
13
14test_expect_success 'setup' '
15 test_commit base &&
16
a8dd7e05 17 test_config pack.writeReverseIndex false &&
e37d0b87
TB
18 pack=$(git pack-objects --all $packdir/pack) &&
19 rev=$packdir/pack-$pack.rev &&
20
21 test_path_is_missing $rev
22'
23
24test_index_pack () {
25 rm -f $rev &&
26 conf=$1 &&
27 shift &&
28 # remove the index since Windows won't overwrite an existing file
29 rm $packdir/pack-$pack.idx &&
30 git -c pack.writeReverseIndex=$conf index-pack "$@" \
31 $packdir/pack-$pack.pack
32}
33
34test_expect_success 'index-pack with pack.writeReverseIndex' '
35 test_index_pack "" &&
36 test_path_is_missing $rev &&
37
38 test_index_pack false &&
39 test_path_is_missing $rev &&
40
41 test_index_pack true &&
42 test_path_is_file $rev
43'
44
45test_expect_success 'index-pack with --[no-]rev-index' '
46 for conf in "" true false
47 do
48 test_index_pack "$conf" --rev-index &&
49 test_path_exists $rev &&
50
51 test_index_pack "$conf" --no-rev-index &&
d0fd9931 52 test_path_is_missing $rev || return 1
e37d0b87
TB
53 done
54'
55
56test_expect_success 'index-pack can verify reverse indexes' '
57 test_when_finished "rm -f $rev" &&
58 test_index_pack true &&
59
60 test_path_is_file $rev &&
61 git index-pack --rev-index --verify $packdir/pack-$pack.pack &&
62
63 # Intentionally corrupt the reverse index.
64 chmod u+w $rev &&
65 printf "xxxx" | dd of=$rev bs=1 count=4 conv=notrunc &&
66
67 test_must_fail git index-pack --rev-index --verify \
68 $packdir/pack-$pack.pack 2>err &&
69 grep "validation error" err
70'
71
72test_expect_success 'index-pack infers reverse index name with -o' '
73 git index-pack --rev-index -o other.idx $packdir/pack-$pack.pack &&
74 test_path_is_file other.idx &&
75 test_path_is_file other.rev
76'
77
c9773343
TB
78test_expect_success 'pack-objects respects pack.writeReverseIndex' '
79 test_when_finished "rm -fr pack-1-*" &&
80
81 git -c pack.writeReverseIndex= pack-objects --all pack-1 &&
82 test_path_is_missing pack-1-*.rev &&
83
84 git -c pack.writeReverseIndex=false pack-objects --all pack-1 &&
85 test_path_is_missing pack-1-*.rev &&
86
87 git -c pack.writeReverseIndex=true pack-objects --all pack-1 &&
88 test_path_is_file pack-1-*.rev
89'
90
ec8e7760
TB
91test_expect_success 'reverse index is not generated when available on disk' '
92 test_index_pack true &&
93 test_path_is_file $rev &&
94
95 git rev-parse HEAD >tip &&
96 GIT_TEST_REV_INDEX_DIE_IN_MEMORY=1 git cat-file \
97 --batch-check="%(objectsize:disk)" <tip
98'
99
dbcf6116
TB
100test_expect_success 'reverse index is ignored when pack.readReverseIndex is false' '
101 test_index_pack true &&
102 test_path_is_file $rev &&
103
104 test_config pack.readReverseIndex false &&
105
106 git rev-parse HEAD >tip &&
107 GIT_TEST_REV_INDEX_DIE_ON_DISK=1 git cat-file \
108 --batch-check="%(objectsize:disk)" <tip
109'
110
6885cd7d
TB
111test_expect_success 'revindex in-memory vs on-disk' '
112 git init repo &&
113 test_when_finished "rm -fr repo" &&
114 (
115 cd repo &&
116
117 test_commit commit &&
118
119 git rev-list --objects --no-object-names --all >objects &&
120
121 git -c pack.writeReverseIndex=false repack -ad &&
122 test_path_is_missing $packdir/pack-*.rev &&
123 git cat-file --batch-check="%(objectsize:disk) %(objectname)" \
124 <objects >in-core &&
125
126 git -c pack.writeReverseIndex=true repack -ad &&
127 test_path_is_file $packdir/pack-*.rev &&
128 git cat-file --batch-check="%(objectsize:disk) %(objectname)" \
129 <objects >on-disk &&
130
131 test_cmp on-disk in-core
132 )
133'
e37d0b87 134test_done