midx: read pack names into array
Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Jul 12, 2018 at 15:39 UTC
3227565cfdeabcb06eede914d38c8729e6ff1434
4 files changed
+35
-5
midx.c
+17
@@ -37,6 +37,7 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir)
37
uint32_t hash_version;
38
char *midx_name = get_midx_filename(object_dir);
39
uint32_t i;
40
+ const char *cur_pack_name;
41
42
fd = git_open(midx_name);
43
@@ -115,6 +116,22 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir)
116
if (!m->chunk_pack_names)
117
die(_("multi-pack-index missing required pack-name chunk"));
118
119
+ m->pack_names = xcalloc(m->num_packs, sizeof(*m->pack_names));
120
+
121
+ cur_pack_name = (const char *)m->chunk_pack_names;
122
+ for (i = 0; i < m->num_packs; i++) {
123
+ m->pack_names[i] = cur_pack_name;
124
+
125
+ cur_pack_name += strlen(cur_pack_name) + 1;
126
+
127
+ if (i && strcmp(m->pack_names[i], m->pack_names[i - 1]) <= 0) {
128
+ error(_("multi-pack-index pack names out of order: '%s' before '%s'"),
129
+ m->pack_names[i - 1],
130
+ m->pack_names[i]);
131
+ goto cleanup_fail;
132
+ }
133
+ }
134
+
135
return m;
136
137
cleanup_fail:
midx.h
+1
@@ -16,6 +16,7 @@ struct multi_pack_index {
16
17
const unsigned char *chunk_pack_names;
18
19
+ const char **pack_names;
20
char object_dir[FLEX_ARRAY];
21
};
22
t/helper/test-read-midx.c
+5
@@ -6,6 +6,7 @@
6
7
static int read_midx_file(const char *object_dir)
8
{
9
+ uint32_t i;
10
struct multi_pack_index *m = load_multi_pack_index(object_dir);
11
12
if (!m)
@@ -24,6 +25,10 @@ static int read_midx_file(const char *object_dir)
25
26
printf("\n");
27
28
+ printf("packs:\n");
29
+ for (i = 0; i < m->num_packs; i++)
30
+ printf("%s\n", m->pack_names[i]);
31
+
32
printf("object-dir: %s\n", m->object_dir);
33
34
return 0;
t/t5319-multi-pack-index.sh
+12
-5
@@ -5,11 +5,18 @@ test_description='multi-pack-indexes'
5
6
midx_read_expect () {
7
NUM_PACKS=$1
8
- cat >expect <<-EOF
9
- header: 4d494458 1 1 $NUM_PACKS
10
- chunks: pack-names
11
- object-dir: .
12
- EOF
8
+ {
9
+ cat <<-EOF &&
10
+ header: 4d494458 1 1 $NUM_PACKS
11
+ chunks: pack-names
12
+ packs:
13
+ EOF
14
+ if test $NUM_PACKS -ge 1
15
+ then
16
+ ls pack/ | grep idx | sort
17
+ fi &&
18
+ printf "object-dir: .\n"
19
+ } >expect &&
20
test-tool read-midx . >actual &&
21
test_cmp expect actual
22
}