95
return 0;
96
}
97
98
-static struct multi_pack_index *load_multi_pack_index_one(struct repository *r,
99
- const char *object_dir,
100
- const char *midx_name,
101
- int local)
98
+static struct multi_pack_index *load_multi_pack_index_one(struct odb_source *source,
99
+ const char *midx_name)
100
{
101
+ struct repository *r = source->odb->repo;
102
struct multi_pack_index *m = NULL;
103
int fd;
104
struct stat st;
128
midx_map = xmmap(NULL, midx_size, PROT_READ, MAP_PRIVATE, fd, 0);
129
close(fd);
130
132
- FLEX_ALLOC_STR(m, object_dir, object_dir);
131
+ FLEX_ALLOC_STR(m, object_dir, source->path);
132
m->data = midx_map;
133
m->data_len = midx_size;
135
- m->local = local;
134
+ m->local = source->local;
135
m->repo = r;
136
137
m->signature = get_be32(m->data);
296
return 1;
297
}
298
300
-static struct multi_pack_index *load_midx_chain_fd_st(struct repository *r,
301
- const char *object_dir,
302
- int local,
299
+static struct multi_pack_index *load_midx_chain_fd_st(struct odb_source *source,
300
int fd, struct stat *st,
301
int *incomplete_chain)
302
{
303
+ const struct git_hash_algo *hash_algo = source->odb->repo->hash_algo;
304
struct multi_pack_index *midx_chain = NULL;
305
struct strbuf buf = STRBUF_INIT;
306
int valid = 1;
307
uint32_t i, count;
308
FILE *fp = xfdopen(fd, "r");
309
312
- count = st->st_size / (r->hash_algo->hexsz + 1);
310
+ count = st->st_size / (hash_algo->hexsz + 1);
311
312
for (i = 0; i < count; i++) {
313
struct multi_pack_index *m;
316
if (strbuf_getline_lf(&buf, fp) == EOF)
317
break;
318
321
- if (get_oid_hex_algop(buf.buf, &layer, r->hash_algo)) {
319
+ if (get_oid_hex_algop(buf.buf, &layer, hash_algo)) {
320
warning(_("invalid multi-pack-index chain: line '%s' "
321
"not a hash"),
322
buf.buf);
327
valid = 0;
328
329
strbuf_reset(&buf);
332
- get_split_midx_filename_ext(r->hash_algo, &buf, object_dir,
330
+ get_split_midx_filename_ext(hash_algo, &buf, source->path,
331
layer.hash, MIDX_EXT_MIDX);
334
- m = load_multi_pack_index_one(r, object_dir, buf.buf, local);
332
+ m = load_multi_pack_index_one(source, buf.buf);
333
334
if (m) {
335
if (add_midx_to_chain(m, midx_chain)) {
352
return midx_chain;
353
}
354
357
-static struct multi_pack_index *load_multi_pack_index_chain(struct repository *r,
358
- const char *object_dir,
359
- int local)
355
+static struct multi_pack_index *load_multi_pack_index_chain(struct odb_source *source)
356
{
357
struct strbuf chain_file = STRBUF_INIT;
358
struct stat st;
359
int fd;
360
struct multi_pack_index *m = NULL;
361
366
- get_midx_chain_filename(&chain_file, object_dir);
367
- if (open_multi_pack_index_chain(r->hash_algo, chain_file.buf, &fd, &st)) {
362
+ get_midx_chain_filename(&chain_file, source->path);
363
+ if (open_multi_pack_index_chain(source->odb->repo->hash_algo, chain_file.buf, &fd, &st)) {
364
int incomplete;
365
/* ownership of fd is taken over by load function */
370
- m = load_midx_chain_fd_st(r, object_dir, local, fd, &st,
371
- &incomplete);
366
+ m = load_midx_chain_fd_st(source, fd, &st, &incomplete);
367
}
368
369
strbuf_release(&chain_file);
370
return m;
371
}
372
378
-struct multi_pack_index *load_multi_pack_index(struct repository *r,
379
- const char *object_dir,
380
- int local)
373
+struct multi_pack_index *load_multi_pack_index(struct odb_source *source)
374
{
375
struct strbuf midx_name = STRBUF_INIT;
376
struct multi_pack_index *m;
377
385
- get_midx_filename(r->hash_algo, &midx_name, object_dir);
378
+ get_midx_filename(source->odb->repo->hash_algo, &midx_name,
379
+ source->path);
380
387
- m = load_multi_pack_index_one(r, object_dir,
388
- midx_name.buf, local);
381
+ m = load_multi_pack_index_one(source, midx_name.buf);
382
if (!m)
390
- m = load_multi_pack_index_chain(r, object_dir, local);
383
+ m = load_multi_pack_index_chain(source);
384
385
strbuf_release(&midx_name);
386
727
if (source->midx)
728
return 1;
729
737
- source->midx = load_multi_pack_index(r, source->path,
738
- source->local);
730
+ source->midx = load_multi_pack_index(source);
731
732
return !!source->midx;
733
}
872
display_progress(progress, _n); \
873
} while (0)
874
883
-int verify_midx_file(struct repository *r, const char *object_dir, unsigned flags)
875
+int verify_midx_file(struct odb_source *source, unsigned flags)
876
{
877
+ struct repository *r = source->odb->repo;
878
struct pair_pos_vs_id *pairs = NULL;
879
uint32_t i;
880
struct progress *progress = NULL;
888
- struct multi_pack_index *m = load_multi_pack_index(r, object_dir, 1);
881
+ struct multi_pack_index *m = load_multi_pack_index(source);
882
struct multi_pack_index *curr;
883
verify_midx_error = 0;
884
887
struct stat sb;
888
struct strbuf filename = STRBUF_INIT;
889
897
- get_midx_filename(r->hash_algo, &filename, object_dir);
890
+ get_midx_filename(r->hash_algo, &filename, source->path);
891
892
if (!stat(filename.buf, &sb)) {
893
error(_("multi-pack-index file exists, but failed to parse"));