]> git.ipfire.org Git - thirdparty/git.git/commitdiff
multi-pack-index: store local property
authorDerrick Stolee <dstolee@microsoft.com>
Mon, 20 Aug 2018 16:51:55 +0000 (16:51 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Aug 2018 22:31:39 +0000 (15:31 -0700)
A pack-file is 'local' if it is stored within the usual object
directory. If it is stored in an alternate, it is non-local.

Pack-files are stored using a 'pack_local' member in the packed_git
struct. Add a similar 'local' member to the multi_pack_index struct
and 'local' parameters to the methods that load and prepare multi-
pack-indexes.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
midx.c
midx.h
packfile.c
t/helper/test-read-midx.c

diff --git a/midx.c b/midx.c
index 19b7df338ee76b174ba09b003520b90ec974fc2d..6824acf5f8937910edfc74ca0827cec1f4416cfb 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -37,7 +37,7 @@ static char *get_midx_filename(const char *object_dir)
        return xstrfmt("%s/pack/multi-pack-index", object_dir);
 }
 
-struct multi_pack_index *load_multi_pack_index(const char *object_dir)
+struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local)
 {
        struct multi_pack_index *m = NULL;
        int fd;
@@ -73,6 +73,7 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir)
        m->fd = fd;
        m->data = midx_map;
        m->data_len = midx_size;
+       m->local = local;
 
        m->signature = get_be32(m->data);
        if (m->signature != MIDX_SIGNATURE) {
@@ -209,7 +210,7 @@ static int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id)
        strbuf_addf(&pack_name, "%s/pack/%s", m->object_dir,
                    m->pack_names[pack_int_id]);
 
-       m->packs[pack_int_id] = add_packed_git(pack_name.buf, pack_name.len, 1);
+       m->packs[pack_int_id] = add_packed_git(pack_name.buf, pack_name.len, m->local);
        strbuf_release(&pack_name);
        return !m->packs[pack_int_id];
 }
@@ -318,7 +319,7 @@ int midx_contains_pack(struct multi_pack_index *m, const char *idx_name)
        return 0;
 }
 
-int prepare_multi_pack_index_one(struct repository *r, const char *object_dir)
+int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local)
 {
        struct multi_pack_index *m = r->objects->multi_pack_index;
        struct multi_pack_index *m_search;
@@ -332,7 +333,7 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir)
                if (!strcmp(object_dir, m_search->object_dir))
                        return 1;
 
-       r->objects->multi_pack_index = load_multi_pack_index(object_dir);
+       r->objects->multi_pack_index = load_multi_pack_index(object_dir, local);
 
        if (r->objects->multi_pack_index) {
                r->objects->multi_pack_index->next = m;
@@ -746,7 +747,7 @@ int write_midx_file(const char *object_dir)
                          midx_name);
        }
 
-       packs.m = load_multi_pack_index(object_dir);
+       packs.m = load_multi_pack_index(object_dir, 1);
 
        packs.nr = 0;
        packs.alloc_list = packs.m ? packs.m->num_packs : 16;
diff --git a/midx.h b/midx.h
index e3b07f15862a75823e3a4ec81db8e87af86fc527..8aa79f4b628fea9b26654a9c4ba4172ab3327162 100644 (file)
--- a/midx.h
+++ b/midx.h
@@ -18,6 +18,8 @@ struct multi_pack_index {
        uint32_t num_packs;
        uint32_t num_objects;
 
+       int local;
+
        const unsigned char *chunk_pack_names;
        const uint32_t *chunk_oid_fanout;
        const unsigned char *chunk_oid_lookup;
@@ -29,14 +31,14 @@ struct multi_pack_index {
        char object_dir[FLEX_ARRAY];
 };
 
-struct multi_pack_index *load_multi_pack_index(const char *object_dir);
+struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);
 int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result);
 struct object_id *nth_midxed_object_oid(struct object_id *oid,
                                        struct multi_pack_index *m,
                                        uint32_t n);
 int fill_midx_entry(const struct object_id *oid, struct pack_entry *e, struct multi_pack_index *m);
 int midx_contains_pack(struct multi_pack_index *m, const char *idx_name);
-int prepare_multi_pack_index_one(struct repository *r, const char *object_dir);
+int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local);
 
 int write_midx_file(const char *object_dir);
 void clear_midx_file(const char *object_dir);
index 12db1a9d7d6251016627e6bc4ac80e55206489c5..896da460ac7779b698b95a52c4bab09c19732e03 100644 (file)
@@ -963,11 +963,11 @@ static void prepare_packed_git(struct repository *r)
 
        if (r->objects->packed_git_initialized)
                return;
-       prepare_multi_pack_index_one(r, r->objects->objectdir);
+       prepare_multi_pack_index_one(r, r->objects->objectdir, 1);
        prepare_packed_git_one(r, r->objects->objectdir, 1);
        prepare_alt_odb(r);
        for (alt = r->objects->alt_odb_list; alt; alt = alt->next) {
-               prepare_multi_pack_index_one(r, alt->path);
+               prepare_multi_pack_index_one(r, alt->path, 0);
                prepare_packed_git_one(r, alt->path, 0);
        }
        rearrange_packed_git(r);
index 8e19972e8939d176999904edaeba13c1d8c5f3a8..831b586d022215ff75b4e426d79e7149b3bfb3bb 100644 (file)
@@ -7,7 +7,7 @@
 static int read_midx_file(const char *object_dir)
 {
        uint32_t i;
-       struct multi_pack_index *m = load_multi_pack_index(object_dir);
+       struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
 
        if (!m)
                return 1;