Skip to content

Commit 3227565

Browse files
derrickstoleegitster
authored andcommitted
midx: read pack names into array
Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 32f3c54 commit 3227565

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

midx.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir)
3737
uint32_t hash_version;
3838
char *midx_name = get_midx_filename(object_dir);
3939
uint32_t i;
40+
const char *cur_pack_name;
4041

4142
fd = git_open(midx_name);
4243

@@ -115,6 +116,22 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir)
115116
if (!m->chunk_pack_names)
116117
die(_("multi-pack-index missing required pack-name chunk"));
117118

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+
118135
return m;
119136

120137
cleanup_fail:

midx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct multi_pack_index {
1616

1717
const unsigned char *chunk_pack_names;
1818

19+
const char **pack_names;
1920
char object_dir[FLEX_ARRAY];
2021
};
2122

t/helper/test-read-midx.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
static int read_midx_file(const char *object_dir)
88
{
9+
uint32_t i;
910
struct multi_pack_index *m = load_multi_pack_index(object_dir);
1011

1112
if (!m)
@@ -24,6 +25,10 @@ static int read_midx_file(const char *object_dir)
2425

2526
printf("\n");
2627

28+
printf("packs:\n");
29+
for (i = 0; i < m->num_packs; i++)
30+
printf("%s\n", m->pack_names[i]);
31+
2732
printf("object-dir: %s\n", m->object_dir);
2833

2934
return 0;

t/t5319-multi-pack-index.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ test_description='multi-pack-indexes'
55

66
midx_read_expect () {
77
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 &&
1320
test-tool read-midx . >actual &&
1421
test_cmp expect actual
1522
}

0 commit comments

Comments
 (0)