multi-pack-index: store local property
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>
Derrick Stolee committed
Aug 20, 2018 at 16:51 UTC
2cf489a3bf75d7569c228147c3d9c559f02fd62c
4 files changed
+13
-10
midx.c
+6
-5
@@ -37,7 +37,7 @@ static char *get_midx_filename(const char *object_dir)
37
return xstrfmt("%s/pack/multi-pack-index", object_dir);
38
}
39
40
-struct multi_pack_index *load_multi_pack_index(const char *object_dir)
40
+struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local)
41
{
42
struct multi_pack_index *m = NULL;
43
int fd;
@@ -73,6 +73,7 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir)
73
m->fd = fd;
74
m->data = midx_map;
75
m->data_len = midx_size;
76
+ m->local = local;
77
78
m->signature = get_be32(m->data);
79
if (m->signature != MIDX_SIGNATURE) {
@@ -209,7 +210,7 @@ static int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id)
210
strbuf_addf(&pack_name, "%s/pack/%s", m->object_dir,
211
m->pack_names[pack_int_id]);
212
212
- m->packs[pack_int_id] = add_packed_git(pack_name.buf, pack_name.len, 1);
213
+ m->packs[pack_int_id] = add_packed_git(pack_name.buf, pack_name.len, m->local);
214
strbuf_release(&pack_name);
215
return !m->packs[pack_int_id];
216
}
@@ -318,7 +319,7 @@ int midx_contains_pack(struct multi_pack_index *m, const char *idx_name)
319
return 0;
320
}
321
321
-int prepare_multi_pack_index_one(struct repository *r, const char *object_dir)
322
+int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local)
323
{
324
struct multi_pack_index *m = r->objects->multi_pack_index;
325
struct multi_pack_index *m_search;
@@ -332,7 +333,7 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir)
333
if (!strcmp(object_dir, m_search->object_dir))
334
return 1;
335
335
- r->objects->multi_pack_index = load_multi_pack_index(object_dir);
336
+ r->objects->multi_pack_index = load_multi_pack_index(object_dir, local);
337
338
if (r->objects->multi_pack_index) {
339
r->objects->multi_pack_index->next = m;
@@ -746,7 +747,7 @@ int write_midx_file(const char *object_dir)
747
midx_name);
748
}
749
749
- packs.m = load_multi_pack_index(object_dir);
750
+ packs.m = load_multi_pack_index(object_dir, 1);
751
752
packs.nr = 0;
753
packs.alloc_list = packs.m ? packs.m->num_packs : 16;
midx.h
+4
-2
@@ -18,6 +18,8 @@ struct multi_pack_index {
18
uint32_t num_packs;
19
uint32_t num_objects;
20
21
+ int local;
22
+
23
const unsigned char *chunk_pack_names;
24
const uint32_t *chunk_oid_fanout;
25
const unsigned char *chunk_oid_lookup;
@@ -29,14 +31,14 @@ struct multi_pack_index {
31
char object_dir[FLEX_ARRAY];
32
};
33
32
-struct multi_pack_index *load_multi_pack_index(const char *object_dir);
34
+struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);
35
int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result);
36
struct object_id *nth_midxed_object_oid(struct object_id *oid,
37
struct multi_pack_index *m,
38
uint32_t n);
39
int fill_midx_entry(const struct object_id *oid, struct pack_entry *e, struct multi_pack_index *m);
40
int midx_contains_pack(struct multi_pack_index *m, const char *idx_name);
39
-int prepare_multi_pack_index_one(struct repository *r, const char *object_dir);
41
+int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local);
42
43
int write_midx_file(const char *object_dir);
44
void clear_midx_file(const char *object_dir);
packfile.c
+2
-2
@@ -963,11 +963,11 @@ static void prepare_packed_git(struct repository *r)
963
964
if (r->objects->packed_git_initialized)
965
return;
966
- prepare_multi_pack_index_one(r, r->objects->objectdir);
966
+ prepare_multi_pack_index_one(r, r->objects->objectdir, 1);
967
prepare_packed_git_one(r, r->objects->objectdir, 1);
968
prepare_alt_odb(r);
969
for (alt = r->objects->alt_odb_list; alt; alt = alt->next) {
970
- prepare_multi_pack_index_one(r, alt->path);
970
+ prepare_multi_pack_index_one(r, alt->path, 0);
971
prepare_packed_git_one(r, alt->path, 0);
972
}
973
rearrange_packed_git(r);
t/helper/test-read-midx.c
+1
-1
@@ -7,7 +7,7 @@
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);
10
+ struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
11
12
if (!m)
13
return 1;