Skip to content

Commit f59aa5e

Browse files
pks-tgitster
authored andcommitted
builtin: stop using the_index
Convert builtins to use `the_repository->index` instead of `the_index`. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 319ba14 commit f59aa5e

28 files changed

+356
-371
lines changed

builtin/add.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (C) 2006 Linus Torvalds
55
*/
6-
#define USE_THE_INDEX_VARIABLE
6+
77
#include "builtin.h"
88
#include "advice.h"
99
#include "config.h"
@@ -40,20 +40,20 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
4040
{
4141
int i, ret = 0;
4242

43-
for (i = 0; i < the_index.cache_nr; i++) {
44-
struct cache_entry *ce = the_index.cache[i];
43+
for (i = 0; i < the_repository->index->cache_nr; i++) {
44+
struct cache_entry *ce = the_repository->index->cache[i];
4545
int err;
4646

4747
if (!include_sparse &&
4848
(ce_skip_worktree(ce) ||
49-
!path_in_sparse_checkout(ce->name, &the_index)))
49+
!path_in_sparse_checkout(ce->name, the_repository->index)))
5050
continue;
5151

52-
if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
52+
if (pathspec && !ce_path_match(the_repository->index, ce, pathspec, NULL))
5353
continue;
5454

5555
if (!show_only)
56-
err = chmod_index_entry(&the_index, ce, flip);
56+
err = chmod_index_entry(the_repository->index, ce, flip);
5757
else
5858
err = S_ISREG(ce->ce_mode) ? 0 : -1;
5959

@@ -68,20 +68,20 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
6868
{
6969
int i, retval = 0;
7070

71-
for (i = 0; i < the_index.cache_nr; i++) {
72-
struct cache_entry *ce = the_index.cache[i];
71+
for (i = 0; i < the_repository->index->cache_nr; i++) {
72+
struct cache_entry *ce = the_repository->index->cache[i];
7373

7474
if (!include_sparse &&
7575
(ce_skip_worktree(ce) ||
76-
!path_in_sparse_checkout(ce->name, &the_index)))
76+
!path_in_sparse_checkout(ce->name, the_repository->index)))
7777
continue;
7878
if (ce_stage(ce))
7979
continue; /* do not touch unmerged paths */
8080
if (!S_ISREG(ce->ce_mode) && !S_ISLNK(ce->ce_mode))
8181
continue; /* do not touch non blobs */
82-
if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
82+
if (pathspec && !ce_path_match(the_repository->index, ce, pathspec, NULL))
8383
continue;
84-
retval |= add_file_to_index(&the_index, ce->name,
84+
retval |= add_file_to_index(the_repository->index, ce->name,
8585
flags | ADD_CACHE_RENORMALIZE);
8686
}
8787

@@ -100,11 +100,11 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
100100
i = dir->nr;
101101
while (--i >= 0) {
102102
struct dir_entry *entry = *src++;
103-
if (dir_path_match(&the_index, entry, pathspec, prefix, seen))
103+
if (dir_path_match(the_repository->index, entry, pathspec, prefix, seen))
104104
*dst++ = entry;
105105
}
106106
dir->nr = dst - dir->entries;
107-
add_pathspec_matches_against_index(pathspec, &the_index, seen,
107+
add_pathspec_matches_against_index(pathspec, the_repository->index, seen,
108108
PS_IGNORE_SKIP_WORKTREE);
109109
return seen;
110110
}
@@ -119,14 +119,14 @@ static int refresh(int verbose, const struct pathspec *pathspec)
119119
(verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET);
120120

121121
seen = xcalloc(pathspec->nr, 1);
122-
refresh_index(&the_index, flags, pathspec, seen,
122+
refresh_index(the_repository->index, flags, pathspec, seen,
123123
_("Unstaged changes after refreshing the index:"));
124124
for (i = 0; i < pathspec->nr; i++) {
125125
if (!seen[i]) {
126126
const char *path = pathspec->items[i].original;
127127

128128
if (matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
129-
!path_in_sparse_checkout(path, &the_index)) {
129+
!path_in_sparse_checkout(path, the_repository->index)) {
130130
string_list_append(&only_match_skip_worktree,
131131
pathspec->items[i].original);
132132
} else {
@@ -335,12 +335,12 @@ static int add_files(struct dir_struct *dir, int flags)
335335

336336
for (i = 0; i < dir->nr; i++) {
337337
if (!include_sparse &&
338-
!path_in_sparse_checkout(dir->entries[i]->name, &the_index)) {
338+
!path_in_sparse_checkout(dir->entries[i]->name, the_repository->index)) {
339339
string_list_append(&matched_sparse_paths,
340340
dir->entries[i]->name);
341341
continue;
342342
}
343-
if (add_file_to_index(&the_index, dir->entries[i]->name, flags)) {
343+
if (add_file_to_index(the_repository->index, dir->entries[i]->name, flags)) {
344344
if (!ignore_add_errors)
345345
die(_("adding files failed"));
346346
exit_status = 1;
@@ -458,8 +458,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
458458
if (repo_read_index_preload(the_repository, &pathspec, 0) < 0)
459459
die(_("index file corrupt"));
460460

461-
die_in_unpopulated_submodule(&the_index, prefix);
462-
die_path_inside_submodule(&the_index, &pathspec);
461+
die_in_unpopulated_submodule(the_repository->index, prefix);
462+
die_path_inside_submodule(the_repository->index, &pathspec);
463463

464464
if (add_new_files) {
465465
int baselen;
@@ -471,7 +471,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
471471
}
472472

473473
/* This picks up the paths that are not tracked */
474-
baselen = fill_directory(&dir, &the_index, &pathspec);
474+
baselen = fill_directory(&dir, the_repository->index, &pathspec);
475475
if (pathspec.nr)
476476
seen = prune_directory(&dir, &pathspec, baselen);
477477
}
@@ -488,7 +488,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
488488

489489
if (!seen)
490490
seen = find_pathspecs_matching_against_index(&pathspec,
491-
&the_index, PS_IGNORE_SKIP_WORKTREE);
491+
the_repository->index, PS_IGNORE_SKIP_WORKTREE);
492492

493493
/*
494494
* file_exists() assumes exact match
@@ -524,8 +524,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
524524
!file_exists(path)) {
525525
if (ignore_missing) {
526526
int dtype = DT_UNKNOWN;
527-
if (is_excluded(&dir, &the_index, path, &dtype))
528-
dir_add_ignored(&dir, &the_index,
527+
if (is_excluded(&dir, the_repository->index, path, &dtype))
528+
dir_add_ignored(&dir, the_repository->index,
529529
path, pathspec.items[i].len);
530530
} else
531531
die(_("pathspec '%s' did not match any files"),
@@ -566,7 +566,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
566566
end_odb_transaction();
567567

568568
finish:
569-
if (write_locked_index(&the_index, &lock_file,
569+
if (write_locked_index(the_repository->index, &lock_file,
570570
COMMIT_LOCK | SKIP_IF_UNCHANGED))
571571
die(_("unable to write new index file"));
572572

builtin/am.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Based on git-am.sh by Junio C Hamano.
55
*/
6-
#define USE_THE_INDEX_VARIABLE
6+
77
#include "builtin.h"
88
#include "abspath.h"
99
#include "advice.h"
@@ -1536,8 +1536,8 @@ static int run_apply(const struct am_state *state, const char *index_file)
15361536

15371537
if (index_file) {
15381538
/* Reload index as apply_all_patches() will have modified it. */
1539-
discard_index(&the_index);
1540-
read_index_from(&the_index, index_file, get_git_dir());
1539+
discard_index(the_repository->index);
1540+
read_index_from(the_repository->index, index_file, get_git_dir());
15411541
}
15421542

15431543
return 0;
@@ -1579,10 +1579,10 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
15791579
if (build_fake_ancestor(state, index_path))
15801580
return error("could not build fake ancestor");
15811581

1582-
discard_index(&the_index);
1583-
read_index_from(&the_index, index_path, get_git_dir());
1582+
discard_index(the_repository->index);
1583+
read_index_from(the_repository->index, index_path, get_git_dir());
15841584

1585-
if (write_index_as_tree(&orig_tree, &the_index, index_path, 0, NULL))
1585+
if (write_index_as_tree(&orig_tree, the_repository->index, index_path, 0, NULL))
15861586
return error(_("Repository lacks necessary blobs to fall back on 3-way merge."));
15871587

15881588
say(state, stdout, _("Using index info to reconstruct a base tree..."));
@@ -1608,12 +1608,12 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
16081608
return error(_("Did you hand edit your patch?\n"
16091609
"It does not apply to blobs recorded in its index."));
16101610

1611-
if (write_index_as_tree(&their_tree, &the_index, index_path, 0, NULL))
1611+
if (write_index_as_tree(&their_tree, the_repository->index, index_path, 0, NULL))
16121612
return error("could not write tree");
16131613

16141614
say(state, stdout, _("Falling back to patching base and 3-way merge..."));
16151615

1616-
discard_index(&the_index);
1616+
discard_index(the_repository->index);
16171617
repo_read_index(the_repository);
16181618

16191619
/*
@@ -1660,7 +1660,7 @@ static void do_commit(const struct am_state *state)
16601660
if (!state->no_verify && run_hooks("pre-applypatch"))
16611661
exit(1);
16621662

1663-
if (write_index_as_tree(&tree, &the_index, get_index_file(), 0, NULL))
1663+
if (write_index_as_tree(&tree, the_repository->index, get_index_file(), 0, NULL))
16641664
die(_("git write-tree failed to write a tree"));
16651665

16661666
if (!repo_get_oid_commit(the_repository, "HEAD", &parent)) {
@@ -1948,7 +1948,7 @@ static void am_resolve(struct am_state *state, int allow_empty)
19481948
}
19491949
}
19501950

1951-
if (unmerged_index(&the_index)) {
1951+
if (unmerged_index(the_repository->index)) {
19521952
printf_ln(_("You still have unmerged paths in your index.\n"
19531953
"You should 'git add' each file with resolved conflicts to mark them as such.\n"
19541954
"You might run `git rm` on a file to accept \"deleted by them\" for it."));
@@ -1987,12 +1987,12 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)
19871987

19881988
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
19891989

1990-
refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
1990+
refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL);
19911991

19921992
memset(&opts, 0, sizeof(opts));
19931993
opts.head_idx = 1;
1994-
opts.src_index = &the_index;
1995-
opts.dst_index = &the_index;
1994+
opts.src_index = the_repository->index;
1995+
opts.dst_index = the_repository->index;
19961996
opts.update = 1;
19971997
opts.merge = 1;
19981998
opts.reset = reset ? UNPACK_RESET_PROTECT_UNTRACKED : 0;
@@ -2006,7 +2006,7 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)
20062006
return -1;
20072007
}
20082008

2009-
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
2009+
if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
20102010
die(_("unable to write new index file"));
20112011

20122012
return 0;
@@ -2029,8 +2029,8 @@ static int merge_tree(struct tree *tree)
20292029

20302030
memset(&opts, 0, sizeof(opts));
20312031
opts.head_idx = 1;
2032-
opts.src_index = &the_index;
2033-
opts.dst_index = &the_index;
2032+
opts.src_index = the_repository->index;
2033+
opts.dst_index = the_repository->index;
20342034
opts.merge = 1;
20352035
opts.fn = oneway_merge;
20362036
init_tree_desc(&t[0], &tree->object.oid, tree->buffer, tree->size);
@@ -2040,7 +2040,7 @@ static int merge_tree(struct tree *tree)
20402040
return -1;
20412041
}
20422042

2043-
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
2043+
if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
20442044
die(_("unable to write new index file"));
20452045

20462046
return 0;
@@ -2068,7 +2068,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
20682068
if (fast_forward_to(head_tree, head_tree, 1))
20692069
return -1;
20702070

2071-
if (write_index_as_tree(&index, &the_index, get_index_file(), 0, NULL))
2071+
if (write_index_as_tree(&index, the_repository->index, get_index_file(), 0, NULL))
20722072
return -1;
20732073

20742074
index_tree = parse_tree_indirect(&index);

builtin/cat-file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (C) Linus Torvalds, 2005
55
*/
6-
#define USE_THE_INDEX_VARIABLE
6+
77
#include "builtin.h"
88
#include "config.h"
99
#include "convert.h"
@@ -77,7 +77,7 @@ static int filter_object(const char *path, unsigned mode,
7777
struct checkout_metadata meta;
7878

7979
init_checkout_metadata(&meta, NULL, NULL, oid);
80-
if (convert_to_working_tree(&the_index, path, *buf, *size, &strbuf, &meta)) {
80+
if (convert_to_working_tree(the_repository->index, path, *buf, *size, &strbuf, &meta)) {
8181
free(*buf);
8282
*size = strbuf.len;
8383
*buf = strbuf_detach(&strbuf, NULL);

builtin/check-attr.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_INDEX_VARIABLE
21
#include "builtin.h"
32
#include "config.h"
43
#include "attr.h"
@@ -71,9 +70,9 @@ static void check_attr(const char *prefix, struct attr_check *check,
7170
prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
7271

7372
if (collect_all) {
74-
git_all_attrs(&the_index, full_path, check);
73+
git_all_attrs(the_repository->index, full_path, check);
7574
} else {
76-
git_check_attr(&the_index, full_path, check);
75+
git_check_attr(the_repository->index, full_path, check);
7776
}
7877
output_attr(check, file);
7978

builtin/check-ignore.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_INDEX_VARIABLE
21
#include "builtin.h"
32
#include "config.h"
43
#include "dir.h"
@@ -95,21 +94,21 @@ static int check_ignore(struct dir_struct *dir,
9594
PATHSPEC_KEEP_ORDER,
9695
prefix, argv);
9796

98-
die_path_inside_submodule(&the_index, &pathspec);
97+
die_path_inside_submodule(the_repository->index, &pathspec);
9998

10099
/*
101100
* look for pathspecs matching entries in the index, since these
102101
* should not be ignored, in order to be consistent with
103102
* 'git status', 'git add' etc.
104103
*/
105-
seen = find_pathspecs_matching_against_index(&pathspec, &the_index,
104+
seen = find_pathspecs_matching_against_index(&pathspec, the_repository->index,
106105
PS_HEED_SKIP_WORKTREE);
107106
for (i = 0; i < pathspec.nr; i++) {
108107
full_path = pathspec.items[i].match;
109108
pattern = NULL;
110109
if (!seen[i]) {
111110
int dtype = DT_UNKNOWN;
112-
pattern = last_matching_pattern(dir, &the_index,
111+
pattern = last_matching_pattern(dir, the_repository->index,
113112
full_path, &dtype);
114113
if (!verbose && pattern &&
115114
pattern->flags & PATTERN_FLAG_NEGATIVE)

0 commit comments

Comments
 (0)