Skip to content

Commit 7fa8c61

Browse files
pks-tgitster
authored andcommitted
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>
1 parent f236b0c commit 7fa8c61

13 files changed

Lines changed: 144 additions & 129 deletions

builtin/multi-pack-index.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "trace2.h"
1111
#include "odb.h"
1212
#include "odb/source.h"
13+
#include "odb/source-files.h"
1314
#include "replace-object.h"
1415
#include "repository.h"
1516

@@ -85,12 +86,12 @@ static int parse_object_dir(const struct option *opt, const char *arg,
8586
return 0;
8687
}
8788

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)
8990
{
9091
struct odb_source *source = odb_find_source(repo->objects, opts.object_dir);
9192
if (!source)
9293
source = odb_add_to_alternates_memory(repo->objects, opts.object_dir);
93-
return source;
94+
return odb_source_files_downcast(source);
9495
}
9596

9697
static struct option common_opts[] = {
@@ -167,7 +168,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
167168
N_("refs snapshot for selecting bitmap commits")),
168169
OPT_END(),
169170
};
170-
struct odb_source *source;
171+
struct odb_source_files *source;
171172
int ret;
172173

173174
opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
@@ -211,7 +212,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
211212

212213
read_packs_from_stdin(&packs);
213214

214-
ret = write_midx_file_only(source, &packs,
215+
ret = write_midx_file_only(source->packed, &packs,
215216
opts.preferred_pack,
216217
opts.refs_snapshot,
217218
opts.incremental_base, opts.flags);
@@ -223,7 +224,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
223224

224225
}
225226

226-
ret = write_midx_file(source, opts.preferred_pack,
227+
ret = write_midx_file(source->packed, opts.preferred_pack,
227228
opts.refs_snapshot, opts.flags);
228229

229230
free(opts.refs_snapshot);
@@ -237,7 +238,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
237238
struct multi_pack_index *m, *cur;
238239
struct multi_pack_index *from_midx = NULL;
239240
struct multi_pack_index *to_midx = NULL;
240-
struct odb_source *source;
241+
struct odb_source_files *source;
241242
int ret;
242243

243244
struct option *options;
@@ -282,7 +283,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
282283

283284
FREE_AND_NULL(options);
284285

285-
m = get_multi_pack_index(source);
286+
m = get_multi_pack_index(source->packed);
286287

287288
for (cur = m; cur && !(from_midx && to_midx); cur = cur->base_midx) {
288289
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,
305306
die(_("MIDX %s must be an ancestor of %s"), argv[0], argv[1]);
306307
}
307308

308-
ret = write_midx_file_compact(source, from_midx, to_midx,
309+
ret = write_midx_file_compact(source->packed, from_midx, to_midx,
309310
opts.incremental_base, opts.flags);
310311

311312
return ret;
@@ -319,7 +320,7 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
319320
static struct option builtin_multi_pack_index_verify_options[] = {
320321
OPT_END(),
321322
};
322-
struct odb_source *source;
323+
struct odb_source_files *source;
323324

324325
options = add_common_options(builtin_multi_pack_index_verify_options);
325326

@@ -337,7 +338,7 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
337338

338339
FREE_AND_NULL(options);
339340

340-
return verify_midx_file(source, opts.flags);
341+
return verify_midx_file(source->packed, opts.flags);
341342
}
342343

343344
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,
348349
static struct option builtin_multi_pack_index_expire_options[] = {
349350
OPT_END(),
350351
};
351-
struct odb_source *source;
352+
struct odb_source_files *source;
352353

353354
options = add_common_options(builtin_multi_pack_index_expire_options);
354355

@@ -366,7 +367,7 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
366367

367368
FREE_AND_NULL(options);
368369

369-
return expire_midx_packs(source, opts.flags);
370+
return expire_midx_packs(source->packed, opts.flags);
370371
}
371372

372373
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,
379380
N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
380381
OPT_END(),
381382
};
382-
struct odb_source *source;
383+
struct odb_source_files *source;
383384

384385
options = add_common_options(builtin_multi_pack_index_repack_options);
385386

@@ -398,7 +399,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
398399

399400
FREE_AND_NULL(options);
400401

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);
402403
}
403404

404405
int cmd_multi_pack_index(int argc,

builtin/pack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,8 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
17751775
odb_prepare_alternates(the_repository->objects);
17761776

17771777
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);
17791780
struct pack_entry e;
17801781

17811782
if (m && fill_midx_entry(m, oid, &e)) {

builtin/repack.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ int cmd_repack(int argc,
458458
}
459459

460460
if (!names.nr) {
461+
struct odb_source_files *files = odb_source_files_downcast(existing.source);
462+
461463
if (!po_args.quiet)
462464
printf_ln(_("Nothing new to pack."));
463465
/*
@@ -473,7 +475,7 @@ int cmd_repack(int argc,
473475
* midx_has_unknown_packs() will make the decision for
474476
* us.
475477
*/
476-
if (!get_multi_pack_index(existing.source))
478+
if (!get_multi_pack_index(files->packed))
477479
midx_must_contain_cruft = 1;
478480
}
479481

@@ -626,10 +628,12 @@ int cmd_repack(int argc,
626628
update_server_info(repo, 0);
627629

628630
if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0)) {
631+
struct odb_source_files *files = odb_source_files_downcast(existing.source);
629632
unsigned flags = 0;
633+
630634
if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL, 0))
631635
flags |= MIDX_WRITE_INCREMENTAL;
632-
write_midx_file(existing.source, NULL, NULL, flags);
636+
write_midx_file(files->packed, NULL, NULL, flags);
633637
}
634638

635639
cleanup:

midx-write.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
#define NO_PREFERRED_PACK (~((uint32_t)0))
2626

2727
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,
2929
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,
3131
const char *ext,
3232
const struct strvec *keep_hashes);
3333
extern int cmp_idx_or_pack_name(const char *idx_or_pack_name,
@@ -119,7 +119,7 @@ struct write_midx_context {
119119
struct string_list *to_include;
120120

121121
struct repository *repo;
122-
struct odb_source *source;
122+
struct odb_source_packed *source;
123123
};
124124

125125
static uint32_t midx_pack_perm(struct write_midx_context *ctx,
@@ -1107,7 +1107,7 @@ static int link_midx_to_chain(struct multi_pack_index *m)
11071107
return ret;
11081108
}
11091109

1110-
static void clear_midx_files(struct odb_source *source,
1110+
static void clear_midx_files(struct odb_source_packed *source,
11111111
const struct strvec *hashes, unsigned incremental)
11121112
{
11131113
/*
@@ -1237,7 +1237,7 @@ static int midx_hashcmp(const struct multi_pack_index *a,
12371237
}
12381238

12391239
struct write_midx_opts {
1240-
struct odb_source *source; /* non-optional */
1240+
struct odb_source_packed *source; /* non-optional */
12411241

12421242
struct string_list *packs_to_include;
12431243
struct string_list *packs_to_drop;
@@ -1253,7 +1253,7 @@ struct write_midx_opts {
12531253

12541254
static int write_midx_internal(struct write_midx_opts *opts)
12551255
{
1256-
struct repository *r = opts->source->odb->repo;
1256+
struct repository *r = opts->source->base.odb->repo;
12571257
struct strbuf midx_name = STRBUF_INIT;
12581258
unsigned char midx_hash[GIT_MAX_RAWSZ];
12591259
uint32_t start_pack;
@@ -1301,7 +1301,7 @@ static int write_midx_internal(struct write_midx_opts *opts)
13011301
if (ctx.incremental)
13021302
strbuf_addf(&midx_name,
13031303
"%s/pack/multi-pack-index.d/tmp_midx_XXXXXX",
1304-
opts->source->path);
1304+
opts->source->base.path);
13051305
else
13061306
get_midx_filename(opts->source, &midx_name);
13071307
if (safe_create_leading_directories(r, midx_name.buf))
@@ -1396,7 +1396,7 @@ static int write_midx_internal(struct write_midx_opts *opts)
13961396
fill_packs_from_midx_range(&ctx, bitmap_order);
13971397
} else {
13981398
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);
14001400
}
14011401
stop_progress(&ctx.progress);
14021402

@@ -1847,7 +1847,7 @@ static int write_midx_internal(struct write_midx_opts *opts)
18471847
return result;
18481848
}
18491849

1850-
int write_midx_file(struct odb_source *source,
1850+
int write_midx_file(struct odb_source_packed *source,
18511851
const char *preferred_pack_name,
18521852
const char *refs_snapshot,
18531853
unsigned flags)
@@ -1862,7 +1862,7 @@ int write_midx_file(struct odb_source *source,
18621862
return write_midx_internal(&opts);
18631863
}
18641864

1865-
int write_midx_file_only(struct odb_source *source,
1865+
int write_midx_file_only(struct odb_source_packed *source,
18661866
struct string_list *packs_to_include,
18671867
const char *preferred_pack_name,
18681868
const char *refs_snapshot,
@@ -1881,7 +1881,7 @@ int write_midx_file_only(struct odb_source *source,
18811881
return write_midx_internal(&opts);
18821882
}
18831883

1884-
int write_midx_file_compact(struct odb_source *source,
1884+
int write_midx_file_compact(struct odb_source_packed *source,
18851885
struct multi_pack_index *from,
18861886
struct multi_pack_index *to,
18871887
const char *incremental_base,
@@ -1898,7 +1898,7 @@ int write_midx_file_compact(struct odb_source *source,
18981898
return write_midx_internal(&opts);
18991899
}
19001900

1901-
int expire_midx_packs(struct odb_source *source, unsigned flags)
1901+
int expire_midx_packs(struct odb_source_packed *source, unsigned flags)
19021902
{
19031903
uint32_t i, *count, result = 0;
19041904
struct string_list packs_to_drop = STRING_LIST_INIT_DUP;
@@ -1915,7 +1915,7 @@ int expire_midx_packs(struct odb_source *source, unsigned flags)
19151915

19161916
if (flags & MIDX_PROGRESS)
19171917
progress = start_delayed_progress(
1918-
source->odb->repo,
1918+
source->base.odb->repo,
19191919
_("Counting referenced objects"),
19201920
m->num_objects);
19211921
for (i = 0; i < m->num_objects; i++) {
@@ -1927,7 +1927,7 @@ int expire_midx_packs(struct odb_source *source, unsigned flags)
19271927

19281928
if (flags & MIDX_PROGRESS)
19291929
progress = start_delayed_progress(
1930-
source->odb->repo,
1930+
source->base.odb->repo,
19311931
_("Finding and deleting unreferenced packfiles"),
19321932
m->num_packs);
19331933
for (i = 0; i < m->num_packs; i++) {
@@ -2085,9 +2085,9 @@ static void fill_included_packs_batch(struct repository *r,
20852085
free(pack_info);
20862086
}
20872087

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)
20892089
{
2090-
struct repository *r = source->odb->repo;
2090+
struct repository *r = source->base.odb->repo;
20912091
int result = 0;
20922092
uint32_t i, packs_to_repack = 0;
20932093
unsigned char *include_pack;
@@ -2131,7 +2131,7 @@ int midx_repack(struct odb_source *source, size_t batch_size, unsigned flags)
21312131

21322132
strvec_push(&cmd.args, "pack-objects");
21332133

2134-
strvec_pushf(&cmd.args, "%s/pack/pack", source->path);
2134+
strvec_pushf(&cmd.args, "%s/pack/pack", source->base.path);
21352135

21362136
if (delta_base_offset)
21372137
strvec_push(&cmd.args, "--delta-base-offset");

0 commit comments

Comments
 (0)