Skip to content

Commit 08c83f2

Browse files
committed
Merge branch 'kn/the-repository' into seen
Various implicit uses of 'the_repoository' in the packfile code have been eliminated. * kn/the-repository: midx: add repository to `multi_pack_index` struct config: make `packed_git_(limit|window_size)` non-global variables config: make `delta_base_cache_limit` a non-global variable packfile: pass down repository to `for_each_packed_object` packfile: pass down repository to `has_object[_kept]_pack` packfile: pass down repository to `odb_pack_name` packfile: pass `repository` to static function in the file packfile: use `repository` from `packed_git` directly packfile: add repository to struct `packed_git`
2 parents 27b487d + 78e4bc3 commit 08c83f2

36 files changed

+268
-190
lines changed

builtin/cat-file.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,15 +927,16 @@ static int batch_objects(struct batch_options *opt)
927927
cb.seen = &seen;
928928

929929
for_each_loose_object(batch_unordered_loose, &cb, 0);
930-
for_each_packed_object(batch_unordered_packed, &cb,
931-
FOR_EACH_OBJECT_PACK_ORDER);
930+
for_each_packed_object(the_repository, batch_unordered_packed,
931+
&cb, FOR_EACH_OBJECT_PACK_ORDER);
932932

933933
oidset_clear(&seen);
934934
} else {
935935
struct oid_array sa = OID_ARRAY_INIT;
936936

937937
for_each_loose_object(collect_loose_object, &sa, 0);
938-
for_each_packed_object(collect_packed_object, &sa, 0);
938+
for_each_packed_object(the_repository, collect_packed_object,
939+
&sa, 0);
939940

940941
oid_array_for_each_unique(&sa, batch_object_cb, &cb);
941942

builtin/count-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static int count_loose(const struct object_id *oid, const char *path,
6767
else {
6868
loose_size += on_disk_bytes(st);
6969
loose++;
70-
if (verbose && has_object_pack(oid))
70+
if (verbose && has_object_pack(the_repository, oid))
7171
packed_loose++;
7272
}
7373
return 0;

builtin/fast-import.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,7 @@ static void start_packfile(void)
765765

766766
p->pack_fd = pack_fd;
767767
p->do_not_close = 1;
768+
p->repo = the_repository;
768769
pack_file = hashfd(pack_fd, p->pack_name);
769770

770771
pack_data = p;
@@ -805,19 +806,19 @@ static char *keep_pack(const char *curr_index_name)
805806
struct strbuf name = STRBUF_INIT;
806807
int keep_fd;
807808

808-
odb_pack_name(&name, pack_data->hash, "keep");
809+
odb_pack_name(pack_data->repo, &name, pack_data->hash, "keep");
809810
keep_fd = odb_pack_keep(name.buf);
810811
if (keep_fd < 0)
811812
die_errno("cannot create keep file");
812813
write_or_die(keep_fd, keep_msg, strlen(keep_msg));
813814
if (close(keep_fd))
814815
die_errno("failed to write keep file");
815816

816-
odb_pack_name(&name, pack_data->hash, "pack");
817+
odb_pack_name(pack_data->repo, &name, pack_data->hash, "pack");
817818
if (finalize_object_file(pack_data->pack_name, name.buf))
818819
die("cannot store pack file");
819820

820-
odb_pack_name(&name, pack_data->hash, "idx");
821+
odb_pack_name(pack_data->repo, &name, pack_data->hash, "idx");
821822
if (finalize_object_file(curr_index_name, name.buf))
822823
die("cannot store index file");
823824
free((void *)curr_index_name);
@@ -831,7 +832,7 @@ static void unkeep_all_packs(void)
831832

832833
for (k = 0; k < pack_id; k++) {
833834
struct packed_git *p = all_packs[k];
834-
odb_pack_name(&name, p->hash, "keep");
835+
odb_pack_name(p->repo, &name, p->hash, "keep");
835836
unlink_or_warn(name.buf);
836837
}
837838
strbuf_release(&name);
@@ -888,7 +889,7 @@ static void end_packfile(void)
888889
idx_name = keep_pack(create_index());
889890

890891
/* Register the packfile with core git's machinery. */
891-
new_p = add_packed_git(idx_name, strlen(idx_name), 1);
892+
new_p = add_packed_git(pack_data->repo, idx_name, strlen(idx_name), 1);
892893
if (!new_p)
893894
die("core git rejected index %s", idx_name);
894895
all_packs[pack_id] = new_p;
@@ -3538,7 +3539,7 @@ static void parse_argv(void)
35383539
int cmd_fast_import(int argc,
35393540
const char **argv,
35403541
const char *prefix,
3541-
struct repository *repo UNUSED)
3542+
struct repository *repo)
35423543
{
35433544
unsigned int i;
35443545

@@ -3659,7 +3660,7 @@ int cmd_fast_import(int argc,
36593660
fprintf(stderr, " pools: %10lu KiB\n", (unsigned long)((tree_entry_allocd + fi_mem_pool.pool_alloc) /1024));
36603661
fprintf(stderr, " objects: %10" PRIuMAX " KiB\n", (alloc_count*sizeof(struct object_entry))/1024);
36613662
fprintf(stderr, "---------------------------------------------------------------------\n");
3662-
pack_report();
3663+
pack_report(repo);
36633664
fprintf(stderr, "---------------------------------------------------------------------\n");
36643665
fprintf(stderr, "\n");
36653666
}

builtin/fsck.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static int mark_object(struct object *obj, enum object_type type,
150150
return 0;
151151
obj->flags |= REACHABLE;
152152

153-
if (is_promisor_object(&obj->oid))
153+
if (is_promisor_object(the_repository, &obj->oid))
154154
/*
155155
* Further recursion does not need to be performed on this
156156
* object since it is a promisor object (so it does not need to
@@ -270,9 +270,9 @@ static void check_reachable_object(struct object *obj)
270270
* do a full fsck
271271
*/
272272
if (!(obj->flags & HAS_OBJ)) {
273-
if (is_promisor_object(&obj->oid))
273+
if (is_promisor_object(the_repository, &obj->oid))
274274
return;
275-
if (has_object_pack(&obj->oid))
275+
if (has_object_pack(the_repository, &obj->oid))
276276
return; /* it is in pack - forget about it */
277277
printf_ln(_("missing %s %s"),
278278
printable_type(&obj->oid, obj->type),
@@ -391,7 +391,10 @@ static void check_connectivity(void)
391391
* traversal.
392392
*/
393393
for_each_loose_object(mark_loose_unreachable_referents, NULL, 0);
394-
for_each_packed_object(mark_packed_unreachable_referents, NULL, 0);
394+
for_each_packed_object(the_repository,
395+
mark_packed_unreachable_referents,
396+
NULL,
397+
0);
395398
}
396399

397400
/* Look up all the requirements, warn about missing objects.. */
@@ -488,7 +491,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
488491
refname, timestamp);
489492
obj->flags |= USED;
490493
mark_object_reachable(obj);
491-
} else if (!is_promisor_object(oid)) {
494+
} else if (!is_promisor_object(the_repository, oid)) {
492495
error(_("%s: invalid reflog entry %s"),
493496
refname, oid_to_hex(oid));
494497
errors_found |= ERROR_REACHABLE;
@@ -531,7 +534,7 @@ static int fsck_handle_ref(const char *refname, const char *referent UNUSED, con
531534

532535
obj = parse_object(the_repository, oid);
533536
if (!obj) {
534-
if (is_promisor_object(oid)) {
537+
if (is_promisor_object(the_repository, oid)) {
535538
/*
536539
* Increment default_refs anyway, because this is a
537540
* valid ref.
@@ -966,7 +969,8 @@ int cmd_fsck(int argc,
966969

967970
if (connectivity_only) {
968971
for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
969-
for_each_packed_object(mark_packed_for_connectivity, NULL, 0);
972+
for_each_packed_object(the_repository,
973+
mark_packed_for_connectivity, NULL, 0);
970974
} else {
971975
prepare_alt_odb(the_repository);
972976
for (odb = the_repository->objects->odb; odb; odb = odb->next)
@@ -1011,7 +1015,7 @@ int cmd_fsck(int argc,
10111015
&oid);
10121016

10131017
if (!obj || !(obj->flags & HAS_OBJ)) {
1014-
if (is_promisor_object(&oid))
1018+
if (is_promisor_object(the_repository, &oid))
10151019
continue;
10161020
error(_("%s: object missing"), oid_to_hex(&oid));
10171021
errors_found |= ERROR_OBJECT;

builtin/gc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ struct gc_config {
138138
char *repack_filter_to;
139139
unsigned long big_pack_threshold;
140140
unsigned long max_delta_cache_size;
141+
size_t delta_base_cache_limit;
141142
};
142143

143144
#define GC_CONFIG_INIT { \
@@ -153,6 +154,7 @@ struct gc_config {
153154
.prune_expire = xstrdup("2.weeks.ago"), \
154155
.prune_worktrees_expire = xstrdup("3.months.ago"), \
155156
.max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE, \
157+
.delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT, \
156158
}
157159

158160
static void gc_config_release(struct gc_config *cfg)
@@ -168,6 +170,7 @@ static void gc_config(struct gc_config *cfg)
168170
{
169171
const char *value;
170172
char *owned = NULL;
173+
unsigned long ulongval;
171174

172175
if (!git_config_get_value("gc.packrefs", &value)) {
173176
if (value && !strcmp(value, "notbare"))
@@ -206,6 +209,9 @@ static void gc_config(struct gc_config *cfg)
206209
git_config_get_ulong("gc.bigpackthreshold", &cfg->big_pack_threshold);
207210
git_config_get_ulong("pack.deltacachesize", &cfg->max_delta_cache_size);
208211

212+
if (!git_config_get_ulong("core.deltabasecachelimit", &ulongval))
213+
cfg->delta_base_cache_limit = ulongval;
214+
209215
if (!git_config_get_string("gc.repackfilter", &owned)) {
210216
free(cfg->repack_filter);
211217
cfg->repack_filter = owned;
@@ -416,7 +422,7 @@ static uint64_t estimate_repack_memory(struct gc_config *cfg,
416422
* read_sha1_file() (either at delta calculation phase, or
417423
* writing phase) also fills up the delta base cache
418424
*/
419-
heap += delta_base_cache_limit;
425+
heap += cfg->delta_base_cache_limit;
420426
/* and of course pack-objects has its own delta cache */
421427
heap += cfg->max_delta_cache_size;
422428

builtin/index-pack.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ static void parse_pack_objects(unsigned char *hash)
12911291
* recursively checking if the resulting object is used as a base
12921292
* for some more deltas.
12931293
*/
1294-
static void resolve_deltas(void)
1294+
static void resolve_deltas(struct pack_idx_option *opts)
12951295
{
12961296
int i;
12971297

@@ -1307,7 +1307,7 @@ static void resolve_deltas(void)
13071307
nr_ref_deltas + nr_ofs_deltas);
13081308

13091309
nr_dispatched = 0;
1310-
base_cache_limit = delta_base_cache_limit * nr_threads;
1310+
base_cache_limit = opts->delta_base_cache_limit * nr_threads;
13111311
if (nr_threads > 1 || getenv("GIT_FORCE_THREADS")) {
13121312
init_thread();
13131313
work_lock();
@@ -1532,7 +1532,7 @@ static void write_special_file(const char *suffix, const char *msg,
15321532
if (pack_name)
15331533
filename = derive_filename(pack_name, "pack", suffix, &name_buf);
15341534
else
1535-
filename = odb_pack_name(&name_buf, hash, suffix);
1535+
filename = odb_pack_name(the_repository, &name_buf, hash, suffix);
15361536

15371537
fd = odb_pack_keep(filename);
15381538
if (fd < 0) {
@@ -1560,7 +1560,7 @@ static void rename_tmp_packfile(const char **final_name,
15601560
{
15611561
if (!*final_name || strcmp(*final_name, curr_name)) {
15621562
if (!*final_name)
1563-
*final_name = odb_pack_name(name, hash, ext);
1563+
*final_name = odb_pack_name(the_repository, name, hash, ext);
15641564
if (finalize_object_file(curr_name, *final_name))
15651565
die(_("unable to rename temporary '*.%s' file to '%s'"),
15661566
ext, *final_name);
@@ -1605,7 +1605,8 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
16051605

16061606
if (do_fsck_object) {
16071607
struct packed_git *p;
1608-
p = add_packed_git(final_index_name, strlen(final_index_name), 0);
1608+
p = add_packed_git(the_repository, final_index_name,
1609+
strlen(final_index_name), 0);
16091610
if (p)
16101611
install_packed_git(the_repository, p);
16111612
}
@@ -1656,6 +1657,10 @@ static int git_index_pack_config(const char *k, const char *v,
16561657
else
16571658
opts->flags &= ~WRITE_REV;
16581659
}
1660+
if (!strcmp(k, "core.deltabasecachelimit")) {
1661+
opts->delta_base_cache_limit = git_config_ulong(k, v, ctx->kvi);
1662+
return 0;
1663+
}
16591664
return git_default_config(k, v, ctx, cb);
16601665
}
16611666

@@ -1703,7 +1708,8 @@ static void read_v2_anomalous_offsets(struct packed_git *p,
17031708

17041709
static void read_idx_option(struct pack_idx_option *opts, const char *pack_name)
17051710
{
1706-
struct packed_git *p = add_packed_git(pack_name, strlen(pack_name), 1);
1711+
struct packed_git *p = add_packed_git(the_repository, pack_name,
1712+
strlen(pack_name), 1);
17071713

17081714
if (!p)
17091715
die(_("Cannot open existing pack file '%s'"), pack_name);
@@ -2033,7 +2039,7 @@ int cmd_index_pack(int argc,
20332039
parse_pack_objects(pack_hash);
20342040
if (report_end_of_input)
20352041
write_in_full(2, "\0", 1);
2036-
resolve_deltas();
2042+
resolve_deltas(&opts);
20372043
conclude_pack(fix_thin_pack, curr_pack, pack_hash);
20382044
free(ofs_deltas);
20392045
free(ref_deltas);

builtin/pack-objects.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ static int want_found_object(const struct object_id *oid, int exclude,
15231523
return 0;
15241524
if (ignore_packed_keep_in_core && p->pack_keep_in_core)
15251525
return 0;
1526-
if (has_object_kept_pack(oid, flags))
1526+
if (has_object_kept_pack(p->repo, oid, flags))
15271527
return 0;
15281528
}
15291529

@@ -3621,7 +3621,7 @@ static void show_cruft_commit(struct commit *commit, void *data)
36213621

36223622
static int cruft_include_check_obj(struct object *obj, void *data UNUSED)
36233623
{
3624-
return !has_object_kept_pack(&obj->oid, IN_CORE_KEEP_PACKS);
3624+
return !has_object_kept_pack(to_pack.repo, &obj->oid, IN_CORE_KEEP_PACKS);
36253625
}
36263626

36273627
static int cruft_include_check(struct commit *commit, void *data)
@@ -3852,7 +3852,8 @@ static void show_object__ma_allow_promisor(struct object *obj, const char *name,
38523852
* Quietly ignore EXPECTED missing objects. This avoids problems with
38533853
* staging them now and getting an odd error later.
38543854
*/
3855-
if (!has_object(the_repository, &obj->oid, 0) && is_promisor_object(&obj->oid))
3855+
if (!has_object(the_repository, &obj->oid, 0) &&
3856+
is_promisor_object(to_pack.repo, &obj->oid))
38563857
return;
38573858

38583859
show_object(obj, name, data);
@@ -3921,7 +3922,9 @@ static int add_object_in_unpacked_pack(const struct object_id *oid,
39213922

39223923
static void add_objects_in_unpacked_packs(void)
39233924
{
3924-
if (for_each_packed_object(add_object_in_unpacked_pack, NULL,
3925+
if (for_each_packed_object(to_pack.repo,
3926+
add_object_in_unpacked_pack,
3927+
NULL,
39253928
FOR_EACH_OBJECT_PACK_ORDER |
39263929
FOR_EACH_OBJECT_LOCAL_ONLY |
39273930
FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS |

builtin/pack-redundant.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s
690690
pl = red = pack_list_difference(local_packs, min);
691691
while (pl) {
692692
printf("%s\n%s\n",
693-
odb_pack_name(&idx_name, pl->pack->hash, "idx"),
693+
odb_pack_name(pl->pack->repo, &idx_name, pl->pack->hash, "idx"),
694694
pl->pack->pack_name);
695695
pl = pl->next;
696696
}

builtin/repack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
409409
* {type -> existing pack order} ordering when computing deltas instead
410410
* of a {type -> size} ordering, which may produce better deltas.
411411
*/
412-
for_each_packed_object(write_oid, &cmd,
412+
for_each_packed_object(the_repository, write_oid, &cmd,
413413
FOR_EACH_OBJECT_PROMISOR_ONLY);
414414

415415
if (cmd.in == -1) {

builtin/rev-list.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static inline void finish_object__ma(struct object *obj)
121121
return;
122122

123123
case MA_ALLOW_PROMISOR:
124-
if (is_promisor_object(&obj->oid))
124+
if (is_promisor_object(the_repository, &obj->oid))
125125
return;
126126
die("unexpected missing %s object '%s'",
127127
type_name(obj->type), oid_to_hex(&obj->oid));

0 commit comments

Comments
 (0)