midx: refactor interfaces to work on "packed" source
Our interfaces used to interact with MIDXs all work on top of the generic `struct odb_source`. This doesn't make much sense though: a MIDX is strictly tied to the "packed" source, so passing in a generic source gives the false sense that it may also work with a different type of source. Fix this conceptual weirdness and instead require the caller to pass in a "packed" source explicitly. This also makes the next commit easier to implement, where we drop the pointer to the "files" source in the "packed" source. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Jun 17, 2026 at 08:39 UTC
7fa8c61afe29bfb82066c81a82ed6393f34dd704
13 files changed
+144
-129
builtin/multi-pack-index.c
+15
-14
@@ -10,6 +10,7 @@
10
#include "trace2.h"
11
#include "odb.h"
12
#include "odb/source.h"
13
+#include "odb/source-files.h"
14
#include "replace-object.h"
15
#include "repository.h"
16
@@ -85,12 +86,12 @@ static int parse_object_dir(const struct option *opt, const char *arg,
86
return 0;
87
}
88
88
-static struct odb_source *handle_object_dir_option(struct repository *repo)
89
+static struct odb_source_files *handle_object_dir_option(struct repository *repo)
90
{
91
struct odb_source *source = odb_find_source(repo->objects, opts.object_dir);
92
if (!source)
93
source = odb_add_to_alternates_memory(repo->objects, opts.object_dir);
93
- return source;
94
+ return odb_source_files_downcast(source);
95
}
96
97
static struct option common_opts[] = {
@@ -167,7 +168,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
168
N_("refs snapshot for selecting bitmap commits")),
169
OPT_END(),
170
};
170
- struct odb_source *source;
171
+ struct odb_source_files *source;
172
int ret;
173
174
opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
@@ -211,7 +212,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
212
213
read_packs_from_stdin(&packs);
214
214
- ret = write_midx_file_only(source, &packs,
215
+ ret = write_midx_file_only(source->packed, &packs,
216
opts.preferred_pack,
217
opts.refs_snapshot,
218
opts.incremental_base, opts.flags);
@@ -223,7 +224,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
224
225
}
226
226
- ret = write_midx_file(source, opts.preferred_pack,
227
+ ret = write_midx_file(source->packed, opts.preferred_pack,
228
opts.refs_snapshot, opts.flags);
229
230
free(opts.refs_snapshot);
@@ -237,7 +238,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
238
struct multi_pack_index *m, *cur;
239
struct multi_pack_index *from_midx = NULL;
240
struct multi_pack_index *to_midx = NULL;
240
- struct odb_source *source;
241
+ struct odb_source_files *source;
242
int ret;
243
244
struct option *options;
@@ -282,7 +283,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
283
284
FREE_AND_NULL(options);
285
285
- m = get_multi_pack_index(source);
286
+ m = get_multi_pack_index(source->packed);
287
288
for (cur = m; cur && !(from_midx && to_midx); cur = cur->base_midx) {
289
const char *midx_csum = midx_get_checksum_hex(cur);
@@ -305,7 +306,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
306
die(_("MIDX %s must be an ancestor of %s"), argv[0], argv[1]);
307
}
308
308
- ret = write_midx_file_compact(source, from_midx, to_midx,
309
+ ret = write_midx_file_compact(source->packed, from_midx, to_midx,
310
opts.incremental_base, opts.flags);
311
312
return ret;
@@ -319,7 +320,7 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
320
static struct option builtin_multi_pack_index_verify_options[] = {
321
OPT_END(),
322
};
322
- struct odb_source *source;
323
+ struct odb_source_files *source;
324
325
options = add_common_options(builtin_multi_pack_index_verify_options);
326
@@ -337,7 +338,7 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
338
339
FREE_AND_NULL(options);
340
340
- return verify_midx_file(source, opts.flags);
341
+ return verify_midx_file(source->packed, opts.flags);
342
}
343
344
static int cmd_multi_pack_index_expire(int argc, const char **argv,
@@ -348,7 +349,7 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
349
static struct option builtin_multi_pack_index_expire_options[] = {
350
OPT_END(),
351
};
351
- struct odb_source *source;
352
+ struct odb_source_files *source;
353
354
options = add_common_options(builtin_multi_pack_index_expire_options);
355
@@ -366,7 +367,7 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
367
368
FREE_AND_NULL(options);
369
369
- return expire_midx_packs(source, opts.flags);
370
+ return expire_midx_packs(source->packed, opts.flags);
371
}
372
373
static int cmd_multi_pack_index_repack(int argc, const char **argv,
@@ -379,7 +380,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
380
N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
381
OPT_END(),
382
};
382
- struct odb_source *source;
383
+ struct odb_source_files *source;
384
385
options = add_common_options(builtin_multi_pack_index_repack_options);
386
@@ -398,7 +399,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
399
400
FREE_AND_NULL(options);
401
401
- return midx_repack(source, (size_t)opts.batch_size, opts.flags);
402
+ return midx_repack(source->packed, (size_t)opts.batch_size, opts.flags);
403
}
404
405
int cmd_multi_pack_index(int argc,
builtin/pack-objects.c
+2
-1
@@ -1775,7 +1775,8 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
1775
odb_prepare_alternates(the_repository->objects);
1776
1777
for (source = the_repository->objects->sources; source; source = source->next) {
1778
- struct multi_pack_index *m = get_multi_pack_index(source);
1778
+ struct odb_source_files *files = odb_source_files_downcast(source);
1779
+ struct multi_pack_index *m = get_multi_pack_index(files->packed);
1780
struct pack_entry e;
1781
1782
if (m && fill_midx_entry(m, oid, &e)) {
builtin/repack.c
+6
-2
@@ -458,6 +458,8 @@ int cmd_repack(int argc,
458
}
459
460
if (!names.nr) {
461
+ struct odb_source_files *files = odb_source_files_downcast(existing.source);
462
+
463
if (!po_args.quiet)
464
printf_ln(_("Nothing new to pack."));
465
/*
@@ -473,7 +475,7 @@ int cmd_repack(int argc,
475
* midx_has_unknown_packs() will make the decision for
476
* us.
477
*/
476
- if (!get_multi_pack_index(existing.source))
478
+ if (!get_multi_pack_index(files->packed))
479
midx_must_contain_cruft = 1;
480
}
481
@@ -626,10 +628,12 @@ int cmd_repack(int argc,
628
update_server_info(repo, 0);
629
630
if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0)) {
631
+ struct odb_source_files *files = odb_source_files_downcast(existing.source);
632
unsigned flags = 0;
633
+
634
if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL, 0))
635
flags |= MIDX_WRITE_INCREMENTAL;
632
- write_midx_file(existing.source, NULL, NULL, flags);
636
+ write_midx_file(files->packed, NULL, NULL, flags);
637
}
638
639
cleanup:
midx-write.c
+17
-17
@@ -25,9 +25,9 @@
25
#define NO_PREFERRED_PACK (~((uint32_t)0))
26
27
extern int midx_checksum_valid(struct multi_pack_index *m);
28
-extern void clear_midx_files_ext(struct odb_source *source, const char *ext,
28
+extern void clear_midx_files_ext(struct odb_source_packed *source, const char *ext,
29
const char *keep_hash);
30
-extern void clear_incremental_midx_files_ext(struct odb_source *source,
30
+extern void clear_incremental_midx_files_ext(struct odb_source_packed *source,
31
const char *ext,
32
const struct strvec *keep_hashes);
33
extern int cmp_idx_or_pack_name(const char *idx_or_pack_name,
@@ -119,7 +119,7 @@ struct write_midx_context {
119
struct string_list *to_include;
120
121
struct repository *repo;
122
- struct odb_source *source;
122
+ struct odb_source_packed *source;
123
};
124
125
static uint32_t midx_pack_perm(struct write_midx_context *ctx,
@@ -1107,7 +1107,7 @@ done:
1107
return ret;
1108
}
1109
1110
-static void clear_midx_files(struct odb_source *source,
1110
+static void clear_midx_files(struct odb_source_packed *source,
1111
const struct strvec *hashes, unsigned incremental)
1112
{
1113
/*
@@ -1237,7 +1237,7 @@ static int midx_hashcmp(const struct multi_pack_index *a,
1237
}
1238
1239
struct write_midx_opts {
1240
- struct odb_source *source; /* non-optional */
1240
+ struct odb_source_packed *source; /* non-optional */
1241
1242
struct string_list *packs_to_include;
1243
struct string_list *packs_to_drop;
@@ -1253,7 +1253,7 @@ struct write_midx_opts {
1253
1254
static int write_midx_internal(struct write_midx_opts *opts)
1255
{
1256
- struct repository *r = opts->source->odb->repo;
1256
+ struct repository *r = opts->source->base.odb->repo;
1257
struct strbuf midx_name = STRBUF_INIT;
1258
unsigned char midx_hash[GIT_MAX_RAWSZ];
1259
uint32_t start_pack;
@@ -1301,7 +1301,7 @@ static int write_midx_internal(struct write_midx_opts *opts)
1301
if (ctx.incremental)
1302
strbuf_addf(&midx_name,
1303
"%s/pack/multi-pack-index.d/tmp_midx_XXXXXX",
1304
- opts->source->path);
1304
+ opts->source->base.path);
1305
else
1306
get_midx_filename(opts->source, &midx_name);
1307
if (safe_create_leading_directories(r, midx_name.buf))
@@ -1396,7 +1396,7 @@ static int write_midx_internal(struct write_midx_opts *opts)
1396
fill_packs_from_midx_range(&ctx, bitmap_order);
1397
} else {
1398
ctx.to_include = opts->packs_to_include;
1399
- for_each_file_in_pack_dir(opts->source->path, add_pack_to_midx, &ctx);
1399
+ for_each_file_in_pack_dir(opts->source->base.path, add_pack_to_midx, &ctx);
1400
}
1401
stop_progress(&ctx.progress);
1402
@@ -1847,7 +1847,7 @@ cleanup:
1847
return result;
1848
}
1849
1850
-int write_midx_file(struct odb_source *source,
1850
+int write_midx_file(struct odb_source_packed *source,
1851
const char *preferred_pack_name,
1852
const char *refs_snapshot,
1853
unsigned flags)
@@ -1862,7 +1862,7 @@ int write_midx_file(struct odb_source *source,
1862
return write_midx_internal(&opts);
1863
}
1864
1865
-int write_midx_file_only(struct odb_source *source,
1865
+int write_midx_file_only(struct odb_source_packed *source,
1866
struct string_list *packs_to_include,
1867
const char *preferred_pack_name,
1868
const char *refs_snapshot,
@@ -1881,7 +1881,7 @@ int write_midx_file_only(struct odb_source *source,
1881
return write_midx_internal(&opts);
1882
}
1883
1884
-int write_midx_file_compact(struct odb_source *source,
1884
+int write_midx_file_compact(struct odb_source_packed *source,
1885
struct multi_pack_index *from,
1886
struct multi_pack_index *to,
1887
const char *incremental_base,
@@ -1898,7 +1898,7 @@ int write_midx_file_compact(struct odb_source *source,
1898
return write_midx_internal(&opts);
1899
}
1900
1901
-int expire_midx_packs(struct odb_source *source, unsigned flags)
1901
+int expire_midx_packs(struct odb_source_packed *source, unsigned flags)
1902
{
1903
uint32_t i, *count, result = 0;
1904
struct string_list packs_to_drop = STRING_LIST_INIT_DUP;
@@ -1915,7 +1915,7 @@ int expire_midx_packs(struct odb_source *source, unsigned flags)
1915
1916
if (flags & MIDX_PROGRESS)
1917
progress = start_delayed_progress(
1918
- source->odb->repo,
1918
+ source->base.odb->repo,
1919
_("Counting referenced objects"),
1920
m->num_objects);
1921
for (i = 0; i < m->num_objects; i++) {
@@ -1927,7 +1927,7 @@ int expire_midx_packs(struct odb_source *source, unsigned flags)
1927
1928
if (flags & MIDX_PROGRESS)
1929
progress = start_delayed_progress(
1930
- source->odb->repo,
1930
+ source->base.odb->repo,
1931
_("Finding and deleting unreferenced packfiles"),
1932
m->num_packs);
1933
for (i = 0; i < m->num_packs; i++) {
@@ -2085,9 +2085,9 @@ static void fill_included_packs_batch(struct repository *r,
2085
free(pack_info);
2086
}
2087
2088
-int midx_repack(struct odb_source *source, size_t batch_size, unsigned flags)
2088
+int midx_repack(struct odb_source_packed *source, size_t batch_size, unsigned flags)
2089
{
2090
- struct repository *r = source->odb->repo;
2090
+ struct repository *r = source->base.odb->repo;
2091
int result = 0;
2092
uint32_t i, packs_to_repack = 0;
2093
unsigned char *include_pack;
@@ -2131,7 +2131,7 @@ int midx_repack(struct odb_source *source, size_t batch_size, unsigned flags)
2131
2132
strvec_push(&cmd.args, "pack-objects");
2133
2134
- strvec_pushf(&cmd.args, "%s/pack/pack", source->path);
2134
+ strvec_pushf(&cmd.args, "%s/pack/pack", source->base.path);
2135
2136
if (delta_base_offset)
2137
strvec_push(&cmd.args, "--delta-base-offset");
midx.c
+59
-59
@@ -17,9 +17,9 @@
17
#define MIDX_PACK_ERROR ((void *)(intptr_t)-1)
18
19
int midx_checksum_valid(struct multi_pack_index *m);
20
-void clear_midx_files_ext(struct odb_source *source, const char *ext,
20
+void clear_midx_files_ext(struct odb_source_packed *source, const char *ext,
21
const char *keep_hash);
22
-void clear_incremental_midx_files_ext(struct odb_source *source, const char *ext,
22
+void clear_incremental_midx_files_ext(struct odb_source_packed *source, const char *ext,
23
const struct strvec *keep_hashes);
24
int cmp_idx_or_pack_name(const char *idx_or_pack_name,
25
const char *idx_name);
@@ -27,25 +27,25 @@ int cmp_idx_or_pack_name(const char *idx_or_pack_name,
27
const char *midx_get_checksum_hex(const struct multi_pack_index *m)
28
{
29
return hash_to_hex_algop(midx_get_checksum_hash(m),
30
- m->source->odb->repo->hash_algo);
30
+ m->source->base.odb->repo->hash_algo);
31
}
32
33
const unsigned char *midx_get_checksum_hash(const struct multi_pack_index *m)
34
{
35
- return m->data + m->data_len - m->source->odb->repo->hash_algo->rawsz;
35
+ return m->data + m->data_len - m->source->base.odb->repo->hash_algo->rawsz;
36
}
37
38
-void get_midx_filename(struct odb_source *source, struct strbuf *out)
38
+void get_midx_filename(struct odb_source_packed *source, struct strbuf *out)
39
{
40
get_midx_filename_ext(source, out, NULL, NULL);
41
}
42
43
-void get_midx_filename_ext(struct odb_source *source, struct strbuf *out,
43
+void get_midx_filename_ext(struct odb_source_packed *source, struct strbuf *out,
44
const unsigned char *hash, const char *ext)
45
{
46
- strbuf_addf(out, "%s/pack/multi-pack-index", source->path);
46
+ strbuf_addf(out, "%s/pack/multi-pack-index", source->base.path);
47
if (ext)
48
- strbuf_addf(out, "-%s.%s", hash_to_hex_algop(hash, source->odb->repo->hash_algo), ext);
48
+ strbuf_addf(out, "-%s.%s", hash_to_hex_algop(hash, source->base.odb->repo->hash_algo), ext);
49
}
50
51
static int midx_read_oid_fanout(const unsigned char *chunk_start,
@@ -99,17 +99,16 @@ static int midx_read_object_offsets(const unsigned char *chunk_start,
99
return 0;
100
}
101
102
-struct multi_pack_index *get_multi_pack_index(struct odb_source *source)
102
+struct multi_pack_index *get_multi_pack_index(struct odb_source_packed *source)
103
{
104
- struct odb_source_files *files = odb_source_files_downcast(source);
105
- odb_source_packed_prepare(files->packed);
106
- return files->packed->midx;
104
+ odb_source_packed_prepare(source);
105
+ return source->midx;
106
}
107
109
-static struct multi_pack_index *load_multi_pack_index_one(struct odb_source *source,
108
+static struct multi_pack_index *load_multi_pack_index_one(struct odb_source_packed *source,
109
const char *midx_name)
110
{
112
- struct repository *r = source->odb->repo;
111
+ struct repository *r = source->base.odb->repo;
112
struct multi_pack_index *m = NULL;
113
int fd;
114
struct stat st;
@@ -234,23 +233,23 @@ cleanup_fail:
233
return NULL;
234
}
235
237
-void get_midx_chain_dirname(struct odb_source *source, struct strbuf *buf)
236
+void get_midx_chain_dirname(struct odb_source_packed *source, struct strbuf *buf)
237
{
239
- strbuf_addf(buf, "%s/pack/multi-pack-index.d", source->path);
238
+ strbuf_addf(buf, "%s/pack/multi-pack-index.d", source->base.path);
239
}
240
242
-void get_midx_chain_filename(struct odb_source *source, struct strbuf *buf)
241
+void get_midx_chain_filename(struct odb_source_packed *source, struct strbuf *buf)
242
{
243
get_midx_chain_dirname(source, buf);
244
strbuf_addstr(buf, "/multi-pack-index-chain");
245
}
246
248
-void get_split_midx_filename_ext(struct odb_source *source, struct strbuf *buf,
247
+void get_split_midx_filename_ext(struct odb_source_packed *source, struct strbuf *buf,
248
const unsigned char *hash, const char *ext)
249
{
250
get_midx_chain_dirname(source, buf);
251
strbuf_addf(buf, "/multi-pack-index-%s.%s",
253
- hash_to_hex_algop(hash, source->odb->repo->hash_algo), ext);
252
+ hash_to_hex_algop(hash, source->base.odb->repo->hash_algo), ext);
253
}
254
255
static int open_multi_pack_index_chain(const struct git_hash_algo *hash_algo,
@@ -306,11 +305,11 @@ static int add_midx_to_chain(struct multi_pack_index *midx,
305
return 1;
306
}
307
309
-static struct multi_pack_index *load_midx_chain_fd_st(struct odb_source *source,
308
+static struct multi_pack_index *load_midx_chain_fd_st(struct odb_source_packed *source,
309
int fd, struct stat *st,
310
int *incomplete_chain)
311
{
313
- const struct git_hash_algo *hash_algo = source->odb->repo->hash_algo;
312
+ const struct git_hash_algo *hash_algo = source->base.odb->repo->hash_algo;
313
struct multi_pack_index *midx_chain = NULL;
314
struct strbuf buf = STRBUF_INIT;
315
int valid = 1;
@@ -362,7 +361,7 @@ static struct multi_pack_index *load_midx_chain_fd_st(struct odb_source *source,
361
return midx_chain;
362
}
363
365
-static struct multi_pack_index *load_multi_pack_index_chain(struct odb_source *source)
364
+static struct multi_pack_index *load_multi_pack_index_chain(struct odb_source_packed *source)
365
{
366
struct strbuf chain_file = STRBUF_INIT;
367
struct stat st;
@@ -370,7 +369,8 @@ static struct multi_pack_index *load_multi_pack_index_chain(struct odb_source *s
369
struct multi_pack_index *m = NULL;
370
371
get_midx_chain_filename(source, &chain_file);
373
- if (open_multi_pack_index_chain(source->odb->repo->hash_algo, chain_file.buf, &fd, &st)) {
372
+ if (open_multi_pack_index_chain(source->base.odb->repo->hash_algo,
373
+ chain_file.buf, &fd, &st)) {
374
int incomplete;
375
/* ownership of fd is taken over by load function */
376
m = load_midx_chain_fd_st(source, fd, &st, &incomplete);
@@ -380,7 +380,7 @@ static struct multi_pack_index *load_multi_pack_index_chain(struct odb_source *s
380
return m;
381
}
382
383
-struct multi_pack_index *load_multi_pack_index(struct odb_source *source)
383
+struct multi_pack_index *load_multi_pack_index(struct odb_source_packed *source)
384
{
385
struct strbuf midx_name = STRBUF_INIT;
386
struct multi_pack_index *m;
@@ -456,7 +456,7 @@ static uint32_t midx_for_pack(struct multi_pack_index **_m,
456
int prepare_midx_pack(struct multi_pack_index *m,
457
uint32_t pack_int_id)
458
{
459
- struct odb_source_files *files = odb_source_files_downcast(m->source);
459
+ struct odb_source_packed *packed = m->source;
460
struct strbuf pack_name = STRBUF_INIT;
461
struct packed_git *p;
462
@@ -467,10 +467,10 @@ int prepare_midx_pack(struct multi_pack_index *m,
467
if (m->packs[pack_int_id])
468
return 0;
469
470
- strbuf_addf(&pack_name, "%s/pack/%s", files->base.path,
470
+ strbuf_addf(&pack_name, "%s/pack/%s", packed->base.path,
471
m->pack_names[pack_int_id]);
472
- p = packfile_store_load_pack(files->packed,
473
- pack_name.buf, files->base.local);
472
+ p = packfile_store_load_pack(packed,
473
+ pack_name.buf, packed->base.local);
474
strbuf_release(&pack_name);
475
476
if (!p) {
@@ -523,7 +523,7 @@ int bsearch_one_midx(const struct object_id *oid, struct multi_pack_index *m,
523
{
524
int ret = bsearch_hash(oid->hash, m->chunk_oid_fanout,
525
m->chunk_oid_lookup,
526
- m->source->odb->repo->hash_algo->rawsz,
526
+ m->source->base.odb->repo->hash_algo->rawsz,
527
result);
528
if (result)
529
*result += m->num_objects_in_base;
@@ -554,7 +554,7 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid,
554
n = midx_for_object(&m, n);
555
556
oidread(oid, m->chunk_oid_lookup + st_mult(m->hash_len, n),
557
- m->source->odb->repo->hash_algo);
557
+ m->source->base.odb->repo->hash_algo);
558
return oid;
559
}
560
@@ -734,26 +734,25 @@ int midx_preferred_pack(struct multi_pack_index *m, uint32_t *pack_int_id)
734
return 0;
735
}
736
737
-int prepare_multi_pack_index_one(struct odb_source *source)
737
+int prepare_multi_pack_index_one(struct odb_source_packed *source)
738
{
739
- struct odb_source_files *files = odb_source_files_downcast(source);
740
- struct repository *r = source->odb->repo;
739
+ struct repository *r = source->base.odb->repo;
740
741
prepare_repo_settings(r);
742
if (!r->settings.core_multi_pack_index)
743
return 0;
744
746
- if (files->packed->midx)
745
+ if (source->midx)
746
return 1;
747
749
- files->packed->midx = load_multi_pack_index(source);
748
+ source->midx = load_multi_pack_index(source);
749
751
- return !!files->packed->midx;
750
+ return !!source->midx;
751
}
752
753
int midx_checksum_valid(struct multi_pack_index *m)
754
{
756
- return hashfile_checksum_valid(m->source->odb->repo->hash_algo,
755
+ return hashfile_checksum_valid(m->source->base.odb->repo->hash_algo,
756
m->data, m->data_len);
757
}
758
@@ -776,7 +775,7 @@ static void clear_midx_file_ext(const char *full_path, size_t full_path_len UNUS
775
die_errno(_("failed to remove %s"), full_path);
776
}
777
779
-void clear_midx_files_ext(struct odb_source *source, const char *ext,
778
+void clear_midx_files_ext(struct odb_source_packed *source, const char *ext,
779
const char *keep_hash)
780
{
781
struct clear_midx_data data = {
@@ -793,12 +792,12 @@ void clear_midx_files_ext(struct odb_source *source, const char *ext,
792
strbuf_release(&buf);
793
}
794
796
- for_each_file_in_pack_dir(source->path, clear_midx_file_ext, &data);
795
+ for_each_file_in_pack_dir(source->base.path, clear_midx_file_ext, &data);
796
797
strset_clear(&data.keep);
798
}
799
801
-void clear_incremental_midx_files_ext(struct odb_source *source, const char *ext,
800
+void clear_incremental_midx_files_ext(struct odb_source_packed *source, const char *ext,
801
const struct strvec *keep_hashes)
802
{
803
struct clear_midx_data data = {
@@ -817,7 +816,7 @@ void clear_incremental_midx_files_ext(struct odb_source *source, const char *ext
816
}
817
}
818
820
- for_each_file_in_pack_subdir(source->path, "multi-pack-index.d",
819
+ for_each_file_in_pack_subdir(source->base.path, "multi-pack-index.d",
820
clear_midx_file_ext, &data);
821
822
strbuf_release(&buf);
@@ -826,26 +825,28 @@ void clear_incremental_midx_files_ext(struct odb_source *source, const char *ext
825
826
void clear_midx_file(struct repository *r)
827
{
828
+ struct odb_source_files *files;
829
struct strbuf midx = STRBUF_INIT;
830
831
- get_midx_filename(r->objects->sources, &midx);
832
-
831
if (r->objects) {
832
struct odb_source *source;
833
834
for (source = r->objects->sources; source; source = source->next) {
837
- struct odb_source_files *files = odb_source_files_downcast(source);
835
+ files = odb_source_files_downcast(source);
836
if (files->packed->midx)
837
close_midx(files->packed->midx);
838
files->packed->midx = NULL;
839
}
840
}
841
842
+ files = odb_source_files_downcast(r->objects->sources);
843
+ get_midx_filename(files->packed, &midx);
844
+
845
if (remove_path(midx.buf))
846
die(_("failed to clear multi-pack-index at %s"), midx.buf);
847
847
- clear_midx_files_ext(r->objects->sources, MIDX_EXT_BITMAP, NULL);
848
- clear_midx_files_ext(r->objects->sources, MIDX_EXT_REV, NULL);
848
+ clear_midx_files_ext(files->packed, MIDX_EXT_BITMAP, NULL);
849
+ clear_midx_files_ext(files->packed, MIDX_EXT_REV, NULL);
850
851
strbuf_release(&midx);
852
}
@@ -853,28 +854,27 @@ void clear_midx_file(struct repository *r)
854
void clear_incremental_midx_files(struct repository *r,
855
const struct strvec *keep_hashes)
856
{
856
- struct odb_source *source = r->objects->sources;
857
+ struct odb_source_files *files;
858
+ struct odb_source *source;
859
struct strbuf chain = STRBUF_INIT;
860
859
- get_midx_chain_filename(source, &chain);
860
-
861
- for (; source; source = source->next) {
862
- struct odb_source_files *files = odb_source_files_downcast(source);
861
+ for (source = r->objects->sources; source; source = source->next) {
862
+ files = odb_source_files_downcast(source);
863
if (files->packed->midx)
864
close_midx(files->packed->midx);
865
files->packed->midx = NULL;
866
}
867
868
+ files = odb_source_files_downcast(r->objects->sources);
869
+ get_midx_chain_filename(files->packed, &chain);
870
+
871
if (!keep_hashes && remove_path(chain.buf))
872
die(_("failed to clear multi-pack-index chain at %s"),
873
chain.buf);
874
872
- clear_incremental_midx_files_ext(r->objects->sources, MIDX_EXT_BITMAP,
873
- keep_hashes);
874
- clear_incremental_midx_files_ext(r->objects->sources, MIDX_EXT_REV,
875
- keep_hashes);
876
- clear_incremental_midx_files_ext(r->objects->sources, MIDX_EXT_MIDX,
877
- keep_hashes);
875
+ clear_incremental_midx_files_ext(files->packed, MIDX_EXT_BITMAP, keep_hashes);
876
+ clear_incremental_midx_files_ext(files->packed, MIDX_EXT_REV, keep_hashes);
877
+ clear_incremental_midx_files_ext(files->packed, MIDX_EXT_MIDX, keep_hashes);
878
879
strbuf_release(&chain);
880
}
@@ -918,9 +918,9 @@ static int compare_pair_pos_vs_id(const void *_a, const void *_b)
918
display_progress(progress, _n); \
919
} while (0)
920
921
-int verify_midx_file(struct odb_source *source, unsigned flags)
921
+int verify_midx_file(struct odb_source_packed *source, unsigned flags)
922
{
923
- struct repository *r = source->odb->repo;
923
+ struct repository *r = source->base.odb->repo;
924
struct pair_pos_vs_id *pairs = NULL;
925
uint32_t i;
926
struct progress *progress = NULL;
midx.h
+15
-15
@@ -37,7 +37,7 @@ struct strvec;
37
"GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL"
38
39
struct multi_pack_index {
40
- struct odb_source *source;
40
+ struct odb_source_packed *source;
41
42
const unsigned char *data;
43
size_t data_len;
@@ -92,16 +92,16 @@ struct multi_pack_index {
92
93
const char *midx_get_checksum_hex(const struct multi_pack_index *m) /* static buffer */;
94
const unsigned char *midx_get_checksum_hash(const struct multi_pack_index *m);
95
-void get_midx_filename(struct odb_source *source, struct strbuf *out);
96
-void get_midx_filename_ext(struct odb_source *source, struct strbuf *out,
95
+void get_midx_filename(struct odb_source_packed *source, struct strbuf *out);
96
+void get_midx_filename_ext(struct odb_source_packed *source, struct strbuf *out,
97
const unsigned char *hash, const char *ext);
98
-void get_midx_chain_dirname(struct odb_source *source, struct strbuf *out);
99
-void get_midx_chain_filename(struct odb_source *source, struct strbuf *out);
100
-void get_split_midx_filename_ext(struct odb_source *source, struct strbuf *buf,
98
+void get_midx_chain_dirname(struct odb_source_packed *source, struct strbuf *out);
99
+void get_midx_chain_filename(struct odb_source_packed *source, struct strbuf *out);
100
+void get_split_midx_filename_ext(struct odb_source_packed *source, struct strbuf *buf,
101
const unsigned char *hash, const char *ext);
102
103
-struct multi_pack_index *get_multi_pack_index(struct odb_source *source);
104
-struct multi_pack_index *load_multi_pack_index(struct odb_source *source);
103
+struct multi_pack_index *get_multi_pack_index(struct odb_source_packed *source);
104
+struct multi_pack_index *load_multi_pack_index(struct odb_source_packed *source);
105
int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id);
106
struct packed_git *nth_midxed_pack(struct multi_pack_index *m,
107
uint32_t pack_int_id);
@@ -123,22 +123,22 @@ int midx_contains_pack(struct multi_pack_index *m,
123
int midx_layer_contains_pack(struct multi_pack_index *m,
124
const char *idx_or_pack_name);
125
int midx_preferred_pack(struct multi_pack_index *m, uint32_t *pack_int_id);
126
-int prepare_multi_pack_index_one(struct odb_source *source);
126
+int prepare_multi_pack_index_one(struct odb_source_packed *source);
127
128
/*
129
* Variant of write_midx_file which writes a MIDX containing only the packs
130
* specified in packs_to_include.
131
*/
132
-int write_midx_file(struct odb_source *source,
132
+int write_midx_file(struct odb_source_packed *source,
133
const char *preferred_pack_name, const char *refs_snapshot,
134
unsigned flags);
135
-int write_midx_file_only(struct odb_source *source,
135
+int write_midx_file_only(struct odb_source_packed *source,
136
struct string_list *packs_to_include,
137
const char *preferred_pack_name,
138
const char *refs_snapshot,
139
const char *incremental_base,
140
unsigned flags);
141
-int write_midx_file_compact(struct odb_source *source,
141
+int write_midx_file_compact(struct odb_source_packed *source,
142
struct multi_pack_index *from,
143
struct multi_pack_index *to,
144
const char *incremental_base,
@@ -146,9 +146,9 @@ int write_midx_file_compact(struct odb_source *source,
146
void clear_midx_file(struct repository *r);
147
void clear_incremental_midx_files(struct repository *r,
148
const struct strvec *keep_hashes);
149
-int verify_midx_file(struct odb_source *source, unsigned flags);
150
-int expire_midx_packs(struct odb_source *source, unsigned flags);
151
-int midx_repack(struct odb_source *source, size_t batch_size, unsigned flags);
149
+int verify_midx_file(struct odb_source_packed *source, unsigned flags);
150
+int expire_midx_packs(struct odb_source_packed *source, unsigned flags);
151
+int midx_repack(struct odb_source_packed *source, size_t batch_size, unsigned flags);
152
153
void close_midx(struct multi_pack_index *m);
154
odb/source-packed.c
+6
-6
@@ -136,8 +136,8 @@ static int for_each_prefixed_object_in_midx(
136
137
for (; m; m = m->base_midx) {
138
uint32_t num, i, first = 0;
139
- int len = opts->prefix_hex_len > m->source->odb->repo->hash_algo->hexsz ?
140
- m->source->odb->repo->hash_algo->hexsz : opts->prefix_hex_len;
139
+ int len = opts->prefix_hex_len > m->source->base.odb->repo->hash_algo->hexsz ?
140
+ m->source->base.odb->repo->hash_algo->hexsz : opts->prefix_hex_len;
141
142
if (!m->num_objects)
143
continue;
@@ -249,7 +249,7 @@ static int odb_source_packed_for_each_prefixed_object(
249
250
store->skip_mru_updates = true;
251
252
- m = get_multi_pack_index(&store->files->base);
252
+ m = get_multi_pack_index(store);
253
if (m) {
254
ret = for_each_prefixed_object_in_midx(store, m, opts, data);
255
if (ret)
@@ -348,7 +348,7 @@ static int odb_source_packed_count_objects(struct odb_source *source,
348
unsigned long count = 0;
349
int ret;
350
351
- m = get_multi_pack_index(&packed->files->base);
351
+ m = get_multi_pack_index(packed);
352
if (m)
353
count += m->num_objects + m->num_objects_in_base;
354
@@ -465,7 +465,7 @@ static int odb_source_packed_find_abbrev_len(struct odb_source *source,
465
struct packfile_list_entry *e;
466
struct multi_pack_index *m;
467
468
- m = get_multi_pack_index(&packed->files->base);
468
+ m = get_multi_pack_index(packed);
469
if (m)
470
find_abbrev_len_for_midx(m, oid, min_len, &min_len);
471
@@ -674,7 +674,7 @@ void odb_source_packed_prepare(struct odb_source_packed *source)
674
if (source->initialized)
675
return;
676
677
- prepare_multi_pack_index_one(&source->files->base);
677
+ prepare_multi_pack_index_one(source);
678
prepare_packed_git_one(&source->files->base);
679
680
sort_packs(&source->packs.head, sort_pack);
pack-bitmap.c
+5
-3
@@ -238,7 +238,7 @@ static uint32_t bitmap_name_hash(struct bitmap_index *index, uint32_t pos)
238
static struct repository *bitmap_repo(struct bitmap_index *bitmap_git)
239
{
240
if (bitmap_is_midx(bitmap_git))
241
- return bitmap_git->midx->source->odb->repo;
241
+ return bitmap_git->midx->source->base.odb->repo;
242
return bitmap_git->pack->repo;
243
}
244
@@ -711,7 +711,8 @@ static int open_midx_bitmap(struct repository *r,
711
712
odb_prepare_alternates(r->objects);
713
for (source = r->objects->sources; source; source = source->next) {
714
- struct multi_pack_index *midx = get_multi_pack_index(source);
714
+ struct odb_source_files *files = odb_source_files_downcast(source);
715
+ struct multi_pack_index *midx = get_multi_pack_index(files->packed);
716
if (midx && !open_midx_bitmap_1(bitmap_git, midx))
717
ret = 0;
718
}
@@ -3399,7 +3400,8 @@ int verify_bitmap_files(struct repository *r)
3400
3401
odb_prepare_alternates(r->objects);
3402
for (source = r->objects->sources; source; source = source->next) {
3402
- struct multi_pack_index *m = get_multi_pack_index(source);
3403
+ struct odb_source_files *files = odb_source_files_downcast(source);
3404
+ struct multi_pack_index *m = get_multi_pack_index(files->packed);
3405
char *midx_bitmap_name;
3406
3407
if (!m)
pack-revindex.c
+3
-3
@@ -383,13 +383,13 @@ int load_midx_revindex(struct multi_pack_index *m)
383
* not want to accidentally call munmap() in the middle of the
384
* MIDX.
385
*/
386
- trace2_data_string("load_midx_revindex", m->source->odb->repo,
386
+ trace2_data_string("load_midx_revindex", m->source->base.odb->repo,
387
"source", "midx");
388
m->revindex_data = (const uint32_t *)m->chunk_revindex;
389
return 0;
390
}
391
392
- trace2_data_string("load_midx_revindex", m->source->odb->repo,
392
+ trace2_data_string("load_midx_revindex", m->source->base.odb->repo,
393
"source", "rev");
394
395
if (m->has_chain)
@@ -401,7 +401,7 @@ int load_midx_revindex(struct multi_pack_index *m)
401
midx_get_checksum_hash(m),
402
MIDX_EXT_REV);
403
404
- ret = load_revindex_from_disk(m->source->odb->repo->hash_algo,
404
+ ret = load_revindex_from_disk(m->source->base.odb->repo->hash_algo,
405
revindex_name.buf,
406
m->num_objects,
407
&m->revindex_map,
repack-geometry.c
+2
-1
@@ -32,7 +32,8 @@ void pack_geometry_init(struct pack_geometry *geometry,
32
{
33
struct packed_git *p;
34
struct strbuf buf = STRBUF_INIT;
35
- struct multi_pack_index *m = get_multi_pack_index(existing->source);
35
+ struct odb_source_files *files = odb_source_files_downcast(existing->source);
36
+ struct multi_pack_index *m = get_multi_pack_index(files->packed);
37
38
repo_for_each_pack(existing->repo, p) {
39
if (geometry->midx_layer_threshold_set && m &&
repack-midx.c
+6
-3
@@ -557,13 +557,14 @@ static void repack_make_midx_append_plan(struct repack_write_midx_opts *opts,
557
struct midx_compaction_step **steps_p,
558
size_t *steps_nr_p)
559
{
560
+ struct odb_source_files *files = odb_source_files_downcast(opts->existing->source);
561
struct multi_pack_index *m;
562
struct midx_compaction_step *steps = NULL;
563
struct midx_compaction_step *step;
564
size_t steps_nr = 0, steps_alloc = 0;
565
566
odb_reprepare(opts->existing->repo->objects);
566
- m = get_multi_pack_index(opts->existing->source);
567
+ m = get_multi_pack_index(files->packed);
568
569
if (opts->names->nr) {
570
struct strbuf buf = STRBUF_INIT;
@@ -606,6 +607,7 @@ static int repack_make_midx_compaction_plan(struct repack_write_midx_opts *opts,
607
struct midx_compaction_step **steps_p,
608
size_t *steps_nr_p)
609
{
610
+ struct odb_source_files *files = odb_source_files_downcast(opts->existing->source);
611
struct multi_pack_index *m;
612
struct midx_compaction_step *steps = NULL;
613
struct midx_compaction_step step = { 0 };
@@ -618,7 +620,7 @@ static int repack_make_midx_compaction_plan(struct repack_write_midx_opts *opts,
620
opts->existing->repo);
621
622
odb_reprepare(opts->existing->repo->objects);
621
- m = get_multi_pack_index(opts->existing->source);
623
+ m = get_multi_pack_index(files->packed);
624
625
for (i = 0; m && i < m->num_packs + m->num_packs_in_base; i++) {
626
if (prepare_midx_pack(m, i)) {
@@ -938,6 +940,7 @@ out:
940
941
static int write_midx_incremental(struct repack_write_midx_opts *opts)
942
{
943
+ struct odb_source_files *files = odb_source_files_downcast(opts->existing->source);
944
struct midx_compaction_step *steps = NULL;
945
struct strbuf lock_name = STRBUF_INIT;
946
struct lock_file lf;
@@ -946,7 +949,7 @@ static int write_midx_incremental(struct repack_write_midx_opts *opts)
949
size_t i;
950
int ret = 0;
951
949
- get_midx_chain_filename(opts->existing->source, &lock_name);
952
+ get_midx_chain_filename(files->packed, &lock_name);
953
if (safe_create_leading_directories(opts->existing->repo,
954
lock_name.buf))
955
die_errno(_("unable to create leading directories of %s"),
repack.c
+3
-3
@@ -59,10 +59,10 @@ void repack_remove_redundant_pack(struct repository *repo, const char *dir_name,
59
bool wrote_incremental_midx)
60
{
61
struct strbuf buf = STRBUF_INIT;
62
- struct odb_source *source = repo->objects->sources;
63
- struct multi_pack_index *m = get_multi_pack_index(source);
62
+ struct odb_source_files *files = odb_source_files_downcast(repo->objects->sources);
63
+ struct multi_pack_index *m = get_multi_pack_index(files->packed);
64
strbuf_addf(&buf, "%s.pack", base_name);
65
- if (m && source->local && midx_contains_pack(m, buf.buf)) {
65
+ if (m && files->base.local && midx_contains_pack(m, buf.buf)) {
66
clear_midx_file(repo);
67
if (!wrote_incremental_midx)
68
clear_incremental_midx_files(repo, NULL);
t/helper/test-read-midx.c
+5
-2
@@ -13,13 +13,16 @@
13
14
static struct multi_pack_index *setup_midx(const char *object_dir)
15
{
16
+ struct odb_source_files *files;
17
struct odb_source *source;
18
setup_git_directory(the_repository);
19
source = odb_find_source(the_repository->objects, object_dir);
20
if (!source)
21
source = odb_add_to_alternates_memory(the_repository->objects,
22
object_dir);
22
- return load_multi_pack_index(source);
23
+ files = odb_source_files_downcast(source);
24
+
25
+ return load_multi_pack_index(files->packed);
26
}
27
28
static int read_midx_file(const char *object_dir, const char *checksum,
@@ -70,7 +73,7 @@ static int read_midx_file(const char *object_dir, const char *checksum,
73
for (i = 0; i < m->num_packs; i++)
74
printf("%s\n", m->pack_names[i]);
75
73
- printf("object-dir: %s\n", m->source->path);
76
+ printf("object-dir: %s\n", m->source->base.path);
77
78
if (show_objects) {
79
struct object_id oid;