Skip to content

Commit

Permalink
Merge branch 'kn/the-repository' into seen
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
gitster committed Nov 5, 2024
2 parents 6f472c4 + 762f8f2 commit 4aa0e87
Show file tree
Hide file tree
Showing 36 changed files with 261 additions and 190 deletions.
7 changes: 4 additions & 3 deletions builtin/cat-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,15 +928,16 @@ static int batch_objects(struct batch_options *opt)
cb.seen = &seen;

for_each_loose_object(batch_unordered_loose, &cb, 0);
for_each_packed_object(batch_unordered_packed, &cb,
FOR_EACH_OBJECT_PACK_ORDER);
for_each_packed_object(the_repository, batch_unordered_packed,
&cb, FOR_EACH_OBJECT_PACK_ORDER);

oidset_clear(&seen);
} else {
struct oid_array sa = OID_ARRAY_INIT;

for_each_loose_object(collect_loose_object, &sa, 0);
for_each_packed_object(collect_packed_object, &sa, 0);
for_each_packed_object(the_repository, collect_packed_object,
&sa, 0);

oid_array_for_each_unique(&sa, batch_object_cb, &cb);

Expand Down
2 changes: 1 addition & 1 deletion builtin/count-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static int count_loose(const struct object_id *oid, const char *path,
else {
loose_size += on_disk_bytes(st);
loose++;
if (verbose && has_object_pack(oid))
if (verbose && has_object_pack(the_repository, oid))
packed_loose++;
}
return 0;
Expand Down
15 changes: 8 additions & 7 deletions builtin/fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ static void start_packfile(void)

p->pack_fd = pack_fd;
p->do_not_close = 1;
p->repo = the_repository;
pack_file = hashfd(pack_fd, p->pack_name);

pack_data = p;
Expand Down Expand Up @@ -805,19 +806,19 @@ static char *keep_pack(const char *curr_index_name)
struct strbuf name = STRBUF_INIT;
int keep_fd;

odb_pack_name(&name, pack_data->hash, "keep");
odb_pack_name(pack_data->repo, &name, pack_data->hash, "keep");
keep_fd = odb_pack_keep(name.buf);
if (keep_fd < 0)
die_errno("cannot create keep file");
write_or_die(keep_fd, keep_msg, strlen(keep_msg));
if (close(keep_fd))
die_errno("failed to write keep file");

odb_pack_name(&name, pack_data->hash, "pack");
odb_pack_name(pack_data->repo, &name, pack_data->hash, "pack");
if (finalize_object_file(pack_data->pack_name, name.buf))
die("cannot store pack file");

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

for (k = 0; k < pack_id; k++) {
struct packed_git *p = all_packs[k];
odb_pack_name(&name, p->hash, "keep");
odb_pack_name(p->repo, &name, p->hash, "keep");
unlink_or_warn(name.buf);
}
strbuf_release(&name);
Expand Down Expand Up @@ -888,7 +889,7 @@ static void end_packfile(void)
idx_name = keep_pack(create_index());

/* Register the packfile with core git's machinery. */
new_p = add_packed_git(idx_name, strlen(idx_name), 1);
new_p = add_packed_git(pack_data->repo, idx_name, strlen(idx_name), 1);
if (!new_p)
die("core git rejected index %s", idx_name);
all_packs[pack_id] = new_p;
Expand Down Expand Up @@ -3538,7 +3539,7 @@ static void parse_argv(void)
int cmd_fast_import(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
struct repository *repo)
{
unsigned int i;

Expand Down Expand Up @@ -3659,7 +3660,7 @@ int cmd_fast_import(int argc,
fprintf(stderr, " pools: %10lu KiB\n", (unsigned long)((tree_entry_allocd + fi_mem_pool.pool_alloc) /1024));
fprintf(stderr, " objects: %10" PRIuMAX " KiB\n", (alloc_count*sizeof(struct object_entry))/1024);
fprintf(stderr, "---------------------------------------------------------------------\n");
pack_report();
pack_report(repo);
fprintf(stderr, "---------------------------------------------------------------------\n");
fprintf(stderr, "\n");
}
Expand Down
20 changes: 12 additions & 8 deletions builtin/fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static int mark_object(struct object *obj, enum object_type type,
return 0;
obj->flags |= REACHABLE;

if (is_promisor_object(&obj->oid))
if (is_promisor_object(the_repository, &obj->oid))
/*
* Further recursion does not need to be performed on this
* object since it is a promisor object (so it does not need to
Expand Down Expand Up @@ -270,9 +270,9 @@ static void check_reachable_object(struct object *obj)
* do a full fsck
*/
if (!(obj->flags & HAS_OBJ)) {
if (is_promisor_object(&obj->oid))
if (is_promisor_object(the_repository, &obj->oid))
return;
if (has_object_pack(&obj->oid))
if (has_object_pack(the_repository, &obj->oid))
return; /* it is in pack - forget about it */
printf_ln(_("missing %s %s"),
printable_type(&obj->oid, obj->type),
Expand Down Expand Up @@ -391,7 +391,10 @@ static void check_connectivity(void)
* traversal.
*/
for_each_loose_object(mark_loose_unreachable_referents, NULL, 0);
for_each_packed_object(mark_packed_unreachable_referents, NULL, 0);
for_each_packed_object(the_repository,
mark_packed_unreachable_referents,
NULL,
0);
}

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

obj = parse_object(the_repository, oid);
if (!obj) {
if (is_promisor_object(oid)) {
if (is_promisor_object(the_repository, oid)) {
/*
* Increment default_refs anyway, because this is a
* valid ref.
Expand Down Expand Up @@ -966,7 +969,8 @@ int cmd_fsck(int argc,

if (connectivity_only) {
for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
for_each_packed_object(mark_packed_for_connectivity, NULL, 0);
for_each_packed_object(the_repository,
mark_packed_for_connectivity, NULL, 0);
} else {
prepare_alt_odb(the_repository);
for (odb = the_repository->objects->odb; odb; odb = odb->next)
Expand Down Expand Up @@ -1011,7 +1015,7 @@ int cmd_fsck(int argc,
&oid);

if (!obj || !(obj->flags & HAS_OBJ)) {
if (is_promisor_object(&oid))
if (is_promisor_object(the_repository, &oid))
continue;
error(_("%s: object missing"), oid_to_hex(&oid));
errors_found |= ERROR_OBJECT;
Expand Down
5 changes: 4 additions & 1 deletion builtin/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ struct gc_config {
char *repack_filter_to;
unsigned long big_pack_threshold;
unsigned long max_delta_cache_size;
unsigned long delta_base_cache_limit;
};

#define GC_CONFIG_INIT { \
Expand All @@ -153,6 +154,7 @@ struct gc_config {
.prune_expire = xstrdup("2.weeks.ago"), \
.prune_worktrees_expire = xstrdup("3.months.ago"), \
.max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE, \
.delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT, \
}

static void gc_config_release(struct gc_config *cfg)
Expand Down Expand Up @@ -205,6 +207,7 @@ static void gc_config(struct gc_config *cfg)

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

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

Expand Down
20 changes: 13 additions & 7 deletions builtin/index-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ static void parse_pack_objects(unsigned char *hash)
* recursively checking if the resulting object is used as a base
* for some more deltas.
*/
static void resolve_deltas(void)
static void resolve_deltas(struct pack_idx_option *opts)
{
int i;

Expand All @@ -1307,7 +1307,7 @@ static void resolve_deltas(void)
nr_ref_deltas + nr_ofs_deltas);

nr_dispatched = 0;
base_cache_limit = delta_base_cache_limit * nr_threads;
base_cache_limit = opts->delta_base_cache_limit * nr_threads;
if (nr_threads > 1 || getenv("GIT_FORCE_THREADS")) {
init_thread();
work_lock();
Expand Down Expand Up @@ -1532,7 +1532,7 @@ static void write_special_file(const char *suffix, const char *msg,
if (pack_name)
filename = derive_filename(pack_name, "pack", suffix, &name_buf);
else
filename = odb_pack_name(&name_buf, hash, suffix);
filename = odb_pack_name(the_repository, &name_buf, hash, suffix);

fd = odb_pack_keep(filename);
if (fd < 0) {
Expand Down Expand Up @@ -1560,7 +1560,7 @@ static void rename_tmp_packfile(const char **final_name,
{
if (!*final_name || strcmp(*final_name, curr_name)) {
if (!*final_name)
*final_name = odb_pack_name(name, hash, ext);
*final_name = odb_pack_name(the_repository, name, hash, ext);
if (finalize_object_file(curr_name, *final_name))
die(_("unable to rename temporary '*.%s' file to '%s'"),
ext, *final_name);
Expand Down Expand Up @@ -1605,7 +1605,8 @@ static void final(const char *final_pack_name, const char *curr_pack_name,

if (do_fsck_object) {
struct packed_git *p;
p = add_packed_git(final_index_name, strlen(final_index_name), 0);
p = add_packed_git(the_repository, final_index_name,
strlen(final_index_name), 0);
if (p)
install_packed_git(the_repository, p);
}
Expand Down Expand Up @@ -1656,6 +1657,10 @@ static int git_index_pack_config(const char *k, const char *v,
else
opts->flags &= ~WRITE_REV;
}
if (!strcmp(k, "core.deltabasecachelimit")) {
opts->delta_base_cache_limit = git_config_ulong(k, v, ctx->kvi);
return 0;
}
return git_default_config(k, v, ctx, cb);
}

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

static void read_idx_option(struct pack_idx_option *opts, const char *pack_name)
{
struct packed_git *p = add_packed_git(pack_name, strlen(pack_name), 1);
struct packed_git *p = add_packed_git(the_repository, pack_name,
strlen(pack_name), 1);

if (!p)
die(_("Cannot open existing pack file '%s'"), pack_name);
Expand Down Expand Up @@ -2033,7 +2039,7 @@ int cmd_index_pack(int argc,
parse_pack_objects(pack_hash);
if (report_end_of_input)
write_in_full(2, "\0", 1);
resolve_deltas();
resolve_deltas(&opts);
conclude_pack(fix_thin_pack, curr_pack, pack_hash);
free(ofs_deltas);
free(ref_deltas);
Expand Down
11 changes: 7 additions & 4 deletions builtin/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ static int want_found_object(const struct object_id *oid, int exclude,
return 0;
if (ignore_packed_keep_in_core && p->pack_keep_in_core)
return 0;
if (has_object_kept_pack(oid, flags))
if (has_object_kept_pack(p->repo, oid, flags))
return 0;
}

Expand Down Expand Up @@ -3636,7 +3636,7 @@ static void show_cruft_commit(struct commit *commit, void *data)

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

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

show_object(obj, name, data);
Expand Down Expand Up @@ -3936,7 +3937,9 @@ static int add_object_in_unpacked_pack(const struct object_id *oid,

static void add_objects_in_unpacked_packs(void)
{
if (for_each_packed_object(add_object_in_unpacked_pack, NULL,
if (for_each_packed_object(to_pack.repo,
add_object_in_unpacked_pack,
NULL,
FOR_EACH_OBJECT_PACK_ORDER |
FOR_EACH_OBJECT_LOCAL_ONLY |
FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS |
Expand Down
2 changes: 1 addition & 1 deletion builtin/pack-redundant.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s
pl = red = pack_list_difference(local_packs, min);
while (pl) {
printf("%s\n%s\n",
odb_pack_name(&idx_name, pl->pack->hash, "idx"),
odb_pack_name(pl->pack->repo, &idx_name, pl->pack->hash, "idx"),
pl->pack->pack_name);
pl = pl->next;
}
Expand Down
2 changes: 1 addition & 1 deletion builtin/repack.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
* {type -> existing pack order} ordering when computing deltas instead
* of a {type -> size} ordering, which may produce better deltas.
*/
for_each_packed_object(write_oid, &cmd,
for_each_packed_object(the_repository, write_oid, &cmd,
FOR_EACH_OBJECT_PROMISOR_ONLY);

if (cmd.in == -1) {
Expand Down
2 changes: 1 addition & 1 deletion builtin/rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static inline void finish_object__ma(struct object *obj)
return;

case MA_ALLOW_PROMISOR:
if (is_promisor_object(&obj->oid))
if (is_promisor_object(the_repository, &obj->oid))
return;
die("unexpected missing %s object '%s'",
type_name(obj->type), oid_to_hex(&obj->oid));
Expand Down
4 changes: 2 additions & 2 deletions commit-graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
struct packed_git *p;
strbuf_setlen(&packname, dirlen);
strbuf_addstr(&packname, pack_indexes->items[i].string);
p = add_packed_git(packname.buf, packname.len, 1);
p = add_packed_git(ctx->r, packname.buf, packname.len, 1);
if (!p) {
ret = error(_("error adding pack %s"), packname.buf);
goto cleanup;
Expand Down Expand Up @@ -1960,7 +1960,7 @@ static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)
ctx->progress = start_delayed_progress(
_("Finding commits for commit graph among packed objects"),
ctx->approx_nr_objects);
for_each_packed_object(add_packed_commits, ctx,
for_each_packed_object(ctx->r, add_packed_commits, ctx,
FOR_EACH_OBJECT_PACK_ORDER);
if (ctx->progress_done < ctx->approx_nr_objects)
display_progress(ctx->progress, ctx->approx_nr_objects);
Expand Down
22 changes: 0 additions & 22 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1594,33 +1594,11 @@ static int git_default_core_config(const char *var, const char *value,
return 0;
}

if (!strcmp(var, "core.packedgitwindowsize")) {
int pgsz_x2 = getpagesize() * 2;
packed_git_window_size = git_config_ulong(var, value, ctx->kvi);

/* This value must be multiple of (pagesize * 2) */
packed_git_window_size /= pgsz_x2;
if (packed_git_window_size < 1)
packed_git_window_size = 1;
packed_git_window_size *= pgsz_x2;
return 0;
}

if (!strcmp(var, "core.bigfilethreshold")) {
big_file_threshold = git_config_ulong(var, value, ctx->kvi);
return 0;
}

if (!strcmp(var, "core.packedgitlimit")) {
packed_git_limit = git_config_ulong(var, value, ctx->kvi);
return 0;
}

if (!strcmp(var, "core.deltabasecachelimit")) {
delta_base_cache_limit = git_config_ulong(var, value, ctx->kvi);
return 0;
}

if (!strcmp(var, "core.autocrlf")) {
if (value && !strcasecmp(value, "input")) {
auto_crlf = AUTO_CRLF_INPUT;
Expand Down
Loading

0 comments on commit 4aa0e87

Please sign in to comment.