Skip to content

Commit 6183661

Browse files
committed
Merge branch 'kn/the-repository' into seen
* kn/the-repository: 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 61cb387 + ca2fdbc commit 6183661

33 files changed

+226
-157
lines changed

builtin/cat-file.c

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

874874
for_each_loose_object(batch_unordered_loose, &cb, 0);
875-
for_each_packed_object(batch_unordered_packed, &cb,
876-
FOR_EACH_OBJECT_PACK_ORDER);
875+
for_each_packed_object(the_repository, batch_unordered_packed,
876+
&cb, FOR_EACH_OBJECT_PACK_ORDER);
877877

878878
oidset_clear(&seen);
879879
} else {
880880
struct oid_array sa = OID_ARRAY_INIT;
881881

882882
for_each_loose_object(collect_loose_object, &sa, 0);
883-
for_each_packed_object(collect_packed_object, &sa, 0);
883+
for_each_packed_object(the_repository, collect_packed_object,
884+
&sa, 0);
884885

885886
oid_array_for_each_unique(&sa, batch_object_cb, &cb);
886887

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(the_repository, &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(the_repository, &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(the_repository, &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(the_repository, 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: 4 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+
unsigned long 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)
@@ -205,6 +207,7 @@ static void gc_config(struct gc_config *cfg)
205207

206208
git_config_get_ulong("gc.bigpackthreshold", &cfg->big_pack_threshold);
207209
git_config_get_ulong("pack.deltacachesize", &cfg->max_delta_cache_size);
210+
git_config_get_ulong("core.deltabasecachelimit", &cfg->delta_base_cache_limit);
208211

209212
if (!git_config_get_string("gc.repackfilter", &owned)) {
210213
free(cfg->repack_filter);
@@ -416,7 +419,7 @@ static uint64_t estimate_repack_memory(struct gc_config *cfg,
416419
* read_sha1_file() (either at delta calculation phase, or
417420
* writing phase) also fills up the delta base cache
418421
*/
419-
heap += delta_base_cache_limit;
422+
heap += cfg->delta_base_cache_limit;
420423
/* and of course pack-objects has its own delta cache */
421424
heap += cfg->max_delta_cache_size;
422425

builtin/index-pack.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ static void parse_pack_objects(unsigned char *hash)
12381238
* recursively checking if the resulting object is used as a base
12391239
* for some more deltas.
12401240
*/
1241-
static void resolve_deltas(void)
1241+
static void resolve_deltas(struct pack_idx_option *opts)
12421242
{
12431243
int i;
12441244

@@ -1254,7 +1254,7 @@ static void resolve_deltas(void)
12541254
nr_ref_deltas + nr_ofs_deltas);
12551255

12561256
nr_dispatched = 0;
1257-
base_cache_limit = delta_base_cache_limit * nr_threads;
1257+
base_cache_limit = opts->delta_base_cache_limit * nr_threads;
12581258
if (nr_threads > 1 || getenv("GIT_FORCE_THREADS")) {
12591259
init_thread();
12601260
work_lock();
@@ -1479,7 +1479,7 @@ static void write_special_file(const char *suffix, const char *msg,
14791479
if (pack_name)
14801480
filename = derive_filename(pack_name, "pack", suffix, &name_buf);
14811481
else
1482-
filename = odb_pack_name(&name_buf, hash, suffix);
1482+
filename = odb_pack_name(the_repository, &name_buf, hash, suffix);
14831483

14841484
fd = odb_pack_keep(filename);
14851485
if (fd < 0) {
@@ -1507,7 +1507,7 @@ static void rename_tmp_packfile(const char **final_name,
15071507
{
15081508
if (!*final_name || strcmp(*final_name, curr_name)) {
15091509
if (!*final_name)
1510-
*final_name = odb_pack_name(name, hash, ext);
1510+
*final_name = odb_pack_name(the_repository, name, hash, ext);
15111511
if (finalize_object_file(curr_name, *final_name))
15121512
die(_("unable to rename temporary '*.%s' file to '%s'"),
15131513
ext, *final_name);
@@ -1552,7 +1552,8 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
15521552

15531553
if (do_fsck_object) {
15541554
struct packed_git *p;
1555-
p = add_packed_git(final_index_name, strlen(final_index_name), 0);
1555+
p = add_packed_git(the_repository, final_index_name,
1556+
strlen(final_index_name), 0);
15561557
if (p)
15571558
install_packed_git(the_repository, p);
15581559
}
@@ -1603,6 +1604,10 @@ static int git_index_pack_config(const char *k, const char *v,
16031604
else
16041605
opts->flags &= ~WRITE_REV;
16051606
}
1607+
if (!strcmp(k, "core.deltabasecachelimit")) {
1608+
opts->delta_base_cache_limit = git_config_ulong(k, v, ctx->kvi);
1609+
return 0;
1610+
}
16061611
return git_default_config(k, v, ctx, cb);
16071612
}
16081613

@@ -1650,7 +1655,8 @@ static void read_v2_anomalous_offsets(struct packed_git *p,
16501655

16511656
static void read_idx_option(struct pack_idx_option *opts, const char *pack_name)
16521657
{
1653-
struct packed_git *p = add_packed_git(pack_name, strlen(pack_name), 1);
1658+
struct packed_git *p = add_packed_git(the_repository, pack_name,
1659+
strlen(pack_name), 1);
16541660

16551661
if (!p)
16561662
die(_("Cannot open existing pack file '%s'"), pack_name);
@@ -1928,7 +1934,7 @@ int cmd_index_pack(int argc,
19281934
parse_pack_objects(pack_hash);
19291935
if (report_end_of_input)
19301936
write_in_full(2, "\0", 1);
1931-
resolve_deltas();
1937+
resolve_deltas(&opts);
19321938
conclude_pack(fix_thin_pack, curr_pack, pack_hash);
19331939
free(ofs_deltas);
19341940
free(ref_deltas);

builtin/pack-objects.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ static int want_found_object(const struct object_id *oid, int exclude,
15401540
return 0;
15411541
if (ignore_packed_keep_in_core && p->pack_keep_in_core)
15421542
return 0;
1543-
if (has_object_kept_pack(oid, flags))
1543+
if (has_object_kept_pack(the_repository, oid, flags))
15441544
return 0;
15451545
}
15461546

@@ -3849,7 +3849,7 @@ static void show_cruft_commit(struct commit *commit, void *data)
38493849

38503850
static int cruft_include_check_obj(struct object *obj, void *data UNUSED)
38513851
{
3852-
return !has_object_kept_pack(&obj->oid, IN_CORE_KEEP_PACKS);
3852+
return !has_object_kept_pack(the_repository, &obj->oid, IN_CORE_KEEP_PACKS);
38533853
}
38543854

38553855
static int cruft_include_check(struct commit *commit, void *data)
@@ -4080,7 +4080,8 @@ static void show_object__ma_allow_promisor(struct object *obj, const char *name,
40804080
* Quietly ignore EXPECTED missing objects. This avoids problems with
40814081
* staging them now and getting an odd error later.
40824082
*/
4083-
if (!has_object(the_repository, &obj->oid, 0) && is_promisor_object(&obj->oid))
4083+
if (!has_object(the_repository, &obj->oid, 0) &&
4084+
is_promisor_object(the_repository, &obj->oid))
40844085
return;
40854086

40864087
show_object(obj, name, data);
@@ -4149,7 +4150,9 @@ static int add_object_in_unpacked_pack(const struct object_id *oid,
41494150

41504151
static void add_objects_in_unpacked_packs(void)
41514152
{
4152-
if (for_each_packed_object(add_object_in_unpacked_pack, NULL,
4153+
if (for_each_packed_object(the_repository,
4154+
add_object_in_unpacked_pack,
4155+
NULL,
41534156
FOR_EACH_OBJECT_PACK_ORDER |
41544157
FOR_EACH_OBJECT_LOCAL_ONLY |
41554158
FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS |

builtin/pack-redundant.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ static void load_all(void)
589589
}
590590
}
591591

592-
int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) {
592+
int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo) {
593593
int i; int i_still_use_this = 0; struct pack_list *min = NULL, *red, *pl;
594594
struct llist *ignore;
595595
struct strbuf idx_name = STRBUF_INIT;
@@ -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(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)