Skip to content

Commit 60ffcbd

Browse files
committed
object.c: get_max_object_index and get_indexed_object accept r parameter
Currently the two functions use global variable `the_repository` to access the values stored in it. This makes `the_repository` to be existent even when not required. This commit replaces it with `r` which is passed as a parameter to those functions. This is in line with a general trend to reduce dependence on usage of global variables wherever possible. This task will be carried out gradually in stages, wherein the caller functions of these functions modified in object.c, might themselves also be using `the_repository` in form of a global variable, shall be passed the `r` variable in a future patch series, and so on for their callers. Signed-off-by: Parth Gala <[email protected]>
1 parent de49261 commit 60ffcbd

File tree

7 files changed

+27
-20
lines changed

7 files changed

+27
-20
lines changed

builtin/fsck.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ static void check_object(struct object *obj)
375375
static void check_connectivity(void)
376376
{
377377
int i, max;
378+
struct repository *r = the_repository;
378379

379380
/* Traverse the pending reachable objects */
380381
traverse_reachable();
@@ -400,12 +401,12 @@ static void check_connectivity(void)
400401
}
401402

402403
/* Look up all the requirements, warn about missing objects.. */
403-
max = get_max_object_index();
404+
max = get_max_object_index(r);
404405
if (verbose)
405406
fprintf_ln(stderr, _("Checking connectivity (%d objects)"), max);
406407

407408
for (i = 0; i < max; i++) {
408-
struct object *obj = get_indexed_object(i);
409+
struct object *obj = get_indexed_object(r, i);
409410

410411
if (obj)
411412
check_object(obj);

builtin/index-pack.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,15 @@ static unsigned check_object(struct object *obj)
218218
static unsigned check_objects(void)
219219
{
220220
unsigned i, max, foreign_nr = 0;
221+
struct repository *r = the_repository;
221222

222-
max = get_max_object_index();
223+
max = get_max_object_index(r);
223224

224225
if (verbose)
225226
progress = start_delayed_progress(_("Checking objects"), max);
226227

227228
for (i = 0; i < max; i++) {
228-
foreign_nr += check_object(get_indexed_object(i));
229+
foreign_nr += check_object(get_indexed_object(r, i));
229230
display_progress(progress, i + 1);
230231
}
231232

builtin/name-rev.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
518518
int cmd_name_rev(int argc, const char **argv, const char *prefix)
519519
{
520520
struct object_array revs = OBJECT_ARRAY_INIT;
521+
struct repository *r = the_repository;
521522
int all = 0, transform_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0;
522523
struct name_ref_data data = { 0, 0, STRING_LIST_INIT_NODUP, STRING_LIST_INIT_NODUP };
523524
struct option opts[] = {
@@ -616,9 +617,9 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
616617
} else if (all) {
617618
int i, max;
618619

619-
max = get_max_object_index();
620+
max = get_max_object_index(r);
620621
for (i = 0; i < max; i++) {
621-
struct object *obj = get_indexed_object(i);
622+
struct object *obj = get_indexed_object(r, i);
622623
if (!obj || obj->type != OBJ_COMMIT)
623624
continue;
624625
show_name(obj, NULL,

object.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
#include "packfile.h"
1111
#include "commit-graph.h"
1212

13-
unsigned int get_max_object_index(void)
13+
unsigned int get_max_object_index(struct repository *r)
1414
{
15-
return the_repository->parsed_objects->obj_hash_size;
15+
return r->parsed_objects->obj_hash_size;
1616
}
1717

18-
struct object *get_indexed_object(unsigned int idx)
18+
struct object *get_indexed_object(struct repository *r, unsigned int idx)
1919
{
20-
return the_repository->parsed_objects->obj_hash[idx];
20+
return r->parsed_objects->obj_hash[idx];
2121
}
2222

2323
static const char *object_type_strings[] = {

object.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ int type_from_string_gently(const char *str, ssize_t, int gentle);
9898
/*
9999
* Return the current number of buckets in the object hashmap.
100100
*/
101-
unsigned int get_max_object_index(void);
101+
unsigned int get_max_object_index(struct repository *);
102102

103103
/*
104104
* Return the object from the specified bucket in the object hashmap.
105105
*/
106-
struct object *get_indexed_object(unsigned int);
106+
struct object *get_indexed_object(struct repository *, unsigned int);
107107

108108
/*
109109
* This can be used to see if we have heard of the object before, but

shallow.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ static void paint_down(struct paint_info *info, const struct object_id *oid,
510510
unsigned int id)
511511
{
512512
unsigned int i, nr;
513+
struct repository *r = the_repository;
513514
struct commit_list *head = NULL;
514515
int bitmap_nr = DIV_ROUND_UP(info->nr_bits, 32);
515516
size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr);
@@ -563,9 +564,9 @@ static void paint_down(struct paint_info *info, const struct object_id *oid,
563564
}
564565
}
565566

566-
nr = get_max_object_index();
567+
nr = get_max_object_index(r);
567568
for (i = 0; i < nr; i++) {
568-
struct object *o = get_indexed_object(i);
569+
struct object *o = get_indexed_object(r, i);
569570
if (o && o->type == OBJ_COMMIT)
570571
o->flags &= ~SEEN;
571572
}
@@ -608,6 +609,7 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
608609
struct object_id *oid = info->shallow->oid;
609610
struct oid_array *ref = info->ref;
610611
unsigned int i, nr;
612+
struct repository *r = the_repository;
611613
int *shallow, nr_shallow = 0;
612614
struct paint_info pi;
613615

@@ -622,9 +624,9 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
622624
* Prepare the commit graph to track what refs can reach what
623625
* (new) shallow commits.
624626
*/
625-
nr = get_max_object_index();
627+
nr = get_max_object_index(r);
626628
for (i = 0; i < nr; i++) {
627-
struct object *o = get_indexed_object(i);
629+
struct object *o = get_indexed_object(r, i);
628630
if (!o || o->type != OBJ_COMMIT)
629631
continue;
630632

upload-pack.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ static int do_reachable_revlist(struct child_process *cmd,
450450
"rev-list", "--stdin", NULL,
451451
};
452452
struct object *o;
453+
struct repository *r = the_repository;
453454
char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
454455
int i;
455456
const unsigned hexsz = the_hash_algo->hexsz;
@@ -472,8 +473,8 @@ static int do_reachable_revlist(struct child_process *cmd,
472473

473474
namebuf[0] = '^';
474475
namebuf[hexsz + 1] = '\n';
475-
for (i = get_max_object_index(); 0 < i; ) {
476-
o = get_indexed_object(--i);
476+
for (i = get_max_object_index(r); 0 < i; ) {
477+
o = get_indexed_object(r, --i);
477478
if (!o)
478479
continue;
479480
if (reachable && o->type == OBJ_COMMIT)
@@ -520,6 +521,7 @@ static int get_reachable_list(struct object_array *src,
520521
struct child_process cmd = CHILD_PROCESS_INIT;
521522
int i;
522523
struct object *o;
524+
struct repository *r = the_repository;
523525
char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
524526
const unsigned hexsz = the_hash_algo->hexsz;
525527

@@ -538,8 +540,8 @@ static int get_reachable_list(struct object_array *src,
538540
o->flags &= ~TMP_MARK;
539541
}
540542
}
541-
for (i = get_max_object_index(); 0 < i; i--) {
542-
o = get_indexed_object(i - 1);
543+
for (i = get_max_object_index(r); 0 < i; i--) {
544+
o = get_indexed_object(r, i - 1);
543545
if (o && o->type == OBJ_COMMIT &&
544546
(o->flags & TMP_MARK)) {
545547
add_object_array(o, NULL, reachable);

0 commit comments

Comments
 (0)