Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerrick Stolee <stolee@gmail.com>2018-07-12 22:39:28 +0300
committerJunio C Hamano <gitster@pobox.com>2018-07-20 21:27:28 +0300
commit3227565cfdeabcb06eede914d38c8729e6ff1434 (patch)
tree9ee4589cd669d497f09fe2e0992b5c2bcf7f2073
parent32f3c541e3c8b3ad225c36b1430c9483d0e427ad (diff)
midx: read pack names into array
Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--midx.c17
-rw-r--r--midx.h1
-rw-r--r--t/helper/test-read-midx.c5
-rwxr-xr-xt/t5319-multi-pack-index.sh17
4 files changed, 35 insertions, 5 deletions
diff --git a/midx.c b/midx.c
index ca7a32bf95..fcdf6553ce 100644
--- a/midx.c
+++ b/midx.c
@@ -37,6 +37,7 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir)
uint32_t hash_version;
char *midx_name = get_midx_filename(object_dir);
uint32_t i;
+ const char *cur_pack_name;
fd = git_open(midx_name);
@@ -115,6 +116,22 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir)
if (!m->chunk_pack_names)
die(_("multi-pack-index missing required pack-name chunk"));
+ m->pack_names = xcalloc(m->num_packs, sizeof(*m->pack_names));
+
+ cur_pack_name = (const char *)m->chunk_pack_names;
+ for (i = 0; i < m->num_packs; i++) {
+ m->pack_names[i] = cur_pack_name;
+
+ cur_pack_name += strlen(cur_pack_name) + 1;
+
+ if (i && strcmp(m->pack_names[i], m->pack_names[i - 1]) <= 0) {
+ error(_("multi-pack-index pack names out of order: '%s' before '%s'"),
+ m->pack_names[i - 1],
+ m->pack_names[i]);
+ goto cleanup_fail;
+ }
+ }
+
return m;
cleanup_fail:
diff --git a/midx.h b/midx.h
index 38af01fa3b..17b56172e3 100644
--- a/midx.h
+++ b/midx.h
@@ -16,6 +16,7 @@ struct multi_pack_index {
const unsigned char *chunk_pack_names;
+ const char **pack_names;
char object_dir[FLEX_ARRAY];
};
diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c
index 3f2d2cfa78..76a60d7882 100644
--- a/t/helper/test-read-midx.c
+++ b/t/helper/test-read-midx.c
@@ -6,6 +6,7 @@
static int read_midx_file(const char *object_dir)
{
+ uint32_t i;
struct multi_pack_index *m = load_multi_pack_index(object_dir);
if (!m)
@@ -24,6 +25,10 @@ static int read_midx_file(const char *object_dir)
printf("\n");
+ printf("packs:\n");
+ for (i = 0; i < m->num_packs; i++)
+ printf("%s\n", m->pack_names[i]);
+
printf("object-dir: %s\n", m->object_dir);
return 0;
diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh
index 7512d55c92..e8da082c64 100755
--- a/t/t5319-multi-pack-index.sh
+++ b/t/t5319-multi-pack-index.sh
@@ -5,11 +5,18 @@ test_description='multi-pack-indexes'
midx_read_expect () {
NUM_PACKS=$1
- cat >expect <<-EOF
- header: 4d494458 1 1 $NUM_PACKS
- chunks: pack-names
- object-dir: .
- EOF
+ {
+ cat <<-EOF &&
+ header: 4d494458 1 1 $NUM_PACKS
+ chunks: pack-names
+ packs:
+ EOF
+ if test $NUM_PACKS -ge 1
+ then
+ ls pack/ | grep idx | sort
+ fi &&
+ printf "object-dir: .\n"
+ } >expect &&
test-tool read-midx . >actual &&
test_cmp expect actual
}