Skip to content

Commit 3e52f70

Browse files
pcloudsgitster
authored andcommitted
t1700: new tests for split-index mode
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5b0a78c commit 3e52f70

File tree

6 files changed

+233
-2
lines changed

6 files changed

+233
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
/test-date
181181
/test-delta
182182
/test-dump-cache-tree
183+
/test-dump-split-index
183184
/test-scrap-cache-tree
184185
/test-genrandom
185186
/test-hashmap

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ TEST_PROGRAMS_NEED_X += test-ctype
565565
TEST_PROGRAMS_NEED_X += test-date
566566
TEST_PROGRAMS_NEED_X += test-delta
567567
TEST_PROGRAMS_NEED_X += test-dump-cache-tree
568+
TEST_PROGRAMS_NEED_X += test-dump-split-index
568569
TEST_PROGRAMS_NEED_X += test-genrandom
569570
TEST_PROGRAMS_NEED_X += test-hashmap
570571
TEST_PROGRAMS_NEED_X += test-index-version

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,8 @@ extern int daemonize(void);
473473
struct lock_file;
474474
extern int read_index(struct index_state *);
475475
extern int read_index_preload(struct index_state *, const struct pathspec *pathspec);
476+
extern int do_read_index(struct index_state *istate, const char *path,
477+
int must_exist); /* for testting only! */
476478
extern int read_index_from(struct index_state *, const char *path);
477479
extern int is_index_unborn(struct index_state *);
478480
extern int read_index_unmerged(struct index_state *);

read-cache.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,8 +1463,7 @@ static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk,
14631463
}
14641464

14651465
/* remember to discard_cache() before reading a different cache! */
1466-
static int do_read_index(struct index_state *istate, const char *path,
1467-
int must_exist)
1466+
int do_read_index(struct index_state *istate, const char *path, int must_exist)
14681467
{
14691468
int fd, i;
14701469
struct stat st;

t/t1700-split-index.sh

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
#!/bin/sh
2+
3+
test_description='split index mode tests'
4+
5+
. ./test-lib.sh
6+
7+
# We need total control of index splitting here
8+
sane_unset GIT_TEST_SPLIT_INDEX
9+
10+
test_expect_success 'enable split index' '
11+
git update-index --split-index &&
12+
test-dump-split-index .git/index >actual &&
13+
cat >expect <<EOF &&
14+
own 8299b0bcd1ac364e5f1d7768efb62fa2da79a339
15+
base 39d890139ee5356c7ef572216cebcd27aa41f9df
16+
replacements:
17+
deletions:
18+
EOF
19+
test_cmp expect actual
20+
'
21+
22+
test_expect_success 'add one file' '
23+
: >one &&
24+
git update-index --add one &&
25+
git ls-files --stage >ls-files.actual &&
26+
cat >ls-files.expect <<EOF &&
27+
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
28+
EOF
29+
test_cmp ls-files.expect ls-files.actual &&
30+
31+
test-dump-split-index .git/index | sed "/^own/d" >actual &&
32+
cat >expect <<EOF &&
33+
base 39d890139ee5356c7ef572216cebcd27aa41f9df
34+
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
35+
replacements:
36+
deletions:
37+
EOF
38+
test_cmp expect actual
39+
'
40+
41+
test_expect_success 'disable split index' '
42+
git update-index --no-split-index &&
43+
git ls-files --stage >ls-files.actual &&
44+
cat >ls-files.expect <<EOF &&
45+
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
46+
EOF
47+
test_cmp ls-files.expect ls-files.actual &&
48+
49+
BASE=`test-dump-split-index .git/index | grep "^own" | sed "s/own/base/"` &&
50+
test-dump-split-index .git/index | sed "/^own/d" >actual &&
51+
cat >expect <<EOF &&
52+
not a split index
53+
EOF
54+
test_cmp expect actual
55+
'
56+
57+
test_expect_success 'enable split index again, "one" now belongs to base index"' '
58+
git update-index --split-index &&
59+
git ls-files --stage >ls-files.actual &&
60+
cat >ls-files.expect <<EOF &&
61+
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
62+
EOF
63+
test_cmp ls-files.expect ls-files.actual &&
64+
65+
test-dump-split-index .git/index | sed "/^own/d" >actual &&
66+
cat >expect <<EOF &&
67+
$BASE
68+
replacements:
69+
deletions:
70+
EOF
71+
test_cmp expect actual
72+
'
73+
74+
test_expect_success 'modify original file, base index untouched' '
75+
echo modified >one &&
76+
git update-index one &&
77+
git ls-files --stage >ls-files.actual &&
78+
cat >ls-files.expect <<EOF &&
79+
100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
80+
EOF
81+
test_cmp ls-files.expect ls-files.actual &&
82+
83+
test-dump-split-index .git/index | sed "/^own/d" >actual &&
84+
q_to_tab >expect <<EOF &&
85+
$BASE
86+
100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
87+
replacements: 0
88+
deletions:
89+
EOF
90+
test_cmp expect actual
91+
'
92+
93+
test_expect_success 'add another file, which stays index' '
94+
: >two &&
95+
git update-index --add two &&
96+
git ls-files --stage >ls-files.actual &&
97+
cat >ls-files.expect <<EOF &&
98+
100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
99+
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two
100+
EOF
101+
test_cmp ls-files.expect ls-files.actual &&
102+
103+
test-dump-split-index .git/index | sed "/^own/d" >actual &&
104+
q_to_tab >expect <<EOF &&
105+
$BASE
106+
100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
107+
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two
108+
replacements: 0
109+
deletions:
110+
EOF
111+
test_cmp expect actual
112+
'
113+
114+
test_expect_success 'remove file not in base index' '
115+
git update-index --force-remove two &&
116+
git ls-files --stage >ls-files.actual &&
117+
cat >ls-files.expect <<EOF &&
118+
100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
119+
EOF
120+
test_cmp ls-files.expect ls-files.actual &&
121+
122+
test-dump-split-index .git/index | sed "/^own/d" >actual &&
123+
q_to_tab >expect <<EOF &&
124+
$BASE
125+
100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
126+
replacements: 0
127+
deletions:
128+
EOF
129+
test_cmp expect actual
130+
'
131+
132+
test_expect_success 'remove file in base index' '
133+
git update-index --force-remove one &&
134+
git ls-files --stage >ls-files.actual &&
135+
cat >ls-files.expect <<EOF &&
136+
EOF
137+
test_cmp ls-files.expect ls-files.actual &&
138+
139+
test-dump-split-index .git/index | sed "/^own/d" >actual &&
140+
cat >expect <<EOF &&
141+
$BASE
142+
replacements:
143+
deletions: 0
144+
EOF
145+
test_cmp expect actual
146+
'
147+
148+
test_expect_success 'add original file back' '
149+
: >one &&
150+
git update-index --add one &&
151+
git ls-files --stage >ls-files.actual &&
152+
cat >ls-files.expect <<EOF &&
153+
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
154+
EOF
155+
test_cmp ls-files.expect ls-files.actual &&
156+
157+
test-dump-split-index .git/index | sed "/^own/d" >actual &&
158+
cat >expect <<EOF &&
159+
$BASE
160+
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
161+
replacements:
162+
deletions: 0
163+
EOF
164+
test_cmp expect actual
165+
'
166+
167+
test_expect_success 'add new file' '
168+
: >two &&
169+
git update-index --add two &&
170+
git ls-files --stage >actual &&
171+
cat >expect <<EOF &&
172+
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
173+
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two
174+
EOF
175+
test_cmp expect actual
176+
'
177+
178+
test_expect_success 'unify index, two files remain' '
179+
git update-index --no-split-index &&
180+
git ls-files --stage >ls-files.actual &&
181+
cat >ls-files.expect <<EOF &&
182+
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
183+
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two
184+
EOF
185+
test_cmp ls-files.expect ls-files.actual
186+
187+
test-dump-split-index .git/index | sed "/^own/d" >actual &&
188+
cat >expect <<EOF &&
189+
not a split index
190+
EOF
191+
test_cmp expect actual
192+
'
193+
194+
test_done

test-dump-split-index.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "cache.h"
2+
#include "split-index.h"
3+
#include "ewah/ewok.h"
4+
5+
static void show_bit(size_t pos, void *data)
6+
{
7+
printf(" %d", (int)pos);
8+
}
9+
10+
int main(int ac, char **av)
11+
{
12+
struct split_index *si;
13+
int i;
14+
15+
do_read_index(&the_index, av[1], 1);
16+
printf("own %s\n", sha1_to_hex(the_index.sha1));
17+
si = the_index.split_index;
18+
if (!si) {
19+
printf("not a split index\n");
20+
return 0;
21+
}
22+
printf("base %s\n", sha1_to_hex(si->base_sha1));
23+
for (i = 0; i < the_index.cache_nr; i++) {
24+
struct cache_entry *ce = the_index.cache[i];
25+
printf("%06o %s %d\t%s\n", ce->ce_mode,
26+
sha1_to_hex(ce->sha1), ce_stage(ce), ce->name);
27+
}
28+
printf("replacements:");
29+
ewah_each_bit(si->replace_bitmap, show_bit, NULL);
30+
printf("\ndeletions:");
31+
ewah_each_bit(si->delete_bitmap, show_bit, NULL);
32+
printf("\n");
33+
return 0;
34+
}

0 commit comments

Comments
 (0)