object: stop depending on the_repository

There are a couple of functions exposed by "object.c" that implicitly
depend on `the_repository`. Remove this dependency by injecting the
repository via a parameter. Adapt callers accordingly by simply using
`the_repository`, except in cases where the subsystem is already free of
the repository. In that case, we instead pass the repository provided by
the caller's context.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2025-03-10 08:13:21 +01:00
committed by Junio C Hamano
parent 228457c9d9
commit 74d414c9f1
15 changed files with 48 additions and 44 deletions

View File

@@ -399,12 +399,12 @@ static void check_connectivity(void)
} }
/* Look up all the requirements, warn about missing objects.. */ /* Look up all the requirements, warn about missing objects.. */
max = get_max_object_index(); max = get_max_object_index(the_repository);
if (verbose) if (verbose)
fprintf_ln(stderr, _("Checking connectivity (%d objects)"), max); fprintf_ln(stderr, _("Checking connectivity (%d objects)"), max);
for (i = 0; i < max; i++) { for (i = 0; i < max; i++) {
struct object *obj = get_indexed_object(i); struct object *obj = get_indexed_object(the_repository, i);
if (obj) if (obj)
check_object(obj); check_object(obj);

View File

@@ -1144,7 +1144,7 @@ int cmd_grep(int argc,
break; break;
} }
object = parse_object_or_die(&oid, arg); object = parse_object_or_die(the_repository, &oid, arg);
if (!seen_dashdash) if (!seen_dashdash)
verify_non_filename(prefix, arg); verify_non_filename(prefix, arg);
add_object_array_with_path(object, arg, &list, oc.mode, oc.path); add_object_array_with_path(object, arg, &list, oc.mode, oc.path);

View File

@@ -279,14 +279,14 @@ static unsigned check_objects(void)
{ {
unsigned i, max, foreign_nr = 0; unsigned i, max, foreign_nr = 0;
max = get_max_object_index(); max = get_max_object_index(the_repository);
if (verbose) if (verbose)
progress = start_delayed_progress(the_repository, progress = start_delayed_progress(the_repository,
_("Checking objects"), max); _("Checking objects"), max);
for (i = 0; i < max; i++) { for (i = 0; i < max; i++) {
foreign_nr += check_object(get_indexed_object(i)); foreign_nr += check_object(get_indexed_object(the_repository, i));
display_progress(progress, i + 1); display_progress(progress, i + 1);
} }

View File

@@ -2468,7 +2468,7 @@ int cmd_format_patch(int argc,
base = get_base_commit(&cfg, list, nr); base = get_base_commit(&cfg, list, nr);
if (base) { if (base) {
reset_revision_walk(); reset_revision_walk();
clear_object_flags(UNINTERESTING); clear_object_flags(the_repository, UNINTERESTING);
prepare_bases(&bases, base, list, nr); prepare_bases(&bases, base, list, nr);
} }

View File

@@ -667,9 +667,9 @@ int cmd_name_rev(int argc,
} else if (all) { } else if (all) {
int i, max; int i, max;
max = get_max_object_index(); max = get_max_object_index(the_repository);
for (i = 0; i < max; i++) { for (i = 0; i < max; i++) {
struct object *obj = get_indexed_object(i); struct object *obj = get_indexed_object(the_repository, i);
if (!obj || obj->type != OBJ_COMMIT) if (!obj || obj->type != OBJ_COMMIT)
continue; continue;
show_name(obj, NULL, show_name(obj, NULL,

View File

@@ -4161,7 +4161,7 @@ static int mark_bitmap_preferred_tip(const char *refname,
if (!peel_iterated_oid(the_repository, oid, &peeled)) if (!peel_iterated_oid(the_repository, oid, &peeled))
oid = &peeled; oid = &peeled;
object = parse_object_or_die(oid, refname); object = parse_object_or_die(the_repository, oid, refname);
if (object->type == OBJ_COMMIT) if (object->type == OBJ_COMMIT)
object->flags |= NEEDS_BITMAP; object->flags |= NEEDS_BITMAP;

View File

@@ -185,7 +185,7 @@ int cmd_prune(int argc,
const char *name = *argv++; const char *name = *argv++;
if (!repo_get_oid(the_repository, name, &oid)) { if (!repo_get_oid(the_repository, name, &oid)) {
struct object *object = parse_object_or_die(&oid, struct object *object = parse_object_or_die(the_repository, &oid,
name); name);
add_pending_object(&revs, object, ""); add_pending_object(&revs, object, "");
} }

View File

@@ -708,7 +708,7 @@ static int add_ref_to_pending(const char *refname, const char *referent UNUSED,
if (!peel_iterated_oid(revs->repo, oid, &peeled)) if (!peel_iterated_oid(revs->repo, oid, &peeled))
oid = &peeled; oid = &peeled;
object = parse_object_or_die(oid, refname); object = parse_object_or_die(revs->repo, oid, refname);
if (object->type != OBJ_COMMIT) if (object->type != OBJ_COMMIT)
return 0; return 0;
@@ -768,7 +768,7 @@ static int read_refs_snapshot(const char *refs_snapshot,
if (*end) if (*end)
die(_("malformed line: %s"), buf.buf); die(_("malformed line: %s"), buf.buf);
object = parse_object_or_die(&oid, NULL); object = parse_object_or_die(revs->repo, &oid, NULL);
if (preferred) if (preferred)
object->flags |= NEEDS_BITMAP; object->flags |= NEEDS_BITMAP;

View File

@@ -1,4 +1,3 @@
#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS #define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h" #include "git-compat-util.h"
@@ -18,14 +17,15 @@
#include "commit-graph.h" #include "commit-graph.h"
#include "loose.h" #include "loose.h"
unsigned int get_max_object_index(void) unsigned int get_max_object_index(const struct repository *repo)
{ {
return the_repository->parsed_objects->obj_hash_size; return repo->parsed_objects->obj_hash_size;
} }
struct object *get_indexed_object(unsigned int idx) struct object *get_indexed_object(const struct repository *repo,
unsigned int idx)
{ {
return the_repository->parsed_objects->obj_hash[idx]; return repo->parsed_objects->obj_hash[idx];
} }
static const char *object_type_strings[] = { static const char *object_type_strings[] = {
@@ -283,10 +283,11 @@ struct object *parse_object_buffer(struct repository *r, const struct object_id
return obj; return obj;
} }
struct object *parse_object_or_die(const struct object_id *oid, struct object *parse_object_or_die(struct repository *repo,
const struct object_id *oid,
const char *name) const char *name)
{ {
struct object *o = parse_object(the_repository, oid); struct object *o = parse_object(repo, oid);
if (o) if (o)
return o; return o;
@@ -524,12 +525,12 @@ void object_array_remove_duplicates(struct object_array *array)
} }
} }
void clear_object_flags(unsigned flags) void clear_object_flags(struct repository *repo, unsigned flags)
{ {
int i; int i;
for (i=0; i < the_repository->parsed_objects->obj_hash_size; i++) { for (i=0; i < repo->parsed_objects->obj_hash_size; i++) {
struct object *obj = the_repository->parsed_objects->obj_hash[i]; struct object *obj = repo->parsed_objects->obj_hash[i];
if (obj) if (obj)
obj->flags &= ~flags; obj->flags &= ~flags;
} }

View File

@@ -169,12 +169,13 @@ int type_from_string_gently(const char *str, ssize_t, int gentle);
/* /*
* Return the current number of buckets in the object hashmap. * Return the current number of buckets in the object hashmap.
*/ */
unsigned int get_max_object_index(void); unsigned int get_max_object_index(const struct repository *repo);
/* /*
* Return the object from the specified bucket in the object hashmap. * Return the object from the specified bucket in the object hashmap.
*/ */
struct object *get_indexed_object(unsigned int); struct object *get_indexed_object(const struct repository *repo,
unsigned int);
/* /*
* This can be used to see if we have heard of the object before, but * This can be used to see if we have heard of the object before, but
@@ -231,7 +232,8 @@ struct object *parse_object_with_flags(struct repository *r,
* "name" parameter is not NULL, it is included in the error message * "name" parameter is not NULL, it is included in the error message
* (otherwise, the hex object ID is given). * (otherwise, the hex object ID is given).
*/ */
struct object *parse_object_or_die(const struct object_id *oid, const char *name); struct object *parse_object_or_die(struct repository *repo, const struct object_id *oid,
const char *name);
/* Given the result of read_sha1_file(), returns the object after /* Given the result of read_sha1_file(), returns the object after
* parsing it. eaten_p indicates if the object has a borrowed copy * parsing it. eaten_p indicates if the object has a borrowed copy
@@ -336,7 +338,7 @@ void object_array_remove_duplicates(struct object_array *array);
*/ */
void object_array_clear(struct object_array *array); void object_array_clear(struct object_array *array);
void clear_object_flags(unsigned flags); void clear_object_flags(struct repository *repo, unsigned flags);
/* /*
* Clear the specified object flags from all in-core commit objects from * Clear the specified object flags from all in-core commit objects from

View File

@@ -1301,7 +1301,7 @@ static struct bitmap *find_boundary_objects(struct bitmap_index *bitmap_git,
revs->tag_objects = tmp_tags; revs->tag_objects = tmp_tags;
reset_revision_walk(); reset_revision_walk();
clear_object_flags(UNINTERESTING); clear_object_flags(repo, UNINTERESTING);
/* /*
* Then add the boundary commit(s) as fill-in traversal tips. * Then add the boundary commit(s) as fill-in traversal tips.
@@ -1935,7 +1935,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
struct object *object = revs->pending.objects[i].item; struct object *object = revs->pending.objects[i].item;
if (object->type == OBJ_NONE) if (object->type == OBJ_NONE)
parse_object_or_die(&object->oid, NULL); parse_object_or_die(revs->repo, &object->oid, NULL);
while (object->type == OBJ_TAG) { while (object->type == OBJ_TAG) {
struct tag *tag = (struct tag *) object; struct tag *tag = (struct tag *) object;
@@ -1945,7 +1945,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
else else
object_list_insert(object, &wants); object_list_insert(object, &wants);
object = parse_object_or_die(get_tagged_oid(tag), NULL); object = parse_object_or_die(revs->repo, get_tagged_oid(tag), NULL);
object->flags |= (tag->object.flags & UNINTERESTING); object->flags |= (tag->object.flags & UNINTERESTING);
} }

View File

@@ -45,7 +45,7 @@ static void add_one_file(const char *path, struct rev_info *revs)
} }
strbuf_trim(&buf); strbuf_trim(&buf);
if (!get_oid_hex(buf.buf, &oid)) { if (!get_oid_hex(buf.buf, &oid)) {
object = parse_object_or_die(&oid, buf.buf); object = parse_object_or_die(the_repository, &oid, buf.buf);
add_pending_object(revs, object, ""); add_pending_object(revs, object, "");
} }
strbuf_release(&buf); strbuf_release(&buf);
@@ -94,7 +94,7 @@ static int add_one_ref(const char *path, const char *referent UNUSED, const stru
return 0; return 0;
} }
object = parse_object_or_die(oid, path); object = parse_object_or_die(the_repository, oid, path);
add_pending_object(revs, object, ""); add_pending_object(revs, object, "");
return 0; return 0;
@@ -218,7 +218,7 @@ static void add_recent_object(const struct object_id *oid,
switch (type) { switch (type) {
case OBJ_TAG: case OBJ_TAG:
case OBJ_COMMIT: case OBJ_COMMIT:
obj = parse_object_or_die(oid, NULL); obj = parse_object_or_die(the_repository, oid, NULL);
break; break;
case OBJ_TREE: case OBJ_TREE:
obj = (struct object *)lookup_tree(the_repository, oid); obj = (struct object *)lookup_tree(the_repository, oid);

View File

@@ -3612,7 +3612,8 @@ static void set_children(struct rev_info *revs)
void reset_revision_walk(void) void reset_revision_walk(void)
{ {
clear_object_flags(SEEN | ADDED | SHOWN | TOPO_WALK_EXPLORED | TOPO_WALK_INDEGREE); clear_object_flags(the_repository,
SEEN | ADDED | SHOWN | TOPO_WALK_EXPLORED | TOPO_WALK_INDEGREE);
} }
static int mark_uninteresting(const struct object_id *oid, static int mark_uninteresting(const struct object_id *oid,

View File

@@ -226,7 +226,7 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,
* SHALLOW (excluded) and NOT_SHALLOW (included) should not be * SHALLOW (excluded) and NOT_SHALLOW (included) should not be
* set at this point. But better be safe than sorry. * set at this point. But better be safe than sorry.
*/ */
clear_object_flags(both_flags); clear_object_flags(the_repository, both_flags);
is_repository_shallow(the_repository); /* make sure shallows are read */ is_repository_shallow(the_repository); /* make sure shallows are read */
@@ -613,9 +613,9 @@ static void paint_down(struct paint_info *info, const struct object_id *oid,
} }
} }
nr = get_max_object_index(); nr = get_max_object_index(the_repository);
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
struct object *o = get_indexed_object(i); struct object *o = get_indexed_object(the_repository, i);
if (o && o->type == OBJ_COMMIT) if (o && o->type == OBJ_COMMIT)
o->flags &= ~SEEN; o->flags &= ~SEEN;
} }
@@ -675,9 +675,9 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
* Prepare the commit graph to track what refs can reach what * Prepare the commit graph to track what refs can reach what
* (new) shallow commits. * (new) shallow commits.
*/ */
nr = get_max_object_index(); nr = get_max_object_index(the_repository);
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
struct object *o = get_indexed_object(i); struct object *o = get_indexed_object(the_repository, i);
if (!o || o->type != OBJ_COMMIT) if (!o || o->type != OBJ_COMMIT)
continue; continue;

View File

@@ -665,8 +665,8 @@ static int do_reachable_revlist(struct child_process *cmd,
cmd_in = xfdopen(cmd->in, "w"); cmd_in = xfdopen(cmd->in, "w");
for (i = get_max_object_index(); 0 < i; ) { for (i = get_max_object_index(the_repository); 0 < i; ) {
o = get_indexed_object(--i); o = get_indexed_object(the_repository, --i);
if (!o) if (!o)
continue; continue;
if (reachable && o->type == OBJ_COMMIT) if (reachable && o->type == OBJ_COMMIT)
@@ -734,8 +734,8 @@ static int get_reachable_list(struct upload_pack_data *data,
o->flags &= ~TMP_MARK; o->flags &= ~TMP_MARK;
} }
} }
for (i = get_max_object_index(); 0 < i; i--) { for (i = get_max_object_index(the_repository); 0 < i; i--) {
o = get_indexed_object(i - 1); o = get_indexed_object(the_repository, i - 1);
if (o && o->type == OBJ_COMMIT && if (o && o->type == OBJ_COMMIT &&
(o->flags & TMP_MARK)) { (o->flags & TMP_MARK)) {
add_object_array(o, NULL, reachable); add_object_array(o, NULL, reachable);
@@ -1557,7 +1557,7 @@ static int parse_want_ref(struct packet_writer *writer, const char *line,
} }
if (!o) if (!o)
o = parse_object_or_die(&oid, refname_nons); o = parse_object_or_die(the_repository, &oid, refname_nons);
if (!(o->flags & WANTED)) { if (!(o->flags & WANTED)) {
o->flags |= WANTED; o->flags |= WANTED;
@@ -1793,7 +1793,7 @@ int upload_pack_v2(struct repository *r, struct packet_reader *request)
enum fetch_state state = FETCH_PROCESS_ARGS; enum fetch_state state = FETCH_PROCESS_ARGS;
struct upload_pack_data data; struct upload_pack_data data;
clear_object_flags(ALL_FLAGS); clear_object_flags(the_repository, ALL_FLAGS);
upload_pack_data_init(&data); upload_pack_data_init(&data);
data.use_sideband = LARGE_PACKET_MAX; data.use_sideband = LARGE_PACKET_MAX;