Skip to content

Commit 764b1a2

Browse files
committed
Change the_repository to r
There are multiple files that try to reference `the repository` and `the_index` directly. To follow a more object-oriented convention these references should be replaced with `r` and `index` and passed through functions. Signed-off-by: Chinmoy Chakraborty <[email protected]>
1 parent 1424303 commit 764b1a2

File tree

6 files changed

+18
-13
lines changed

6 files changed

+18
-13
lines changed

builtin/checkout.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
684684
int ret;
685685
struct lock_file lock_file = LOCK_INIT;
686686
struct tree *new_tree;
687+
struct repository *r = the_repository;
687688

688689
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
689690
if (read_cache_preload(NULL) < 0)
@@ -822,7 +823,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
822823
}
823824

824825
if (!cache_tree_fully_valid(active_cache_tree))
825-
cache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
826+
cache_tree_update(r, &the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
826827

827828
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
828829
die(_("unable to write new index file"));

cache-tree.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ static int update_one(struct cache_tree *it,
433433
return i;
434434
}
435435

436-
int cache_tree_update(struct index_state *istate, int flags)
436+
int cache_tree_update(struct repository *r, struct index_state *istate, int flags)
437437
{
438438
int skip, i;
439439

@@ -446,10 +446,10 @@ int cache_tree_update(struct index_state *istate, int flags)
446446
istate->cache_tree = cache_tree();
447447

448448
trace_performance_enter();
449-
trace2_region_enter("cache_tree", "update", the_repository);
449+
trace2_region_enter("cache_tree", "update", r);
450450
i = update_one(istate->cache_tree, istate->cache, istate->cache_nr,
451451
"", 0, &skip, flags);
452-
trace2_region_leave("cache_tree", "update", the_repository);
452+
trace2_region_leave("cache_tree", "update", r);
453453
trace_performance_leave("cache_tree_update");
454454
if (i < 0)
455455
return i;
@@ -638,7 +638,7 @@ static int write_index_as_tree_internal(struct object_id *oid,
638638
cache_tree_valid = 0;
639639
}
640640

641-
if (!cache_tree_valid && cache_tree_update(index_state, flags) < 0)
641+
if (!cache_tree_valid && cache_tree_update(the_repository, index_state, flags) < 0)
642642
return WRITE_TREE_UNMERGED_INDEX;
643643

644644
if (prefix) {

cache-tree.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void cache_tree_write(struct strbuf *, struct cache_tree *root);
3333
struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
3434

3535
int cache_tree_fully_valid(struct cache_tree *);
36-
int cache_tree_update(struct index_state *, int);
36+
int cache_tree_update(struct repository *, struct index_state *, int);
3737
void cache_tree_verify(struct repository *, struct index_state *);
3838

3939
/* bitmasks to write_index_as_tree flags */
@@ -62,9 +62,11 @@ static inline int write_cache_as_tree(struct object_id *oid, int flags, const ch
6262

6363
static inline int update_main_cache_tree(int flags)
6464
{
65+
struct repository *r = the_repository;
66+
6567
if (!the_index.cache_tree)
6668
the_index.cache_tree = cache_tree();
67-
return cache_tree_update(&the_index, flags);
69+
return cache_tree_update(r, r->index, flags);
6870
}
6971
#endif
7072

sequencer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,10 @@ static int do_recursive_merge(struct repository *r,
677677
return !clean;
678678
}
679679

680-
static struct object_id *get_cache_tree_oid(struct index_state *istate)
680+
static struct object_id *get_cache_tree_oid(struct repository *r, struct index_state *istate)
681681
{
682682
if (!cache_tree_fully_valid(istate->cache_tree))
683-
if (cache_tree_update(istate, 0)) {
683+
if (cache_tree_update(r, istate, 0)) {
684684
error(_("unable to update cache tree"));
685685
return NULL;
686686
}
@@ -710,7 +710,7 @@ static int is_index_unchanged(struct repository *r)
710710
if (parse_commit(head_commit))
711711
return -1;
712712

713-
if (!(cache_tree_oid = get_cache_tree_oid(istate)))
713+
if (!(cache_tree_oid = get_cache_tree_oid(r, istate)))
714714
return -1;
715715

716716
return oideq(cache_tree_oid, get_commit_tree_oid(head_commit));

t/helper/test-dump-cache-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ int cmd__dump_cache_tree(int ac, const char **av)
6464
die("unable to read index file");
6565
istate = the_index;
6666
istate.cache_tree = another;
67-
cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
67+
cache_tree_update(the_repository, &istate, WRITE_TREE_DRY_RUN);
6868
return dump_cache_tree(active_cache_tree, another, "");
6969
}

unpack-trees.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,12 +1574,13 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
15741574
static struct cache_entry *dfc;
15751575
struct pattern_list pl;
15761576
int free_pattern_list = 0;
1577+
struct repository *r = the_repository;
15771578

15781579
if (len > MAX_UNPACK_TREES)
15791580
die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
15801581

15811582
trace_performance_enter();
1582-
trace2_region_enter("unpack_trees", "unpack_trees", the_repository);
1583+
trace2_region_enter("unpack_trees", "unpack_trees", r);
15831584

15841585
if (!core_apply_sparse_checkout || !o->update)
15851586
o->skip_sparse_checkout = 1;
@@ -1726,7 +1727,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
17261727
if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0))
17271728
cache_tree_verify(the_repository, &o->result);
17281729
if (!cache_tree_fully_valid(o->result.cache_tree))
1729-
cache_tree_update(&o->result,
1730+
cache_tree_update(the_repository,
1731+
&o->result,
17301732
WRITE_TREE_SILENT |
17311733
WRITE_TREE_REPAIR);
17321734
}

0 commit comments

Comments
 (0)