Skip to content

Commit 1bba44e

Browse files
committed
Merge branch 'ps/odb-source-packed' into ps/odb-generalize-prepare
* ps/odb-source-packed: odb/source-packed: drop pointer to "files" parent source midx: refactor interfaces to work on "packed" source odb/source-packed: stub out remaining functions odb/source-packed: wire up `freshen_object()` callback odb/source-packed: wire up `find_abbrev_len()` callback odb/source-packed: wire up `count_objects()` callback odb/source-packed: wire up `for_each_object()` callback odb/source-packed: wire up `read_object_stream()` callback odb/source-packed: wire up `read_object_info()` callback packfile: use higher-level interface to implement `has_object_pack()` odb/source-packed: wire up `reprepare()` callback odb/source-packed: wire up `close()` callback odb/source-packed: start converting to a proper `struct odb_source` odb/source-packed: store pointer to "files" instead of generic source packfile: move packed source into "odb/" subsystem packfile: split out packfile list logic packfile: rename `struct packfile_store` to `odb_source_packed`
2 parents 8d96f09 + 1bba3c0 commit 1bba44e

26 files changed

Lines changed: 1163 additions & 1079 deletions

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,7 @@ LIB_OBJS += odb/source.o
12181218
LIB_OBJS += odb/source-files.o
12191219
LIB_OBJS += odb/source-inmemory.o
12201220
LIB_OBJS += odb/source-loose.o
1221+
LIB_OBJS += odb/source-packed.o
12211222
LIB_OBJS += odb/streaming.o
12221223
LIB_OBJS += odb/transaction.o
12231224
LIB_OBJS += oid-array.o
@@ -1233,6 +1234,7 @@ LIB_OBJS += pack-refs.o
12331234
LIB_OBJS += pack-revindex.o
12341235
LIB_OBJS += pack-write.o
12351236
LIB_OBJS += packfile.o
1237+
LIB_OBJS += packfile-list.o
12361238
LIB_OBJS += pager.o
12371239
LIB_OBJS += parallel-checkout.o
12381240
LIB_OBJS += parse.o

builtin/cat-file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,8 +915,8 @@ static void batch_each_object(struct batch_options *opt,
915915

916916
for (source = the_repository->objects->sources; source; source = source->next) {
917917
struct odb_source_files *files = odb_source_files_downcast(source);
918-
int ret = packfile_store_for_each_object(files->packed, &oi,
919-
batch_one_object_oi, &payload, &opts);
918+
int ret = odb_source_for_each_object(&files->packed->base, &oi,
919+
batch_one_object_oi, &payload, &opts);
920920
if (ret)
921921
break;
922922
}

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ int cmd_grep(int argc,
13631363
odb_prepare_alternates(the_repository->objects);
13641364
for (source = the_repository->objects->sources; source; source = source->next) {
13651365
struct odb_source_files *files = odb_source_files_downcast(source);
1366-
packfile_store_prepare(files->packed);
1366+
odb_source_packed_prepare(files->packed);
13671367
}
13681368
}
13691369

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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,8 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
17771777
odb_prepare_alternates(the_repository->objects);
17781778

17791779
for (source = the_repository->objects->sources; source; source = source->next) {
1780-
struct multi_pack_index *m = get_multi_pack_index(source);
1780+
struct odb_source_files *files = odb_source_files_downcast(source);
1781+
struct multi_pack_index *m = get_multi_pack_index(files->packed);
17811782
struct pack_entry e;
17821783

17831784
if (m && fill_midx_entry(m, oid, &e)) {
@@ -4506,8 +4507,8 @@ static void add_objects_in_unpacked_packs(void)
45064507
if (!source->local)
45074508
continue;
45084509

4509-
if (packfile_store_for_each_object(files->packed, &oi,
4510-
add_object_in_unpacked_pack, NULL, &opts))
4510+
if (odb_source_for_each_object(&files->packed->base, &oi,
4511+
add_object_in_unpacked_pack, NULL, &opts))
45114512
die(_("cannot open pack index"));
45124513
}
45134514
}

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:

commit-graph.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,8 +2016,8 @@ static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)
20162016
odb_prepare_alternates(ctx->r->objects);
20172017
for (source = ctx->r->objects->sources; source; source = source->next) {
20182018
struct odb_source_files *files = odb_source_files_downcast(source);
2019-
packfile_store_for_each_object(files->packed, &oi, add_packed_commits_oi,
2020-
ctx, &opts);
2019+
odb_source_for_each_object(&files->packed->base, &oi, add_packed_commits_oi,
2020+
ctx, &opts);
20212021
}
20222022

20232023
if (ctx->progress_done < ctx->approx_nr_objects)

meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ libgit_sources = [
406406
'odb/source-files.c',
407407
'odb/source-inmemory.c',
408408
'odb/source-loose.c',
409+
'odb/source-packed.c',
409410
'odb/streaming.c',
410411
'odb/transaction.c',
411412
'oid-array.c',
@@ -421,6 +422,7 @@ libgit_sources = [
421422
'pack-revindex.c',
422423
'pack-write.c',
423424
'packfile.c',
425+
'packfile-list.c',
424426
'pager.c',
425427
'parallel-checkout.c',
426428
'parse.c',

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)