Skip to content

Commit 74d414c

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 228457c commit 74d414c

File tree

15 files changed

+48
-44
lines changed

15 files changed

+48
-44
lines changed

builtin/fsck.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,12 @@ static void check_connectivity(void)
399399
}
400400

401401
/* Look up all the requirements, warn about missing objects.. */
402-
max = get_max_object_index();
402+
max = get_max_object_index(the_repository);
403403
if (verbose)
404404
fprintf_ln(stderr, _("Checking connectivity (%d objects)"), max);
405405

406406
for (i = 0; i < max; i++) {
407-
struct object *obj = get_indexed_object(i);
407+
struct object *obj = get_indexed_object(the_repository, i);
408408

409409
if (obj)
410410
check_object(obj);

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ int cmd_grep(int argc,
11441144
break;
11451145
}
11461146

1147-
object = parse_object_or_die(&oid, arg);
1147+
object = parse_object_or_die(the_repository, &oid, arg);
11481148
if (!seen_dashdash)
11491149
verify_non_filename(prefix, arg);
11501150
add_object_array_with_path(object, arg, &list, oc.mode, oc.path);

builtin/index-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,14 @@ static unsigned check_objects(void)
279279
{
280280
unsigned i, max, foreign_nr = 0;
281281

282-
max = get_max_object_index();
282+
max = get_max_object_index(the_repository);
283283

284284
if (verbose)
285285
progress = start_delayed_progress(the_repository,
286286
_("Checking objects"), max);
287287

288288
for (i = 0; i < max; i++) {
289-
foreign_nr += check_object(get_indexed_object(i));
289+
foreign_nr += check_object(get_indexed_object(the_repository, i));
290290
display_progress(progress, i + 1);
291291
}
292292

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2468,7 +2468,7 @@ int cmd_format_patch(int argc,
24682468
base = get_base_commit(&cfg, list, nr);
24692469
if (base) {
24702470
reset_revision_walk();
2471-
clear_object_flags(UNINTERESTING);
2471+
clear_object_flags(the_repository, UNINTERESTING);
24722472
prepare_bases(&bases, base, list, nr);
24732473
}
24742474

builtin/name-rev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,9 +667,9 @@ int cmd_name_rev(int argc,
667667
} else if (all) {
668668
int i, max;
669669

670-
max = get_max_object_index();
670+
max = get_max_object_index(the_repository);
671671
for (i = 0; i < max; i++) {
672-
struct object *obj = get_indexed_object(i);
672+
struct object *obj = get_indexed_object(the_repository, i);
673673
if (!obj || obj->type != OBJ_COMMIT)
674674
continue;
675675
show_name(obj, NULL,

builtin/pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4161,7 +4161,7 @@ static int mark_bitmap_preferred_tip(const char *refname,
41614161
if (!peel_iterated_oid(the_repository, oid, &peeled))
41624162
oid = &peeled;
41634163

4164-
object = parse_object_or_die(oid, refname);
4164+
object = parse_object_or_die(the_repository, oid, refname);
41654165
if (object->type == OBJ_COMMIT)
41664166
object->flags |= NEEDS_BITMAP;
41674167

builtin/prune.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ int cmd_prune(int argc,
185185
const char *name = *argv++;
186186

187187
if (!repo_get_oid(the_repository, name, &oid)) {
188-
struct object *object = parse_object_or_die(&oid,
188+
struct object *object = parse_object_or_die(the_repository, &oid,
189189
name);
190190
add_pending_object(&revs, object, "");
191191
}

midx-write.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ static int add_ref_to_pending(const char *refname, const char *referent UNUSED,
708708
if (!peel_iterated_oid(revs->repo, oid, &peeled))
709709
oid = &peeled;
710710

711-
object = parse_object_or_die(oid, refname);
711+
object = parse_object_or_die(revs->repo, oid, refname);
712712
if (object->type != OBJ_COMMIT)
713713
return 0;
714714

@@ -768,7 +768,7 @@ static int read_refs_snapshot(const char *refs_snapshot,
768768
if (*end)
769769
die(_("malformed line: %s"), buf.buf);
770770

771-
object = parse_object_or_die(&oid, NULL);
771+
object = parse_object_or_die(revs->repo, &oid, NULL);
772772
if (preferred)
773773
object->flags |= NEEDS_BITMAP;
774774

object.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
21
#define DISABLE_SIGN_COMPARE_WARNINGS
32

43
#include "git-compat-util.h"
@@ -18,14 +17,15 @@
1817
#include "commit-graph.h"
1918
#include "loose.h"
2019

21-
unsigned int get_max_object_index(void)
20+
unsigned int get_max_object_index(const struct repository *repo)
2221
{
23-
return the_repository->parsed_objects->obj_hash_size;
22+
return repo->parsed_objects->obj_hash_size;
2423
}
2524

26-
struct object *get_indexed_object(unsigned int idx)
25+
struct object *get_indexed_object(const struct repository *repo,
26+
unsigned int idx)
2727
{
28-
return the_repository->parsed_objects->obj_hash[idx];
28+
return repo->parsed_objects->obj_hash[idx];
2929
}
3030

3131
static const char *object_type_strings[] = {
@@ -283,10 +283,11 @@ struct object *parse_object_buffer(struct repository *r, const struct object_id
283283
return obj;
284284
}
285285

286-
struct object *parse_object_or_die(const struct object_id *oid,
286+
struct object *parse_object_or_die(struct repository *repo,
287+
const struct object_id *oid,
287288
const char *name)
288289
{
289-
struct object *o = parse_object(the_repository, oid);
290+
struct object *o = parse_object(repo, oid);
290291
if (o)
291292
return o;
292293

@@ -524,12 +525,12 @@ void object_array_remove_duplicates(struct object_array *array)
524525
}
525526
}
526527

527-
void clear_object_flags(unsigned flags)
528+
void clear_object_flags(struct repository *repo, unsigned flags)
528529
{
529530
int i;
530531

531-
for (i=0; i < the_repository->parsed_objects->obj_hash_size; i++) {
532-
struct object *obj = the_repository->parsed_objects->obj_hash[i];
532+
for (i=0; i < repo->parsed_objects->obj_hash_size; i++) {
533+
struct object *obj = repo->parsed_objects->obj_hash[i];
533534
if (obj)
534535
obj->flags &= ~flags;
535536
}

object.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,13 @@ int type_from_string_gently(const char *str, ssize_t, int gentle);
169169
/*
170170
* Return the current number of buckets in the object hashmap.
171171
*/
172-
unsigned int get_max_object_index(void);
172+
unsigned int get_max_object_index(const struct repository *repo);
173173

174174
/*
175175
* Return the object from the specified bucket in the object hashmap.
176176
*/
177-
struct object *get_indexed_object(unsigned int);
177+
struct object *get_indexed_object(const struct repository *repo,
178+
unsigned int);
178179

179180
/*
180181
* 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,
231232
* "name" parameter is not NULL, it is included in the error message
232233
* (otherwise, the hex object ID is given).
233234
*/
234-
struct object *parse_object_or_die(const struct object_id *oid, const char *name);
235+
struct object *parse_object_or_die(struct repository *repo, const struct object_id *oid,
236+
const char *name);
235237

236238
/* Given the result of read_sha1_file(), returns the object after
237239
* 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);
336338
*/
337339
void object_array_clear(struct object_array *array);
338340

339-
void clear_object_flags(unsigned flags);
341+
void clear_object_flags(struct repository *repo, unsigned flags);
340342

341343
/*
342344
* Clear the specified object flags from all in-core commit objects from

0 commit comments

Comments
 (0)