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>maint
parent
228457c9d9
commit
74d414c9f1
|
@ -399,12 +399,12 @@ static void check_connectivity(void)
|
|||
}
|
||||
|
||||
/* Look up all the requirements, warn about missing objects.. */
|
||||
max = get_max_object_index();
|
||||
max = get_max_object_index(the_repository);
|
||||
if (verbose)
|
||||
fprintf_ln(stderr, _("Checking connectivity (%d objects)"), max);
|
||||
|
||||
for (i = 0; i < max; i++) {
|
||||
struct object *obj = get_indexed_object(i);
|
||||
struct object *obj = get_indexed_object(the_repository, i);
|
||||
|
||||
if (obj)
|
||||
check_object(obj);
|
||||
|
|
|
@ -1144,7 +1144,7 @@ int cmd_grep(int argc,
|
|||
break;
|
||||
}
|
||||
|
||||
object = parse_object_or_die(&oid, arg);
|
||||
object = parse_object_or_die(the_repository, &oid, arg);
|
||||
if (!seen_dashdash)
|
||||
verify_non_filename(prefix, arg);
|
||||
add_object_array_with_path(object, arg, &list, oc.mode, oc.path);
|
||||
|
|
|
@ -279,14 +279,14 @@ static unsigned check_objects(void)
|
|||
{
|
||||
unsigned i, max, foreign_nr = 0;
|
||||
|
||||
max = get_max_object_index();
|
||||
max = get_max_object_index(the_repository);
|
||||
|
||||
if (verbose)
|
||||
progress = start_delayed_progress(the_repository,
|
||||
_("Checking objects"), max);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -2468,7 +2468,7 @@ int cmd_format_patch(int argc,
|
|||
base = get_base_commit(&cfg, list, nr);
|
||||
if (base) {
|
||||
reset_revision_walk();
|
||||
clear_object_flags(UNINTERESTING);
|
||||
clear_object_flags(the_repository, UNINTERESTING);
|
||||
prepare_bases(&bases, base, list, nr);
|
||||
}
|
||||
|
||||
|
|
|
@ -667,9 +667,9 @@ int cmd_name_rev(int argc,
|
|||
} else if (all) {
|
||||
int i, max;
|
||||
|
||||
max = get_max_object_index();
|
||||
max = get_max_object_index(the_repository);
|
||||
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)
|
||||
continue;
|
||||
show_name(obj, NULL,
|
||||
|
|
|
@ -4161,7 +4161,7 @@ static int mark_bitmap_preferred_tip(const char *refname,
|
|||
if (!peel_iterated_oid(the_repository, 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)
|
||||
object->flags |= NEEDS_BITMAP;
|
||||
|
||||
|
|
|
@ -185,7 +185,7 @@ int cmd_prune(int argc,
|
|||
const char *name = *argv++;
|
||||
|
||||
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);
|
||||
add_pending_object(&revs, object, "");
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
oid = &peeled;
|
||||
|
||||
object = parse_object_or_die(oid, refname);
|
||||
object = parse_object_or_die(revs->repo, oid, refname);
|
||||
if (object->type != OBJ_COMMIT)
|
||||
return 0;
|
||||
|
||||
|
@ -768,7 +768,7 @@ static int read_refs_snapshot(const char *refs_snapshot,
|
|||
if (*end)
|
||||
die(_("malformed line: %s"), buf.buf);
|
||||
|
||||
object = parse_object_or_die(&oid, NULL);
|
||||
object = parse_object_or_die(revs->repo, &oid, NULL);
|
||||
if (preferred)
|
||||
object->flags |= NEEDS_BITMAP;
|
||||
|
||||
|
|
21
object.c
21
object.c
|
@ -1,4 +1,3 @@
|
|||
#define USE_THE_REPOSITORY_VARIABLE
|
||||
#define DISABLE_SIGN_COMPARE_WARNINGS
|
||||
|
||||
#include "git-compat-util.h"
|
||||
|
@ -18,14 +17,15 @@
|
|||
#include "commit-graph.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[] = {
|
||||
|
@ -283,10 +283,11 @@ struct object *parse_object_buffer(struct repository *r, const struct object_id
|
|||
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)
|
||||
{
|
||||
struct object *o = parse_object(the_repository, oid);
|
||||
struct object *o = parse_object(repo, oid);
|
||||
if (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;
|
||||
|
||||
for (i=0; i < the_repository->parsed_objects->obj_hash_size; i++) {
|
||||
struct object *obj = the_repository->parsed_objects->obj_hash[i];
|
||||
for (i=0; i < repo->parsed_objects->obj_hash_size; i++) {
|
||||
struct object *obj = repo->parsed_objects->obj_hash[i];
|
||||
if (obj)
|
||||
obj->flags &= ~flags;
|
||||
}
|
||||
|
|
10
object.h
10
object.h
|
@ -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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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
|
||||
|
@ -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
|
||||
* (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
|
||||
* 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 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
|
||||
|
|
|
@ -1301,7 +1301,7 @@ static struct bitmap *find_boundary_objects(struct bitmap_index *bitmap_git,
|
|||
revs->tag_objects = tmp_tags;
|
||||
|
||||
reset_revision_walk();
|
||||
clear_object_flags(UNINTERESTING);
|
||||
clear_object_flags(repo, UNINTERESTING);
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
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) {
|
||||
struct tag *tag = (struct tag *) object;
|
||||
|
@ -1945,7 +1945,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
|
|||
else
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ static void add_one_file(const char *path, struct rev_info *revs)
|
|||
}
|
||||
strbuf_trim(&buf);
|
||||
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, "");
|
||||
}
|
||||
strbuf_release(&buf);
|
||||
|
@ -94,7 +94,7 @@ static int add_one_ref(const char *path, const char *referent UNUSED, const stru
|
|||
return 0;
|
||||
}
|
||||
|
||||
object = parse_object_or_die(oid, path);
|
||||
object = parse_object_or_die(the_repository, oid, path);
|
||||
add_pending_object(revs, object, "");
|
||||
|
||||
return 0;
|
||||
|
@ -218,7 +218,7 @@ static void add_recent_object(const struct object_id *oid,
|
|||
switch (type) {
|
||||
case OBJ_TAG:
|
||||
case OBJ_COMMIT:
|
||||
obj = parse_object_or_die(oid, NULL);
|
||||
obj = parse_object_or_die(the_repository, oid, NULL);
|
||||
break;
|
||||
case OBJ_TREE:
|
||||
obj = (struct object *)lookup_tree(the_repository, oid);
|
||||
|
|
|
@ -3612,7 +3612,8 @@ static void set_children(struct rev_info *revs)
|
|||
|
||||
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,
|
||||
|
|
10
shallow.c
10
shallow.c
|
@ -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
|
||||
* 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 */
|
||||
|
||||
|
@ -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++) {
|
||||
struct object *o = get_indexed_object(i);
|
||||
struct object *o = get_indexed_object(the_repository, i);
|
||||
if (o && o->type == OBJ_COMMIT)
|
||||
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
|
||||
* (new) shallow commits.
|
||||
*/
|
||||
nr = get_max_object_index();
|
||||
nr = get_max_object_index(the_repository);
|
||||
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)
|
||||
continue;
|
||||
|
||||
|
|
|
@ -665,8 +665,8 @@ static int do_reachable_revlist(struct child_process *cmd,
|
|||
|
||||
cmd_in = xfdopen(cmd->in, "w");
|
||||
|
||||
for (i = get_max_object_index(); 0 < i; ) {
|
||||
o = get_indexed_object(--i);
|
||||
for (i = get_max_object_index(the_repository); 0 < i; ) {
|
||||
o = get_indexed_object(the_repository, --i);
|
||||
if (!o)
|
||||
continue;
|
||||
if (reachable && o->type == OBJ_COMMIT)
|
||||
|
@ -734,8 +734,8 @@ static int get_reachable_list(struct upload_pack_data *data,
|
|||
o->flags &= ~TMP_MARK;
|
||||
}
|
||||
}
|
||||
for (i = get_max_object_index(); 0 < i; i--) {
|
||||
o = get_indexed_object(i - 1);
|
||||
for (i = get_max_object_index(the_repository); 0 < i; i--) {
|
||||
o = get_indexed_object(the_repository, i - 1);
|
||||
if (o && o->type == OBJ_COMMIT &&
|
||||
(o->flags & TMP_MARK)) {
|
||||
add_object_array(o, NULL, reachable);
|
||||
|
@ -1557,7 +1557,7 @@ static int parse_want_ref(struct packet_writer *writer, const char *line,
|
|||
}
|
||||
|
||||
if (!o)
|
||||
o = parse_object_or_die(&oid, refname_nons);
|
||||
o = parse_object_or_die(the_repository, &oid, refname_nons);
|
||||
|
||||
if (!(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;
|
||||
struct upload_pack_data data;
|
||||
|
||||
clear_object_flags(ALL_FLAGS);
|
||||
clear_object_flags(the_repository, ALL_FLAGS);
|
||||
|
||||
upload_pack_data_init(&data);
|
||||
data.use_sideband = LARGE_PACKET_MAX;
|
||||
|
|
Loading…
Reference in New Issue