Skip to content

Commit 51ab74f

Browse files
committed
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 51ab74f

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

builtin/checkout.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ struct branch_info {
101101
char *checkout;
102102
};
103103

104+
struct repository *r;
105+
104106
static int post_checkout_hook(struct commit *old_commit, struct commit *new_commit,
105107
int changed)
106108
{
@@ -822,7 +824,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
822824
}
823825

824826
if (!cache_tree_fully_valid(active_cache_tree))
825-
cache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
827+
cache_tree_update(r, &the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
826828

827829
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
828830
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: 2 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 */
@@ -64,7 +64,7 @@ static inline int update_main_cache_tree(int flags)
6464
{
6565
if (!the_index.cache_tree)
6666
the_index.cache_tree = cache_tree();
67-
return cache_tree_update(&the_index, flags);
67+
return cache_tree_update(the_repository, &the_index, flags);
6868
}
6969
#endif
7070

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
17261726
if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0))
17271727
cache_tree_verify(the_repository, &o->result);
17281728
if (!cache_tree_fully_valid(o->result.cache_tree))
1729-
cache_tree_update(&o->result,
1729+
cache_tree_update(the_repository,
1730+
&o->result,
17301731
WRITE_TREE_SILENT |
17311732
WRITE_TREE_REPAIR);
17321733
}

0 commit comments

Comments
 (0)