builtin: stop using `the_index`
Convert builtins to use `the_repository->index` instead of `the_index`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Apr 18, 2024 at 14:14 UTC
f59aa5e0a93242f73bf21e241fabe0c261f4b62a
28 files changed
+356
-371
builtin/add.c
+24
-24
@@ -3,7 +3,7 @@
3
*
4
* Copyright (C) 2006 Linus Torvalds
5
*/
6
-#define USE_THE_INDEX_VARIABLE
6
+
7
#include "builtin.h"
8
#include "advice.h"
9
#include "config.h"
@@ -40,20 +40,20 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
40
{
41
int i, ret = 0;
42
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];
45
int err;
46
47
if (!include_sparse &&
48
(ce_skip_worktree(ce) ||
49
- !path_in_sparse_checkout(ce->name, &the_index)))
49
+ !path_in_sparse_checkout(ce->name, the_repository->index)))
50
continue;
51
52
- if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
52
+ if (pathspec && !ce_path_match(the_repository->index, ce, pathspec, NULL))
53
continue;
54
55
if (!show_only)
56
- err = chmod_index_entry(&the_index, ce, flip);
56
+ err = chmod_index_entry(the_repository->index, ce, flip);
57
else
58
err = S_ISREG(ce->ce_mode) ? 0 : -1;
59
@@ -68,20 +68,20 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
68
{
69
int i, retval = 0;
70
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];
73
74
if (!include_sparse &&
75
(ce_skip_worktree(ce) ||
76
- !path_in_sparse_checkout(ce->name, &the_index)))
76
+ !path_in_sparse_checkout(ce->name, the_repository->index)))
77
continue;
78
if (ce_stage(ce))
79
continue; /* do not touch unmerged paths */
80
if (!S_ISREG(ce->ce_mode) && !S_ISLNK(ce->ce_mode))
81
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))
83
continue;
84
- retval |= add_file_to_index(&the_index, ce->name,
84
+ retval |= add_file_to_index(the_repository->index, ce->name,
85
flags | ADD_CACHE_RENORMALIZE);
86
}
87
@@ -100,11 +100,11 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
100
i = dir->nr;
101
while (--i >= 0) {
102
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))
104
*dst++ = entry;
105
}
106
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,
108
PS_IGNORE_SKIP_WORKTREE);
109
return seen;
110
}
@@ -119,14 +119,14 @@ static int refresh(int verbose, const struct pathspec *pathspec)
119
(verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET);
120
121
seen = xcalloc(pathspec->nr, 1);
122
- refresh_index(&the_index, flags, pathspec, seen,
122
+ refresh_index(the_repository->index, flags, pathspec, seen,
123
_("Unstaged changes after refreshing the index:"));
124
for (i = 0; i < pathspec->nr; i++) {
125
if (!seen[i]) {
126
const char *path = pathspec->items[i].original;
127
128
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)) {
130
string_list_append(&only_match_skip_worktree,
131
pathspec->items[i].original);
132
} else {
@@ -335,12 +335,12 @@ static int add_files(struct dir_struct *dir, int flags)
335
336
for (i = 0; i < dir->nr; i++) {
337
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)) {
339
string_list_append(&matched_sparse_paths,
340
dir->entries[i]->name);
341
continue;
342
}
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)) {
344
if (!ignore_add_errors)
345
die(_("adding files failed"));
346
exit_status = 1;
@@ -458,8 +458,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
458
if (repo_read_index_preload(the_repository, &pathspec, 0) < 0)
459
die(_("index file corrupt"));
460
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);
463
464
if (add_new_files) {
465
int baselen;
@@ -471,7 +471,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
471
}
472
473
/* 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);
475
if (pathspec.nr)
476
seen = prune_directory(&dir, &pathspec, baselen);
477
}
@@ -488,7 +488,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
488
489
if (!seen)
490
seen = find_pathspecs_matching_against_index(&pathspec,
491
- &the_index, PS_IGNORE_SKIP_WORKTREE);
491
+ the_repository->index, PS_IGNORE_SKIP_WORKTREE);
492
493
/*
494
* file_exists() assumes exact match
@@ -524,8 +524,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
524
!file_exists(path)) {
525
if (ignore_missing) {
526
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,
529
path, pathspec.items[i].len);
530
} else
531
die(_("pathspec '%s' did not match any files"),
@@ -566,7 +566,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
566
end_odb_transaction();
567
568
finish:
569
- if (write_locked_index(&the_index, &lock_file,
569
+ if (write_locked_index(the_repository->index, &lock_file,
570
COMMIT_LOCK | SKIP_IF_UNCHANGED))
571
die(_("unable to write new index file"));
572
builtin/am.c
+18
-18
@@ -3,7 +3,7 @@
3
*
4
* Based on git-am.sh by Junio C Hamano.
5
*/
6
-#define USE_THE_INDEX_VARIABLE
6
+
7
#include "builtin.h"
8
#include "abspath.h"
9
#include "advice.h"
@@ -1536,8 +1536,8 @@ static int run_apply(const struct am_state *state, const char *index_file)
1536
1537
if (index_file) {
1538
/* 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());
1541
}
1542
1543
return 0;
@@ -1579,10 +1579,10 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
1579
if (build_fake_ancestor(state, index_path))
1580
return error("could not build fake ancestor");
1581
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());
1584
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))
1586
return error(_("Repository lacks necessary blobs to fall back on 3-way merge."));
1587
1588
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
1608
return error(_("Did you hand edit your patch?\n"
1609
"It does not apply to blobs recorded in its index."));
1610
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))
1612
return error("could not write tree");
1613
1614
say(state, stdout, _("Falling back to patching base and 3-way merge..."));
1615
1616
- discard_index(&the_index);
1616
+ discard_index(the_repository->index);
1617
repo_read_index(the_repository);
1618
1619
/*
@@ -1660,7 +1660,7 @@ static void do_commit(const struct am_state *state)
1660
if (!state->no_verify && run_hooks("pre-applypatch"))
1661
exit(1);
1662
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))
1664
die(_("git write-tree failed to write a tree"));
1665
1666
if (!repo_get_oid_commit(the_repository, "HEAD", &parent)) {
@@ -1948,7 +1948,7 @@ static void am_resolve(struct am_state *state, int allow_empty)
1948
}
1949
}
1950
1951
- if (unmerged_index(&the_index)) {
1951
+ if (unmerged_index(the_repository->index)) {
1952
printf_ln(_("You still have unmerged paths in your index.\n"
1953
"You should 'git add' each file with resolved conflicts to mark them as such.\n"
1954
"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)
1987
1988
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
1989
1990
- refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
1990
+ refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL);
1991
1992
memset(&opts, 0, sizeof(opts));
1993
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;
1996
opts.update = 1;
1997
opts.merge = 1;
1998
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)
2006
return -1;
2007
}
2008
2009
- if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
2009
+ if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
2010
die(_("unable to write new index file"));
2011
2012
return 0;
@@ -2029,8 +2029,8 @@ static int merge_tree(struct tree *tree)
2029
2030
memset(&opts, 0, sizeof(opts));
2031
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;
2034
opts.merge = 1;
2035
opts.fn = oneway_merge;
2036
init_tree_desc(&t[0], &tree->object.oid, tree->buffer, tree->size);
@@ -2040,7 +2040,7 @@ static int merge_tree(struct tree *tree)
2040
return -1;
2041
}
2042
2043
- if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
2043
+ if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
2044
die(_("unable to write new index file"));
2045
2046
return 0;
@@ -2068,7 +2068,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
2068
if (fast_forward_to(head_tree, head_tree, 1))
2069
return -1;
2070
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))
2072
return -1;
2073
2074
index_tree = parse_tree_indirect(&index);
builtin/cat-file.c
+2
-2
@@ -3,7 +3,7 @@
3
*
4
* Copyright (C) Linus Torvalds, 2005
5
*/
6
-#define USE_THE_INDEX_VARIABLE
6
+
7
#include "builtin.h"
8
#include "config.h"
9
#include "convert.h"
@@ -77,7 +77,7 @@ static int filter_object(const char *path, unsigned mode,
77
struct checkout_metadata meta;
78
79
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)) {
81
free(*buf);
82
*size = strbuf.len;
83
*buf = strbuf_detach(&strbuf, NULL);
builtin/check-attr.c
+2
-3
@@ -1,4 +1,3 @@
1
-#define USE_THE_INDEX_VARIABLE
1
#include "builtin.h"
2
#include "config.h"
3
#include "attr.h"
@@ -71,9 +70,9 @@ static void check_attr(const char *prefix, struct attr_check *check,
70
prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
71
72
if (collect_all) {
74
- git_all_attrs(&the_index, full_path, check);
73
+ git_all_attrs(the_repository->index, full_path, check);
74
} else {
76
- git_check_attr(&the_index, full_path, check);
75
+ git_check_attr(the_repository->index, full_path, check);
76
}
77
output_attr(check, file);
78
builtin/check-ignore.c
+3
-4
@@ -1,4 +1,3 @@
1
-#define USE_THE_INDEX_VARIABLE
1
#include "builtin.h"
2
#include "config.h"
3
#include "dir.h"
@@ -95,21 +94,21 @@ static int check_ignore(struct dir_struct *dir,
94
PATHSPEC_KEEP_ORDER,
95
prefix, argv);
96
98
- die_path_inside_submodule(&the_index, &pathspec);
97
+ die_path_inside_submodule(the_repository->index, &pathspec);
98
99
/*
100
* look for pathspecs matching entries in the index, since these
101
* should not be ignored, in order to be consistent with
102
* 'git status', 'git add' etc.
103
*/
105
- seen = find_pathspecs_matching_against_index(&pathspec, &the_index,
104
+ seen = find_pathspecs_matching_against_index(&pathspec, the_repository->index,
105
PS_HEED_SKIP_WORKTREE);
106
for (i = 0; i < pathspec.nr; i++) {
107
full_path = pathspec.items[i].match;
108
pattern = NULL;
109
if (!seen[i]) {
110
int dtype = DT_UNKNOWN;
112
- pattern = last_matching_pattern(dir, &the_index,
111
+ pattern = last_matching_pattern(dir, the_repository->index,
112
full_path, &dtype);
113
if (!verbose && pattern &&
114
pattern->flags & PATTERN_FLAG_NEGATIVE)
builtin/checkout-index.c
+11
-11
@@ -4,7 +4,7 @@
4
* Copyright (C) 2005 Linus Torvalds
5
*
6
*/
7
-#define USE_THE_INDEX_VARIABLE
7
+
8
#include "builtin.h"
9
#include "config.h"
10
#include "gettext.h"
@@ -69,7 +69,7 @@ static void write_tempfile_record(const char *name, const char *prefix)
69
static int checkout_file(const char *name, const char *prefix)
70
{
71
int namelen = strlen(name);
72
- int pos = index_name_pos(&the_index, name, namelen);
72
+ int pos = index_name_pos(the_repository->index, name, namelen);
73
int has_same_name = 0;
74
int is_file = 0;
75
int is_skipped = 1;
@@ -79,8 +79,8 @@ static int checkout_file(const char *name, const char *prefix)
79
if (pos < 0)
80
pos = -pos - 1;
81
82
- while (pos < the_index.cache_nr) {
83
- struct cache_entry *ce = the_index.cache[pos];
82
+ while (pos <the_repository->index->cache_nr) {
83
+ struct cache_entry *ce =the_repository->index->cache[pos];
84
if (ce_namelen(ce) != namelen ||
85
memcmp(ce->name, name, namelen))
86
break;
@@ -140,8 +140,8 @@ static int checkout_all(const char *prefix, int prefix_length)
140
int i, errs = 0;
141
struct cache_entry *last_ce = NULL;
142
143
- for (i = 0; i < the_index.cache_nr ; i++) {
144
- struct cache_entry *ce = the_index.cache[i];
143
+ for (i = 0; i < the_repository->index->cache_nr ; i++) {
144
+ struct cache_entry *ce = the_repository->index->cache[i];
145
146
if (S_ISSPARSEDIR(ce->ce_mode)) {
147
if (!ce_skip_worktree(ce))
@@ -154,8 +154,8 @@ static int checkout_all(const char *prefix, int prefix_length)
154
* first entry inside the expanded sparse directory).
155
*/
156
if (ignore_skip_worktree) {
157
- ensure_full_index(&the_index);
158
- ce = the_index.cache[i];
157
+ ensure_full_index(the_repository->index);
158
+ ce = the_repository->index->cache[i];
159
}
160
}
161
@@ -260,7 +260,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
260
261
argc = parse_options(argc, argv, prefix, builtin_checkout_index_options,
262
builtin_checkout_index_usage, 0);
263
- state.istate = &the_index;
263
+ state.istate = the_repository->index;
264
state.force = force;
265
state.quiet = quiet;
266
state.not_new = not_new;
@@ -280,7 +280,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
280
*/
281
if (index_opt && !state.base_dir_len && !to_tempfile) {
282
state.refresh_cache = 1;
283
- state.istate = &the_index;
283
+ state.istate = the_repository->index;
284
repo_hold_locked_index(the_repository, &lock_file,
285
LOCK_DIE_ON_ERROR);
286
}
@@ -339,7 +339,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
339
return 1;
340
341
if (is_lock_file_locked(&lock_file) &&
342
- write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
342
+ write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
343
die("Unable to write new index file");
344
return 0;
345
}
builtin/checkout.c
+43
-44
@@ -1,4 +1,3 @@
1
-#define USE_THE_INDEX_VARIABLE
1
#include "builtin.h"
2
#include "advice.h"
3
#include "branch.h"
@@ -146,7 +145,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
145
return READ_TREE_RECURSIVE;
146
147
len = base->len + strlen(pathname);
149
- ce = make_empty_cache_entry(&the_index, len);
148
+ ce = make_empty_cache_entry(the_repository->index, len);
149
oidcpy(&ce->oid, oid);
150
memcpy(ce->name, base->buf, base->len);
151
memcpy(ce->name + base->len, pathname, len - base->len);
@@ -159,9 +158,9 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
158
* entry in place. Whether it is UPTODATE or not, checkout_entry will
159
* do the right thing.
160
*/
162
- pos = index_name_pos(&the_index, ce->name, ce->ce_namelen);
161
+ pos = index_name_pos(the_repository->index, ce->name, ce->ce_namelen);
162
if (pos >= 0) {
164
- struct cache_entry *old = the_index.cache[pos];
163
+ struct cache_entry *old = the_repository->index->cache[pos];
164
if (ce->ce_mode == old->ce_mode &&
165
!ce_intent_to_add(old) &&
166
oideq(&ce->oid, &old->oid)) {
@@ -171,7 +170,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
170
}
171
}
172
174
- add_index_entry(&the_index, ce,
173
+ add_index_entry(the_repository->index, ce,
174
ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
175
return 0;
176
}
@@ -190,8 +189,8 @@ static int read_tree_some(struct tree *tree, const struct pathspec *pathspec)
189
190
static int skip_same_name(const struct cache_entry *ce, int pos)
191
{
193
- while (++pos < the_index.cache_nr &&
194
- !strcmp(the_index.cache[pos]->name, ce->name))
192
+ while (++pos < the_repository->index->cache_nr &&
193
+ !strcmp(the_repository->index->cache[pos]->name, ce->name))
194
; /* skip */
195
return pos;
196
}
@@ -199,9 +198,9 @@ static int skip_same_name(const struct cache_entry *ce, int pos)
198
static int check_stage(int stage, const struct cache_entry *ce, int pos,
199
int overlay_mode)
200
{
202
- while (pos < the_index.cache_nr &&
203
- !strcmp(the_index.cache[pos]->name, ce->name)) {
204
- if (ce_stage(the_index.cache[pos]) == stage)
201
+ while (pos < the_repository->index->cache_nr &&
202
+ !strcmp(the_repository->index->cache[pos]->name, ce->name)) {
203
+ if (ce_stage(the_repository->index->cache[pos]) == stage)
204
return 0;
205
pos++;
206
}
@@ -218,8 +217,8 @@ static int check_stages(unsigned stages, const struct cache_entry *ce, int pos)
217
unsigned seen = 0;
218
const char *name = ce->name;
219
221
- while (pos < the_index.cache_nr) {
222
- ce = the_index.cache[pos];
220
+ while (pos < the_repository->index->cache_nr) {
221
+ ce = the_repository->index->cache[pos];
222
if (strcmp(name, ce->name))
223
break;
224
seen |= (1 << ce_stage(ce));
@@ -235,10 +234,10 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
234
const struct checkout *state, int *nr_checkouts,
235
int overlay_mode)
236
{
238
- while (pos < the_index.cache_nr &&
239
- !strcmp(the_index.cache[pos]->name, ce->name)) {
240
- if (ce_stage(the_index.cache[pos]) == stage)
241
- return checkout_entry(the_index.cache[pos], state,
237
+ while (pos < the_repository->index->cache_nr &&
238
+ !strcmp(the_repository->index->cache[pos]->name, ce->name)) {
239
+ if (ce_stage(the_repository->index->cache[pos]) == stage)
240
+ return checkout_entry(the_repository->index->cache[pos], state,
241
NULL, nr_checkouts);
242
pos++;
243
}
@@ -256,7 +255,7 @@ static int checkout_merged(int pos, const struct checkout *state,
255
int *nr_checkouts, struct mem_pool *ce_mem_pool,
256
int conflict_style)
257
{
259
- struct cache_entry *ce = the_index.cache[pos];
258
+ struct cache_entry *ce = the_repository->index->cache[pos];
259
const char *path = ce->name;
260
mmfile_t ancestor, ours, theirs;
261
enum ll_merge_result merge_status;
@@ -269,7 +268,7 @@ static int checkout_merged(int pos, const struct checkout *state,
268
int renormalize = 0;
269
270
memset(threeway, 0, sizeof(threeway));
272
- while (pos < the_index.cache_nr) {
271
+ while (pos < the_repository->index->cache_nr) {
272
int stage;
273
stage = ce_stage(ce);
274
if (!stage || strcmp(path, ce->name))
@@ -278,7 +277,7 @@ static int checkout_merged(int pos, const struct checkout *state,
277
if (stage == 2)
278
mode = create_ce_mode(ce->ce_mode);
279
pos++;
281
- ce = the_index.cache[pos];
280
+ ce = the_repository->index->cache[pos];
281
}
282
if (is_null_oid(&threeway[1]) || is_null_oid(&threeway[2]))
283
return error(_("path '%s' does not have necessary versions"), path);
@@ -356,7 +355,7 @@ static void mark_ce_for_checkout_overlay(struct cache_entry *ce,
355
* match_pathspec() for _all_ entries when
356
* opts->source_tree != NULL.
357
*/
359
- if (ce_path_match(&the_index, ce, &opts->pathspec, ps_matched))
358
+ if (ce_path_match(the_repository->index, ce, &opts->pathspec, ps_matched))
359
ce->ce_flags |= CE_MATCHED;
360
}
361
@@ -367,7 +366,7 @@ static void mark_ce_for_checkout_no_overlay(struct cache_entry *ce,
366
ce->ce_flags &= ~CE_MATCHED;
367
if (!opts->ignore_skipworktree && ce_skip_worktree(ce))
368
return;
370
- if (ce_path_match(&the_index, ce, &opts->pathspec, ps_matched)) {
369
+ if (ce_path_match(the_repository->index, ce, &opts->pathspec, ps_matched)) {
370
ce->ce_flags |= CE_MATCHED;
371
if (opts->source_tree && !(ce->ce_flags & CE_UPDATE))
372
/*
@@ -391,7 +390,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
390
391
state.force = 1;
392
state.refresh_cache = 1;
394
- state.istate = &the_index;
393
+ state.istate = the_repository->index;
394
395
mem_pool_init(&ce_mem_pool, 0);
396
get_parallel_checkout_configs(&pc_workers, &pc_threshold);
@@ -404,8 +403,8 @@ static int checkout_worktree(const struct checkout_opts *opts,
403
if (pc_workers > 1)
404
init_parallel_checkout();
405
407
- for (pos = 0; pos < the_index.cache_nr; pos++) {
408
- struct cache_entry *ce = the_index.cache[pos];
406
+ for (pos = 0; pos < the_repository->index->cache_nr; pos++) {
407
+ struct cache_entry *ce = the_repository->index->cache[pos];
408
if (ce->ce_flags & CE_MATCHED) {
409
if (!ce_stage(ce)) {
410
errs |= checkout_entry(ce, &state,
@@ -429,7 +428,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
428
errs |= run_parallel_checkout(&state, pc_workers, pc_threshold,
429
NULL, NULL);
430
mem_pool_discard(&ce_mem_pool, should_validate_cache_entries());
432
- remove_marked_cache_entries(&the_index, 1);
431
+ remove_marked_cache_entries(the_repository->index, 1);
432
remove_scheduled_dirs();
433
errs |= finish_delayed_checkout(&state, opts->show_progress);
434
@@ -571,7 +570,7 @@ static int checkout_paths(const struct checkout_opts *opts,
570
if (opts->source_tree)
571
read_tree_some(opts->source_tree, &opts->pathspec);
572
if (opts->merge)
574
- unmerge_index(&the_index, &opts->pathspec, CE_MATCHED);
573
+ unmerge_index(the_repository->index, &opts->pathspec, CE_MATCHED);
574
575
ps_matched = xcalloc(opts->pathspec.nr, 1);
576
@@ -579,13 +578,13 @@ static int checkout_paths(const struct checkout_opts *opts,
578
* Make sure all pathspecs participated in locating the paths
579
* to be checked out.
580
*/
582
- for (pos = 0; pos < the_index.cache_nr; pos++)
581
+ for (pos = 0; pos < the_repository->index->cache_nr; pos++)
582
if (opts->overlay_mode)
584
- mark_ce_for_checkout_overlay(the_index.cache[pos],
583
+ mark_ce_for_checkout_overlay(the_repository->index->cache[pos],
584
ps_matched,
585
opts);
586
else
588
- mark_ce_for_checkout_no_overlay(the_index.cache[pos],
587
+ mark_ce_for_checkout_no_overlay(the_repository->index->cache[pos],
588
ps_matched,
589
opts);
590
@@ -596,8 +595,8 @@ static int checkout_paths(const struct checkout_opts *opts,
595
free(ps_matched);
596
597
/* Any unmerged paths? */
599
- for (pos = 0; pos < the_index.cache_nr; pos++) {
600
- const struct cache_entry *ce = the_index.cache[pos];
598
+ for (pos = 0; pos < the_repository->index->cache_nr; pos++) {
599
+ const struct cache_entry *ce = the_repository->index->cache[pos];
600
if (ce->ce_flags & CE_MATCHED) {
601
if (!ce_stage(ce))
602
continue;
@@ -622,7 +621,7 @@ static int checkout_paths(const struct checkout_opts *opts,
621
if (opts->checkout_worktree)
622
errs |= checkout_worktree(opts, new_branch_info);
623
else
625
- remove_marked_cache_entries(&the_index, 1);
624
+ remove_marked_cache_entries(the_repository->index, 1);
625
626
/*
627
* Allow updating the index when checking out from the index.
@@ -634,7 +633,7 @@ static int checkout_paths(const struct checkout_opts *opts,
633
checkout_index = opts->checkout_index;
634
635
if (checkout_index) {
637
- if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
636
+ if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
637
die(_("unable to write new index file"));
638
} else {
639
/*
@@ -703,8 +702,8 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
702
opts.merge = 1;
703
opts.fn = oneway_merge;
704
opts.verbose_update = o->show_progress;
706
- opts.src_index = &the_index;
707
- opts.dst_index = &the_index;
705
+ opts.src_index = the_repository->index;
706
+ opts.dst_index = the_repository->index;
707
init_checkout_metadata(&opts.meta, info->refname,
708
info->commit ? &info->commit->object.oid : null_oid(),
709
NULL);
@@ -756,12 +755,12 @@ static void init_topts(struct unpack_trees_options *topts, int merge,
755
{
756
memset(topts, 0, sizeof(*topts));
757
topts->head_idx = -1;
759
- topts->src_index = &the_index;
760
- topts->dst_index = &the_index;
758
+ topts->src_index = the_repository->index;
759
+ topts->dst_index = the_repository->index;
760
761
setup_unpack_trees_porcelain(topts, "checkout");
762
764
- topts->initial_checkout = is_index_unborn(&the_index);
763
+ topts->initial_checkout = is_index_unborn(the_repository->index);
764
topts->update = 1;
765
topts->merge = 1;
766
topts->quiet = merge && old_commit;
@@ -783,7 +782,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
782
if (repo_read_index_preload(the_repository, NULL, 0) < 0)
783
return error(_("index file corrupt"));
784
786
- resolve_undo_clear_index(&the_index);
785
+ resolve_undo_clear_index(the_repository->index);
786
if (opts->new_orphan_branch && opts->orphan_from_empty_tree) {
787
if (new_branch_info->commit)
788
BUG("'switch --orphan' should never accept a commit as starting point");
@@ -807,9 +806,9 @@ static int merge_working_tree(const struct checkout_opts *opts,
806
struct unpack_trees_options topts;
807
const struct object_id *old_commit_oid;
808
810
- refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
809
+ refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL);
810
812
- if (unmerged_index(&the_index)) {
811
+ if (unmerged_index(the_repository->index)) {
812
error(_("you need to resolve your current index first"));
813
return 1;
814
}
@@ -919,10 +918,10 @@ static int merge_working_tree(const struct checkout_opts *opts,
918
}
919
}
920
922
- if (!cache_tree_fully_valid(the_index.cache_tree))
923
- cache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
921
+ if (!cache_tree_fully_valid(the_repository->index->cache_tree))
922
+ cache_tree_update(the_repository->index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
923
925
- if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
924
+ if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
925
die(_("unable to write new index file"));
926
927
if (!opts->discard_changes && !opts->quiet && new_branch_info->commit)
builtin/clean.c
+3
-4
@@ -6,7 +6,6 @@
6
* Based on git-clean.sh by Pavel Roskin
7
*/
8
9
-#define USE_THE_INDEX_VARIABLE
9
#include "builtin.h"
10
#include "abspath.h"
11
#include "config.h"
@@ -714,7 +713,7 @@ static int filter_by_patterns_cmd(void)
713
for_each_string_list_item(item, &del_list) {
714
int dtype = DT_UNKNOWN;
715
717
- if (is_excluded(&dir, &the_index, item->string, &dtype)) {
716
+ if (is_excluded(&dir, the_repository->index, item->string, &dtype)) {
717
*item->string = '\0';
718
changed++;
719
}
@@ -1021,7 +1020,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
1020
PATHSPEC_PREFER_CWD,
1021
prefix, argv);
1022
1024
- fill_directory(&dir, &the_index, &pathspec);
1023
+ fill_directory(&dir, the_repository->index, &pathspec);
1024
correct_untracked_entries(&dir);
1025
1026
for (i = 0; i < dir.nr; i++) {
@@ -1029,7 +1028,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
1028
struct stat st;
1029
const char *rel;
1030
1032
- if (!index_name_is_other(&the_index, ent->name, ent->len))
1031
+ if (!index_name_is_other(the_repository->index, ent->name, ent->len))
1032
continue;
1033
1034
if (lstat(ent->name, &st))
builtin/commit.c
+40
-41
@@ -5,7 +5,6 @@
5
* Based on git-commit.sh by Junio C Hamano and Linus Torvalds
6
*/
7
8
-#define USE_THE_INDEX_VARIABLE
8
#include "builtin.h"
9
#include "advice.h"
10
#include "config.h"
@@ -266,19 +265,19 @@ static int list_paths(struct string_list *list, const char *with_tree,
265
266
if (with_tree) {
267
char *max_prefix = common_prefix(pattern);
269
- overlay_tree_on_index(&the_index, with_tree, max_prefix);
268
+ overlay_tree_on_index(the_repository->index, with_tree, max_prefix);
269
free(max_prefix);
270
}
271
272
/* TODO: audit for interaction with sparse-index. */
274
- ensure_full_index(&the_index);
275
- for (i = 0; i < the_index.cache_nr; i++) {
276
- const struct cache_entry *ce = the_index.cache[i];
273
+ ensure_full_index(the_repository->index);
274
+ for (i = 0; i < the_repository->index->cache_nr; i++) {
275
+ const struct cache_entry *ce = the_repository->index->cache[i];
276
struct string_list_item *item;
277
278
if (ce->ce_flags & CE_UPDATE)
279
continue;
281
- if (!ce_path_match(&the_index, ce, pattern, m))
280
+ if (!ce_path_match(the_repository->index, ce, pattern, m))
281
continue;
282
item = string_list_insert(list, ce->name);
283
if (ce_skip_worktree(ce))
@@ -302,10 +301,10 @@ static void add_remove_files(struct string_list *list)
301
continue;
302
303
if (!lstat(p->string, &st)) {
305
- if (add_to_index(&the_index, p->string, &st, 0))
304
+ if (add_to_index(the_repository->index, p->string, &st, 0))
305
die(_("updating files failed"));
306
} else
308
- remove_file_from_index(&the_index, p->string);
307
+ remove_file_from_index(the_repository->index, p->string);
308
}
309
}
310
@@ -316,7 +315,7 @@ static void create_base_index(const struct commit *current_head)
315
struct tree_desc t;
316
317
if (!current_head) {
319
- discard_index(&the_index);
318
+ discard_index(the_repository->index);
319
return;
320
}
321
@@ -324,8 +323,8 @@ static void create_base_index(const struct commit *current_head)
323
opts.head_idx = 1;
324
opts.index_only = 1;
325
opts.merge = 1;
327
- opts.src_index = &the_index;
328
- opts.dst_index = &the_index;
326
+ opts.src_index = the_repository->index;
327
+ opts.dst_index = the_repository->index;
328
329
opts.fn = oneway_merge;
330
tree = parse_tree_indirect(¤t_head->object.oid);
@@ -344,7 +343,7 @@ static void refresh_cache_or_die(int refresh_flags)
343
* refresh_flags contains REFRESH_QUIET, so the only errors
344
* are for unmerged entries.
345
*/
347
- if (refresh_index(&the_index, refresh_flags | REFRESH_IN_PORCELAIN, NULL, NULL, NULL))
346
+ if (refresh_index(the_repository->index, refresh_flags | REFRESH_IN_PORCELAIN, NULL, NULL, NULL))
347
die_resolve_conflict("commit");
348
}
349
@@ -393,7 +392,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
392
393
refresh_cache_or_die(refresh_flags);
394
396
- if (write_locked_index(&the_index, &index_lock, 0))
395
+ if (write_locked_index(the_repository->index, &index_lock, 0))
396
die(_("unable to create temporary index"));
397
398
old_repo_index_file = the_repository->index_file;
@@ -412,13 +411,13 @@ static const char *prepare_index(const char **argv, const char *prefix,
411
unsetenv(INDEX_ENVIRONMENT);
412
FREE_AND_NULL(old_index_env);
413
415
- discard_index(&the_index);
416
- read_index_from(&the_index, get_lock_file_path(&index_lock),
414
+ discard_index(the_repository->index);
415
+ read_index_from(the_repository->index, get_lock_file_path(&index_lock),
416
get_git_dir());
418
- if (cache_tree_update(&the_index, WRITE_TREE_SILENT) == 0) {
417
+ if (cache_tree_update(the_repository->index, WRITE_TREE_SILENT) == 0) {
418
if (reopen_lock_file(&index_lock) < 0)
419
die(_("unable to write index file"));
421
- if (write_locked_index(&the_index, &index_lock, 0))
420
+ if (write_locked_index(the_repository->index, &index_lock, 0))
421
die(_("unable to update temporary index"));
422
} else
423
warning(_("Failed to update main cache tree"));
@@ -450,8 +449,8 @@ static const char *prepare_index(const char **argv, const char *prefix,
449
exit(128);
450
451
refresh_cache_or_die(refresh_flags);
453
- cache_tree_update(&the_index, WRITE_TREE_SILENT);
454
- if (write_locked_index(&the_index, &index_lock, 0))
452
+ cache_tree_update(the_repository->index, WRITE_TREE_SILENT);
453
+ if (write_locked_index(the_repository->index, &index_lock, 0))
454
die(_("unable to write new index file"));
455
commit_style = COMMIT_NORMAL;
456
ret = get_lock_file_path(&index_lock);
@@ -472,10 +471,10 @@ static const char *prepare_index(const char **argv, const char *prefix,
471
repo_hold_locked_index(the_repository, &index_lock,
472
LOCK_DIE_ON_ERROR);
473
refresh_cache_or_die(refresh_flags);
475
- if (the_index.cache_changed
476
- || !cache_tree_fully_valid(the_index.cache_tree))
477
- cache_tree_update(&the_index, WRITE_TREE_SILENT);
478
- if (write_locked_index(&the_index, &index_lock,
474
+ if (the_repository->index->cache_changed
475
+ || !cache_tree_fully_valid(the_repository->index->cache_tree))
476
+ cache_tree_update(the_repository->index, WRITE_TREE_SILENT);
477
+ if (write_locked_index(the_repository->index, &index_lock,
478
COMMIT_LOCK | SKIP_IF_UNCHANGED))
479
die(_("unable to write new index file"));
480
commit_style = COMMIT_AS_IS;
@@ -516,15 +515,15 @@ static const char *prepare_index(const char **argv, const char *prefix,
515
if (list_paths(&partial, !current_head ? NULL : "HEAD", &pathspec))
516
exit(1);
517
519
- discard_index(&the_index);
518
+ discard_index(the_repository->index);
519
if (repo_read_index(the_repository) < 0)
520
die(_("cannot read the index"));
521
522
repo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR);
523
add_remove_files(&partial);
525
- refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
526
- cache_tree_update(&the_index, WRITE_TREE_SILENT);
527
- if (write_locked_index(&the_index, &index_lock, 0))
524
+ refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL);
525
+ cache_tree_update(the_repository->index, WRITE_TREE_SILENT);
526
+ if (write_locked_index(the_repository->index, &index_lock, 0))
527
die(_("unable to write new index file"));
528
529
hold_lock_file_for_update(&false_lock,
@@ -534,14 +533,14 @@ static const char *prepare_index(const char **argv, const char *prefix,
533
534
create_base_index(current_head);
535
add_remove_files(&partial);
537
- refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
536
+ refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL);
537
539
- if (write_locked_index(&the_index, &false_lock, 0))
538
+ if (write_locked_index(the_repository->index, &false_lock, 0))
539
die(_("unable to write temporary index file"));
540
542
- discard_index(&the_index);
541
+ discard_index(the_repository->index);
542
ret = get_lock_file_path(&false_lock);
544
- read_index_from(&the_index, ret, get_git_dir());
543
+ read_index_from(the_repository->index, ret, get_git_dir());
544
out:
545
string_list_clear(&partial, 0);
546
clear_pathspec(&pathspec);
@@ -999,7 +998,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
998
struct object_id oid;
999
const char *parent = "HEAD";
1000
1002
- if (!the_index.initialized && repo_read_index(the_repository) < 0)
1001
+ if (!the_repository->index->initialized && repo_read_index(the_repository) < 0)
1002
die(_("Cannot read index"));
1003
1004
if (amend)
@@ -1009,11 +1008,11 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
1008
int i, ita_nr = 0;
1009
1010
/* TODO: audit for interaction with sparse-index. */
1012
- ensure_full_index(&the_index);
1013
- for (i = 0; i < the_index.cache_nr; i++)
1014
- if (ce_intent_to_add(the_index.cache[i]))
1011
+ ensure_full_index(the_repository->index);
1012
+ for (i = 0; i < the_repository->index->cache_nr; i++)
1013
+ if (ce_intent_to_add(the_repository->index->cache[i]))
1014
ita_nr++;
1016
- committable = the_index.cache_nr - ita_nr > 0;
1015
+ committable = the_repository->index->cache_nr - ita_nr > 0;
1016
} else {
1017
/*
1018
* Unless the user did explicitly request a submodule
@@ -1081,11 +1080,11 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
1080
* and could have updated it. We must do this before we invoke
1081
* the editor and after we invoke run_status above.
1082
*/
1084
- discard_index(&the_index);
1083
+ discard_index(the_repository->index);
1084
}
1086
- read_index_from(&the_index, index_file, get_git_dir());
1085
+ read_index_from(the_repository->index, index_file, get_git_dir());
1086
1088
- if (cache_tree_update(&the_index, 0)) {
1087
+ if (cache_tree_update(the_repository->index, 0)) {
1088
error(_("Error building trees"));
1089
return 0;
1090
}
@@ -1586,7 +1585,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1585
status_format != STATUS_FORMAT_PORCELAIN_V2)
1586
progress_flag = REFRESH_PROGRESS;
1587
repo_read_index(the_repository);
1589
- refresh_index(&the_index,
1588
+ refresh_index(the_repository->index,
1589
REFRESH_QUIET|REFRESH_UNMERGED|progress_flag,
1590
&s.pathspec, NULL, NULL);
1591
@@ -1856,7 +1855,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1855
append_merge_tag_headers(parents, &tail);
1856
}
1857
1859
- if (commit_tree_extended(sb.buf, sb.len, &the_index.cache_tree->oid,
1858
+ if (commit_tree_extended(sb.buf, sb.len, &the_repository->index->cache_tree->oid,
1859
parents, &oid, author_ident.buf, NULL,
1860
sign_commit, extra)) {
1861
rollback_index_files();
builtin/describe.c
+1
-2
@@ -1,4 +1,3 @@
1
-#define USE_THE_INDEX_VARIABLE
1
#include "builtin.h"
2
#include "config.h"
3
#include "environment.h"
@@ -674,7 +673,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
673
prepare_repo_settings(the_repository);
674
the_repository->settings.command_requires_full_index = 0;
675
repo_read_index(the_repository);
677
- refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,
676
+ refresh_index(the_repository->index, REFRESH_QUIET|REFRESH_UNMERGED,
677
NULL, NULL, NULL);
678
fd = repo_hold_locked_index(the_repository,
679
&index_lock, 0);
builtin/diff-tree.c
+1
-2
@@ -1,4 +1,3 @@
1
-#define USE_THE_INDEX_VARIABLE
1
#include "builtin.h"
2
#include "config.h"
3
#include "diff.h"
@@ -206,7 +205,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
205
opt->diffopt.rotate_to_strict = 0;
206
opt->diffopt.no_free = 1;
207
if (opt->diffopt.detect_rename) {
209
- if (!the_index.cache)
208
+ if (the_repository->index->cache)
209
repo_read_index(the_repository);
210
opt->diffopt.setup |= DIFF_SETUP_USE_SIZE_CACHE;
211
}
builtin/diff.c
+3
-3
@@ -3,7 +3,7 @@
3
*
4
* Copyright (c) 2006 Junio C Hamano
5
*/
6
-#define USE_THE_INDEX_VARIABLE
6
+
7
#include "builtin.h"
8
#include "config.h"
9
#include "ewah/ewok.h"
@@ -239,9 +239,9 @@ static void refresh_index_quietly(void)
239
fd = repo_hold_locked_index(the_repository, &lock_file, 0);
240
if (fd < 0)
241
return;
242
- discard_index(&the_index);
242
+ discard_index(the_repository->index);
243
repo_read_index(the_repository);
244
- refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL,
244
+ refresh_index(the_repository->index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL,
245
NULL);
246
repo_update_index_if_able(the_repository, &lock_file);
247
}
builtin/difftool.c
+2
-2
@@ -11,7 +11,7 @@
11
*
12
* Copyright (C) 2016 Johannes Schindelin
13
*/
14
-#define USE_THE_INDEX_VARIABLE
14
+
15
#include "builtin.h"
16
#include "abspath.h"
17
#include "config.h"
@@ -117,7 +117,7 @@ static int use_wt_file(const char *workdir, const char *name,
117
int fd = open(buf.buf, O_RDONLY);
118
119
if (fd >= 0 &&
120
- !index_fd(&the_index, &wt_oid, fd, &st, OBJ_BLOB, name, 0)) {
120
+ !index_fd(the_repository->index, &wt_oid, fd, &st, OBJ_BLOB, name, 0)) {
121
if (is_null_oid(oid)) {
122
oidcpy(oid, &wt_oid);
123
use = 1;
builtin/merge-index.c
+8
-9
@@ -1,4 +1,3 @@
1
-#define USE_THE_INDEX_VARIABLE
1
#include "builtin.h"
2
#include "hex.h"
3
#include "read-cache-ll.h"
@@ -18,11 +17,11 @@ static int merge_entry(int pos, const char *path)
17
char ownbuf[4][60];
18
struct child_process cmd = CHILD_PROCESS_INIT;
19
21
- if (pos >= the_index.cache_nr)
20
+ if (pos >= the_repository->index->cache_nr)
21
die("git merge-index: %s not in the cache", path);
22
found = 0;
23
do {
25
- const struct cache_entry *ce = the_index.cache[pos];
24
+ const struct cache_entry *ce = the_repository->index->cache[pos];
25
int stage = ce_stage(ce);
26
27
if (strcmp(ce->name, path))
@@ -32,7 +31,7 @@ static int merge_entry(int pos, const char *path)
31
xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%o", ce->ce_mode);
32
arguments[stage] = hexbuf[stage];
33
arguments[stage + 4] = ownbuf[stage];
35
- } while (++pos < the_index.cache_nr);
34
+ } while (++pos < the_repository->index->cache_nr);
35
if (!found)
36
die("git merge-index: %s not in the cache", path);
37
@@ -51,7 +50,7 @@ static int merge_entry(int pos, const char *path)
50
51
static void merge_one_path(const char *path)
52
{
54
- int pos = index_name_pos(&the_index, path, strlen(path));
53
+ int pos = index_name_pos(the_repository->index, path, strlen(path));
54
55
/*
56
* If it already exists in the cache as stage0, it's
@@ -65,9 +64,9 @@ static void merge_all(void)
64
{
65
int i;
66
/* TODO: audit for interaction with sparse-index. */
68
- ensure_full_index(&the_index);
69
- for (i = 0; i < the_index.cache_nr; i++) {
70
- const struct cache_entry *ce = the_index.cache[i];
67
+ ensure_full_index(the_repository->index);
68
+ for (i = 0; i < the_repository->index->cache_nr; i++) {
69
+ const struct cache_entry *ce = the_repository->index->cache[i];
70
if (!ce_stage(ce))
71
continue;
72
i += merge_entry(i, ce->name)-1;
@@ -89,7 +88,7 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix UNUSED)
88
repo_read_index(the_repository);
89
90
/* TODO: audit for interaction with sparse-index. */
92
- ensure_full_index(&the_index);
91
+ ensure_full_index(the_repository->index);
92
93
i = 1;
94
if (!strcmp(argv[i], "-o")) {
builtin/merge-tree.c
+1
-2
@@ -1,4 +1,3 @@
1
-#define USE_THE_INDEX_VARIABLE
1
#include "builtin.h"
2
#include "tree-walk.h"
3
#include "xdiff-interface.h"
@@ -364,7 +363,7 @@ static void trivial_merge_trees(struct tree_desc t[3], const char *base)
363
364
setup_traverse_info(&info, base);
365
info.fn = threeway_callback;
367
- traverse_trees(&the_index, 3, t, &info);
366
+ traverse_trees(the_repository->index, 3, t, &info);
367
}
368
369
static void *get_tree_descriptor(struct repository *r,
builtin/merge.c
+15
-16
@@ -6,7 +6,6 @@
6
* Based on git-merge.sh by Junio C Hamano.
7
*/
8
9
-#define USE_THE_INDEX_VARIABLE
9
#include "builtin.h"
10
#include "abspath.h"
11
#include "advice.h"
@@ -300,7 +299,7 @@ static int save_state(struct object_id *stash)
299
int rc = -1;
300
301
fd = repo_hold_locked_index(the_repository, &lock_file, 0);
303
- refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
302
+ refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL);
303
if (0 <= fd)
304
repo_update_index_if_able(the_repository, &lock_file);
305
rollback_lock_file(&lock_file);
@@ -372,7 +371,7 @@ static void restore_state(const struct object_id *head,
371
run_command(&cmd);
372
373
refresh_cache:
375
- discard_index(&the_index);
374
+ discard_index(the_repository->index);
375
if (repo_read_index(the_repository) < 0)
376
die(_("could not read index"));
377
}
@@ -657,8 +656,8 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
656
657
memset(&opts, 0, sizeof(opts));
658
opts.head_idx = 2;
660
- opts.src_index = &the_index;
661
- opts.dst_index = &the_index;
659
+ opts.src_index = the_repository->index;
660
+ opts.dst_index = the_repository->index;
661
opts.update = 1;
662
opts.verbose_update = 1;
663
opts.trivial_merges_only = 1;
@@ -674,7 +673,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
673
if (!trees[nr_trees++])
674
return -1;
675
opts.fn = threeway_merge;
677
- cache_tree_free(&the_index.cache_tree);
676
+ cache_tree_free(&the_repository->index->cache_tree);
677
for (i = 0; i < nr_trees; i++) {
678
parse_tree(trees[i]);
679
init_tree_desc(t+i, &trees[i]->object.oid,
@@ -687,7 +686,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
686
687
static void write_tree_trivial(struct object_id *oid)
688
{
690
- if (write_index_as_tree(oid, &the_index, get_index_file(), 0, NULL))
689
+ if (write_index_as_tree(oid, the_repository->index, get_index_file(), 0, NULL))
690
die(_("git write-tree failed to write a tree"));
691
}
692
@@ -745,7 +744,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
744
rollback_lock_file(&lock);
745
return 2;
746
}
748
- if (write_locked_index(&the_index, &lock,
747
+ if (write_locked_index(the_repository->index, &lock,
748
COMMIT_LOCK | SKIP_IF_UNCHANGED))
749
die(_("unable to write %s"), get_index_file());
750
return clean ? 0 : 1;
@@ -768,8 +767,8 @@ static int count_unmerged_entries(void)
767
{
768
int i, ret = 0;
769
771
- for (i = 0; i < the_index.cache_nr; i++)
772
- if (ce_stage(the_index.cache[i]))
770
+ for (i = 0; i < the_repository->index->cache_nr; i++)
771
+ if (ce_stage(the_repository->index->cache[i]))
772
ret++;
773
774
return ret;
@@ -843,9 +842,9 @@ static void prepare_to_commit(struct commit_list *remoteheads)
842
* the editor and after we invoke run_status above.
843
*/
844
if (invoked_hook)
846
- discard_index(&the_index);
845
+ discard_index(the_repository->index);
846
}
848
- read_index_from(&the_index, index_file, get_git_dir());
847
+ read_index_from(the_repository->index, index_file, get_git_dir());
848
strbuf_addbuf(&msg, &merge_msg);
849
if (squash)
850
BUG("the control must not reach here under --squash");
@@ -957,7 +956,7 @@ static int suggest_conflicts(void)
956
* Thus, we will get the cleanup mode which is returned when we _are_
957
* using an editor.
958
*/
960
- append_conflicts_hint(&the_index, &msgbuf,
959
+ append_conflicts_hint(the_repository->index, &msgbuf,
960
get_cleanup_mode(cleanup_arg, 1));
961
fputs(msgbuf.buf, fp);
962
strbuf_release(&msgbuf);
@@ -1386,7 +1385,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1385
else
1386
die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists)."));
1387
}
1389
- resolve_undo_clear_index(&the_index);
1388
+ resolve_undo_clear_index(the_repository->index);
1389
1390
if (option_edit < 0)
1391
option_edit = default_edit_option();
@@ -1595,7 +1594,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1594
* We are not doing octopus, not fast-forward, and have
1595
* only one common.
1596
*/
1598
- refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
1597
+ refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL);
1598
if (allow_trivial && fast_forward != FF_ONLY) {
1599
/*
1600
* Must first ensure that index matches HEAD before
@@ -1784,6 +1783,6 @@ done:
1783
}
1784
strbuf_release(&buf);
1785
free(branch_to_free);
1787
- discard_index(&the_index);
1786
+ discard_index(the_repository->index);
1787
return ret;
1788
}
builtin/mv.c
+34
-34
@@ -3,7 +3,7 @@
3
*
4
* Copyright (C) 2006 Johannes Schindelin
5
*/
6
-#define USE_THE_INDEX_VARIABLE
6
+
7
#include "builtin.h"
8
#include "abspath.h"
9
#include "advice.h"
@@ -95,9 +95,9 @@ static void prepare_move_submodule(const char *src, int first,
95
const char **submodule_gitfile)
96
{
97
struct strbuf submodule_dotgit = STRBUF_INIT;
98
- if (!S_ISGITLINK(the_index.cache[first]->ce_mode))
98
+ if (!S_ISGITLINK(the_repository->index->cache[first]->ce_mode))
99
die(_("Directory %s is in index and no submodule?"), src);
100
- if (!is_staging_gitmodules_ok(&the_index))
100
+ if (!is_staging_gitmodules_ok(the_repository->index))
101
die(_("Please stage your changes to .gitmodules or stash them to proceed"));
102
strbuf_addf(&submodule_dotgit, "%s/.git", src);
103
*submodule_gitfile = read_gitfile(submodule_dotgit.buf);
@@ -114,13 +114,13 @@ static int index_range_of_same_dir(const char *src, int length,
114
const char *src_w_slash = add_slash(src);
115
int first, last, len_w_slash = length + 1;
116
117
- first = index_name_pos(&the_index, src_w_slash, len_w_slash);
117
+ first = index_name_pos(the_repository->index, src_w_slash, len_w_slash);
118
if (first >= 0)
119
die(_("%.*s is in index"), len_w_slash, src_w_slash);
120
121
first = -1 - first;
122
- for (last = first; last < the_index.cache_nr; last++) {
123
- const char *path = the_index.cache[last]->name;
122
+ for (last = first; last < the_repository->index->cache_nr; last++) {
123
+ const char *path = the_repository->index->cache[last]->name;
124
if (strncmp(path, src_w_slash, len_w_slash))
125
break;
126
}
@@ -144,14 +144,14 @@ static int empty_dir_has_sparse_contents(const char *name)
144
const char *with_slash = add_slash(name);
145
int length = strlen(with_slash);
146
147
- int pos = index_name_pos(&the_index, with_slash, length);
147
+ int pos = index_name_pos(the_repository->index, with_slash, length);
148
const struct cache_entry *ce;
149
150
if (pos < 0) {
151
pos = -pos - 1;
152
- if (pos >= the_index.cache_nr)
152
+ if (pos >= the_repository->index->cache_nr)
153
goto free_return;
154
- ce = the_index.cache[pos];
154
+ ce = the_repository->index->cache[pos];
155
if (strncmp(with_slash, ce->name, length))
156
goto free_return;
157
if (ce_skip_worktree(ce))
@@ -223,7 +223,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
223
S_ISDIR(st.st_mode)) {
224
destination = internal_prefix_pathspec(dst_w_slash, argv, argc, DUP_BASENAME);
225
} else {
226
- if (!path_in_sparse_checkout(dst_w_slash, &the_index) &&
226
+ if (!path_in_sparse_checkout(dst_w_slash, the_repository->index) &&
227
empty_dir_has_sparse_contents(dst_w_slash)) {
228
destination = internal_prefix_pathspec(dst_w_slash, argv, argc, DUP_BASENAME);
229
dst_mode = SKIP_WORKTREE_DIR;
@@ -239,7 +239,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
239
* is deprecated at this point) sparse-checkout. As
240
* SPARSE here is only considering cone-mode situation.
241
*/
242
- if (!path_in_cone_mode_sparse_checkout(destination[0], &the_index))
242
+ if (!path_in_cone_mode_sparse_checkout(destination[0], the_repository->index))
243
dst_mode = SPARSE;
244
}
245
}
@@ -263,10 +263,10 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
263
int pos;
264
const struct cache_entry *ce;
265
266
- pos = index_name_pos(&the_index, src, length);
266
+ pos = index_name_pos(the_repository->index, src, length);
267
if (pos < 0) {
268
const char *src_w_slash = add_slash(src);
269
- if (!path_in_sparse_checkout(src_w_slash, &the_index) &&
269
+ if (!path_in_sparse_checkout(src_w_slash, the_repository->index) &&
270
empty_dir_has_sparse_contents(src)) {
271
modes[i] |= SKIP_WORKTREE_DIR;
272
goto dir_check;
@@ -276,7 +276,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
276
bad = _("bad source");
277
goto act_on_entry;
278
}
279
- ce = the_index.cache[pos];
279
+ ce = the_repository->index->cache[pos];
280
if (!ce_skip_worktree(ce)) {
281
bad = _("bad source");
282
goto act_on_entry;
@@ -286,7 +286,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
286
goto act_on_entry;
287
}
288
/* Check if dst exists in index */
289
- if (index_name_pos(&the_index, dst, strlen(dst)) < 0) {
289
+ if (index_name_pos(the_repository->index, dst, strlen(dst)) < 0) {
290
modes[i] |= SPARSE;
291
goto act_on_entry;
292
}
@@ -311,7 +311,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
311
dir_check:
312
if (S_ISDIR(st.st_mode)) {
313
int j, dst_len, n;
314
- int first = index_name_pos(&the_index, src, length), last;
314
+ int first = index_name_pos(the_repository->index, src, length), last;
315
316
if (first >= 0) {
317
prepare_move_submodule(src, first,
@@ -339,7 +339,7 @@ dir_check:
339
dst_len = strlen(dst);
340
341
for (j = 0; j < last - first; j++) {
342
- const struct cache_entry *ce = the_index.cache[first + j];
342
+ const struct cache_entry *ce = the_repository->index->cache[first + j];
343
const char *path = ce->name;
344
source[argc + j] = path;
345
destination[argc + j] =
@@ -351,7 +351,7 @@ dir_check:
351
argc += last - first;
352
goto act_on_entry;
353
}
354
- if (!(ce = index_file_exists(&the_index, src, length, 0))) {
354
+ if (!(ce = index_file_exists(the_repository->index, src, length, 0))) {
355
bad = _("not under version control");
356
goto act_on_entry;
357
}
@@ -387,7 +387,7 @@ dir_check:
387
388
if (ignore_sparse &&
389
(dst_mode & (SKIP_WORKTREE_DIR | SPARSE)) &&
390
- index_entry_exists(&the_index, dst, strlen(dst))) {
390
+ index_entry_exists(the_repository->index, dst, strlen(dst))) {
391
bad = _("destination exists in the index");
392
if (force) {
393
if (verbose)
@@ -404,12 +404,12 @@ dir_check:
404
* option as a way to have a successful run.
405
*/
406
if (!ignore_sparse &&
407
- !path_in_sparse_checkout(src, &the_index)) {
407
+ !path_in_sparse_checkout(src, the_repository->index)) {
408
string_list_append(&only_match_skip_worktree, src);
409
skip_sparse = 1;
410
}
411
if (!ignore_sparse &&
412
- !path_in_sparse_checkout(dst, &the_index)) {
412
+ !path_in_sparse_checkout(dst, the_repository->index)) {
413
string_list_append(&only_match_skip_worktree, dst);
414
skip_sparse = 1;
415
}
@@ -449,7 +449,7 @@ remove_entry:
449
int pos;
450
int sparse_and_dirty = 0;
451
struct checkout state = CHECKOUT_INIT;
452
- state.istate = &the_index;
452
+ state.istate = the_repository->index;
453
454
if (force)
455
state.force = 1;
@@ -476,14 +476,14 @@ remove_entry:
476
if (mode & (WORKING_DIRECTORY | SKIP_WORKTREE_DIR))
477
continue;
478
479
- pos = index_name_pos(&the_index, src, strlen(src));
479
+ pos = index_name_pos(the_repository->index, src, strlen(src));
480
assert(pos >= 0);
481
if (!(mode & SPARSE) && !lstat(src, &st))
482
- sparse_and_dirty = ie_modified(&the_index,
483
- the_index.cache[pos],
482
+ sparse_and_dirty = ie_modified(the_repository->index,
483
+ the_repository->index->cache[pos],
484
&st,
485
0);
486
- rename_index_entry_at(&the_index, pos, dst);
486
+ rename_index_entry_at(the_repository->index, pos, dst);
487
488
if (ignore_sparse &&
489
core_apply_sparse_checkout &&
@@ -495,11 +495,11 @@ remove_entry:
495
* should be added in a future patch.
496
*/
497
if ((mode & SPARSE) &&
498
- path_in_sparse_checkout(dst, &the_index)) {
498
+ path_in_sparse_checkout(dst, the_repository->index)) {
499
/* from out-of-cone to in-cone */
500
- int dst_pos = index_name_pos(&the_index, dst,
500
+ int dst_pos = index_name_pos(the_repository->index, dst,
501
strlen(dst));
502
- struct cache_entry *dst_ce = the_index.cache[dst_pos];
502
+ struct cache_entry *dst_ce = the_repository->index->cache[dst_pos];
503
504
dst_ce->ce_flags &= ~CE_SKIP_WORKTREE;
505
@@ -507,11 +507,11 @@ remove_entry:
507
die(_("cannot checkout %s"), dst_ce->name);
508
} else if ((dst_mode & (SKIP_WORKTREE_DIR | SPARSE)) &&
509
!(mode & SPARSE) &&
510
- !path_in_sparse_checkout(dst, &the_index)) {
510
+ !path_in_sparse_checkout(dst, the_repository->index)) {
511
/* from in-cone to out-of-cone */
512
- int dst_pos = index_name_pos(&the_index, dst,
512
+ int dst_pos = index_name_pos(the_repository->index, dst,
513
strlen(dst));
514
- struct cache_entry *dst_ce = the_index.cache[dst_pos];
514
+ struct cache_entry *dst_ce = the_repository->index->cache[dst_pos];
515
516
/*
517
* if src is clean, it will suffice to remove it
@@ -559,9 +559,9 @@ remove_entry:
559
advise_on_moving_dirty_path(&dirty_paths);
560
561
if (gitmodules_modified)
562
- stage_updated_gitmodules(&the_index);
562
+ stage_updated_gitmodules(the_repository->index);
563
564
- if (write_locked_index(&the_index, &lock_file,
564
+ if (write_locked_index(the_repository->index, &lock_file,
565
COMMIT_LOCK | SKIP_IF_UNCHANGED))
566
die(_("Unable to write new index file"));
567
builtin/pull.c
+2
-2
@@ -5,7 +5,7 @@
5
*
6
* Fetch one or more remote refs and merge it/them into the current HEAD.
7
*/
8
-#define USE_THE_INDEX_VARIABLE
8
+
9
#include "builtin.h"
10
#include "advice.h"
11
#include "config.h"
@@ -1044,7 +1044,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
1044
if (opt_autostash == -1)
1045
opt_autostash = config_autostash;
1046
1047
- if (is_null_oid(&orig_head) && !is_index_unborn(&the_index))
1047
+ if (is_null_oid(&orig_head) && !is_index_unborn(the_repository->index))
1048
die(_("Updating an unborn branch with changes added to the index."));
1049
1050
if (!opt_autostash)
builtin/read-tree.c
+7
-8
@@ -4,7 +4,6 @@
4
* Copyright (C) Linus Torvalds, 2005
5
*/
6
7
-#define USE_THE_INDEX_VARIABLE
7
#include "builtin.h"
8
#include "config.h"
9
#include "gettext.h"
@@ -159,8 +158,8 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
158
159
memset(&opts, 0, sizeof(opts));
160
opts.head_idx = -1;
162
- opts.src_index = &the_index;
163
- opts.dst_index = &the_index;
161
+ opts.src_index = the_repository->index;
162
+ opts.dst_index = the_repository->index;
163
164
git_config(git_read_tree_config, NULL);
165
@@ -197,7 +196,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
196
die(_("You need to resolve your current index first"));
197
stage = opts.merge = 1;
198
}
200
- resolve_undo_clear_index(&the_index);
199
+ resolve_undo_clear_index(the_repository->index);
200
201
for (i = 0; i < argc; i++) {
202
const char *arg = argv[i];
@@ -225,7 +224,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
224
setup_work_tree();
225
226
if (opts.skip_sparse_checkout)
228
- ensure_full_index(&the_index);
227
+ ensure_full_index(the_repository->index);
228
229
if (opts.merge) {
230
switch (stage - 1) {
@@ -237,7 +236,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
236
break;
237
case 2:
238
opts.fn = twoway_merge;
240
- opts.initial_checkout = is_index_unborn(&the_index);
239
+ opts.initial_checkout = is_index_unborn(the_repository->index);
240
break;
241
case 3:
242
default:
@@ -258,7 +257,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
257
if (nr_trees == 1 && !opts.prefix)
258
opts.skip_cache_tree_update = 1;
259
261
- cache_tree_free(&the_index.cache_tree);
260
+ cache_tree_free(&the_repository->index->cache_tree);
261
for (i = 0; i < nr_trees; i++) {
262
struct tree *tree = trees[i];
263
if (parse_tree(tree) < 0)
@@ -282,7 +281,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
281
the_repository->index,
282
trees[0]);
283
285
- if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
284
+ if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
285
die("unable to write new index file");
286
return 0;
287
}
builtin/rebase.c
+1
-2
@@ -4,7 +4,6 @@
4
* Copyright (c) 2018 Pratik Karki
5
*/
6
7
-#define USE_THE_INDEX_VARIABLE
7
#include "builtin.h"
8
#include "abspath.h"
9
#include "environment.h"
@@ -295,7 +294,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
294
if (ret)
295
error(_("could not generate todo list"));
296
else {
298
- discard_index(&the_index);
297
+ discard_index(the_repository->index);
298
if (todo_list_parse_insn_buffer(the_repository, todo_list.buf.buf,
299
&todo_list))
300
BUG("unusable todo list");
builtin/replay.c
-1
@@ -2,7 +2,6 @@
2
* "git replay" builtin command
3
*/
4
5
-#define USE_THE_INDEX_VARIABLE
5
#include "git-compat-util.h"
6
7
#include "builtin.h"
builtin/reset.c
+16
-16
@@ -7,7 +7,7 @@
7
*
8
* Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
9
*/
10
-#define USE_THE_INDEX_VARIABLE
10
+
11
#include "builtin.h"
12
#include "advice.h"
13
#include "config.h"
@@ -66,8 +66,8 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t
66
67
memset(&opts, 0, sizeof(opts));
68
opts.head_idx = 1;
69
- opts.src_index = &the_index;
70
- opts.dst_index = &the_index;
69
+ opts.src_index = the_repository->index;
70
+ opts.dst_index = the_repository->index;
71
opts.fn = oneway_merge;
72
opts.merge = 1;
73
init_checkout_metadata(&opts.meta, ref, oid, NULL);
@@ -159,11 +159,11 @@ static void update_index_from_diff(struct diff_queue_struct *q,
159
struct cache_entry *ce;
160
161
if (!is_in_reset_tree && !intent_to_add) {
162
- remove_file_from_index(&the_index, one->path);
162
+ remove_file_from_index(the_repository->index, one->path);
163
continue;
164
}
165
166
- ce = make_cache_entry(&the_index, one->mode, &one->oid, one->path,
166
+ ce = make_cache_entry(the_repository->index, one->mode, &one->oid, one->path,
167
0, 0);
168
169
/*
@@ -174,9 +174,9 @@ static void update_index_from_diff(struct diff_queue_struct *q,
174
* if this entry is outside the sparse cone - this is necessary
175
* to properly construct the reset sparse directory.
176
*/
177
- pos = index_name_pos(&the_index, one->path, strlen(one->path));
178
- if ((pos >= 0 && ce_skip_worktree(the_index.cache[pos])) ||
179
- (pos < 0 && !path_in_sparse_checkout(one->path, &the_index)))
177
+ pos = index_name_pos(the_repository->index, one->path, strlen(one->path));
178
+ if ((pos >= 0 && ce_skip_worktree(the_repository->index->cache[pos])) ||
179
+ (pos < 0 && !path_in_sparse_checkout(one->path, the_repository->index)))
180
ce->ce_flags |= CE_SKIP_WORKTREE;
181
182
if (!ce)
@@ -186,7 +186,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,
186
ce->ce_flags |= CE_INTENT_TO_ADD;
187
set_object_name_for_intent_to_add_entry(ce);
188
}
189
- add_index_entry(&the_index, ce,
189
+ add_index_entry(the_repository->index, ce,
190
ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
191
}
192
}
@@ -208,8 +208,8 @@ static int read_from_tree(const struct pathspec *pathspec,
208
opt.change = diff_change;
209
opt.add_remove = diff_addremove;
210
211
- if (pathspec->nr && pathspec_needs_expanded_index(&the_index, pathspec))
212
- ensure_full_index(&the_index);
211
+ if (pathspec->nr && pathspec_needs_expanded_index(the_repository->index, pathspec))
212
+ ensure_full_index(the_repository->index);
213
214
if (do_diff_cache(tree_oid, &opt))
215
return 1;
@@ -235,7 +235,7 @@ static void set_reflog_message(struct strbuf *sb, const char *action,
235
236
static void die_if_unmerged_cache(int reset_type)
237
{
238
- if (is_merge() || unmerged_index(&the_index))
238
+ if (is_merge() || unmerged_index(the_repository->index))
239
die(_("Cannot do a %s reset in the middle of a merge."),
240
_(reset_type_names[reset_type]));
241
@@ -470,12 +470,12 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
470
update_ref_status = 1;
471
goto cleanup;
472
}
473
- the_index.updated_skipworktree = 1;
473
+ the_repository->index->updated_skipworktree = 1;
474
if (!no_refresh && get_git_work_tree()) {
475
uint64_t t_begin, t_delta_in_ms;
476
477
t_begin = getnanotime();
478
- refresh_index(&the_index, flags, NULL, NULL,
478
+ refresh_index(the_repository->index, flags, NULL, NULL,
479
_("Unstaged changes after reset:"));
480
t_delta_in_ms = (getnanotime() - t_begin) / 1000000;
481
if (!quiet && advice_enabled(ADVICE_RESET_NO_REFRESH_WARNING) && t_delta_in_ms > REFRESH_INDEX_DELAY_WARNING_IN_MS) {
@@ -501,7 +501,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
501
free(ref);
502
}
503
504
- if (write_locked_index(&the_index, &lock, COMMIT_LOCK))
504
+ if (write_locked_index(the_repository->index, &lock, COMMIT_LOCK))
505
die(_("Could not write new index file."));
506
}
507
@@ -516,7 +516,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
516
if (!pathspec.nr)
517
remove_branch_state(the_repository, 0);
518
519
- discard_index(&the_index);
519
+ discard_index(the_repository->index);
520
521
cleanup:
522
clear_pathspec(&pathspec);
builtin/rev-parse.c
+3
-3
@@ -3,7 +3,7 @@
3
*
4
* Copyright (C) Linus Torvalds, 2005
5
*/
6
-#define USE_THE_INDEX_VARIABLE
6
+
7
#include "builtin.h"
8
#include "abspath.h"
9
#include "config.h"
@@ -1049,8 +1049,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
1049
if (!strcmp(arg, "--shared-index-path")) {
1050
if (repo_read_index(the_repository) < 0)
1051
die(_("Could not read the index"));
1052
- if (the_index.split_index) {
1053
- const struct object_id *oid = &the_index.split_index->base_oid;
1052
+ if (the_repository->index->split_index) {
1053
+ const struct object_id *oid = &the_repository->index->split_index->base_oid;
1054
const char *path = git_path("sharedindex.%s", oid_to_hex(oid));
1055
print_path(path, prefix, format, DEFAULT_RELATIVE);
1056
}
builtin/rm.c
+20
-20
@@ -3,7 +3,7 @@
3
*
4
* Copyright (C) Linus Torvalds 2006
5
*/
6
-#define USE_THE_INDEX_VARIABLE
6
+
7
#include "builtin.h"
8
#include "advice.h"
9
#include "config.h"
@@ -41,8 +41,8 @@ static int get_ours_cache_pos(const char *path, int pos)
41
{
42
int i = -pos - 1;
43
44
- while ((i < the_index.cache_nr) && !strcmp(the_index.cache[i]->name, path)) {
45
- if (ce_stage(the_index.cache[i]) == 2)
44
+ while ((i < the_repository->index->cache_nr) && !strcmp(the_repository->index->cache[i]->name, path)) {
45
+ if (ce_stage(the_repository->index->cache[i]) == 2)
46
return i;
47
i++;
48
}
@@ -78,13 +78,13 @@ static void submodules_absorb_gitdir_if_needed(void)
78
int pos;
79
const struct cache_entry *ce;
80
81
- pos = index_name_pos(&the_index, name, strlen(name));
81
+ pos = index_name_pos(the_repository->index, name, strlen(name));
82
if (pos < 0) {
83
pos = get_ours_cache_pos(name, pos);
84
if (pos < 0)
85
continue;
86
}
87
- ce = the_index.cache[pos];
87
+ ce = the_repository->index->cache[pos];
88
89
if (!S_ISGITLINK(ce->ce_mode) ||
90
!file_exists(ce->name) ||
@@ -122,7 +122,7 @@ static int check_local_mod(struct object_id *head, int index_only)
122
int local_changes = 0;
123
int staged_changes = 0;
124
125
- pos = index_name_pos(&the_index, name, strlen(name));
125
+ pos = index_name_pos(the_repository->index, name, strlen(name));
126
if (pos < 0) {
127
/*
128
* Skip unmerged entries except for populated submodules
@@ -132,11 +132,11 @@ static int check_local_mod(struct object_id *head, int index_only)
132
if (pos < 0)
133
continue;
134
135
- if (!S_ISGITLINK(the_index.cache[pos]->ce_mode) ||
135
+ if (!S_ISGITLINK(the_repository->index->cache[pos]->ce_mode) ||
136
is_empty_dir(name))
137
continue;
138
}
139
- ce = the_index.cache[pos];
139
+ ce = the_repository->index->cache[pos];
140
141
if (lstat(ce->name, &st) < 0) {
142
if (!is_missing_file_error(errno))
@@ -173,7 +173,7 @@ static int check_local_mod(struct object_id *head, int index_only)
173
* Is the index different from the file in the work tree?
174
* If it's a submodule, is its work tree modified?
175
*/
176
- if (ie_match_stat(&the_index, ce, &st, 0) ||
176
+ if (ie_match_stat(the_repository->index, ce, &st, 0) ||
177
(S_ISGITLINK(ce->ce_mode) &&
178
bad_to_remove_submodule(ce->name,
179
SUBMODULE_REMOVAL_DIE_ON_ERROR |
@@ -301,27 +301,27 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
301
if (repo_read_index(the_repository) < 0)
302
die(_("index file corrupt"));
303
304
- refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &pathspec, NULL, NULL);
304
+ refresh_index(the_repository->index, REFRESH_QUIET|REFRESH_UNMERGED, &pathspec, NULL, NULL);
305
306
seen = xcalloc(pathspec.nr, 1);
307
308
- if (pathspec_needs_expanded_index(&the_index, &pathspec))
309
- ensure_full_index(&the_index);
308
+ if (pathspec_needs_expanded_index(the_repository->index, &pathspec))
309
+ ensure_full_index(the_repository->index);
310
311
- for (i = 0; i < the_index.cache_nr; i++) {
312
- const struct cache_entry *ce = the_index.cache[i];
311
+ for (i = 0; i < the_repository->index->cache_nr; i++) {
312
+ const struct cache_entry *ce = the_repository->index->cache[i];
313
314
if (!include_sparse &&
315
(ce_skip_worktree(ce) ||
316
- !path_in_sparse_checkout(ce->name, &the_index)))
316
+ !path_in_sparse_checkout(ce->name, the_repository->index)))
317
continue;
318
- if (!ce_path_match(&the_index, ce, &pathspec, seen))
318
+ if (!ce_path_match(the_repository->index, ce, &pathspec, seen))
319
continue;
320
ALLOC_GROW(list.entry, list.nr + 1, list.alloc);
321
list.entry[list.nr].name = xstrdup(ce->name);
322
list.entry[list.nr].is_submodule = S_ISGITLINK(ce->ce_mode);
323
if (list.entry[list.nr++].is_submodule &&
324
- !is_staging_gitmodules_ok(&the_index))
324
+ !is_staging_gitmodules_ok(the_repository->index))
325
die(_("please stage your changes to .gitmodules or stash them to proceed"));
326
}
327
@@ -391,7 +391,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
391
if (!quiet)
392
printf("rm '%s'\n", path);
393
394
- if (remove_file_from_index(&the_index, path))
394
+ if (remove_file_from_index(the_repository->index, path))
395
die(_("git rm: unable to remove %s"), path);
396
}
397
@@ -432,10 +432,10 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
432
}
433
strbuf_release(&buf);
434
if (gitmodules_modified)
435
- stage_updated_gitmodules(&the_index);
435
+ stage_updated_gitmodules(the_repository->index);
436
}
437
438
- if (write_locked_index(&the_index, &lock_file,
438
+ if (write_locked_index(the_repository->index, &lock_file,
439
COMMIT_LOCK | SKIP_IF_UNCHANGED))
440
die(_("Unable to write new index file"));
441
builtin/stash.c
+22
-23
@@ -1,4 +1,3 @@
1
-#define USE_THE_INDEX_VARIABLE
1
#include "builtin.h"
2
#include "abspath.h"
3
#include "config.h"
@@ -273,7 +272,7 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)
272
struct lock_file lock_file = LOCK_INIT;
273
274
repo_read_index_preload(the_repository, NULL, 0);
276
- if (refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL))
275
+ if (refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL))
276
return -1;
277
278
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
@@ -287,8 +286,8 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)
286
init_tree_desc(t, &tree->object.oid, tree->buffer, tree->size);
287
288
opts.head_idx = 1;
290
- opts.src_index = &the_index;
291
- opts.dst_index = &the_index;
289
+ opts.src_index = the_repository->index;
290
+ opts.dst_index = the_repository->index;
291
opts.merge = 1;
292
opts.reset = reset ? UNPACK_RESET_PROTECT_UNTRACKED : 0;
293
opts.update = update;
@@ -299,7 +298,7 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)
298
if (unpack_trees(nr_trees, t, &opts))
299
return -1;
300
302
- if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
301
+ if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
302
return error(_("unable to write new index file"));
303
304
return 0;
@@ -430,7 +429,7 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)
429
state.force = 1;
430
state.quiet = 1;
431
state.refresh_cache = 1;
433
- state.istate = &the_index;
432
+ state.istate = the_repository->index;
433
434
/*
435
* Step 1: get a difference between orig_tree (which corresponding
@@ -454,7 +453,7 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)
453
454
/* Look up the path's position in the current index. */
455
p = diff_queued_diff.queue[i];
457
- pos = index_name_pos(&the_index, p->two->path,
456
+ pos = index_name_pos(the_repository->index, p->two->path,
457
strlen(p->two->path));
458
459
/*
@@ -465,10 +464,10 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)
464
* path, but left it out of the working tree, then clear the
465
* SKIP_WORKTREE bit and write it to the working tree.
466
*/
468
- if (pos >= 0 && ce_skip_worktree(the_index.cache[pos])) {
467
+ if (pos >= 0 && ce_skip_worktree(the_repository->index->cache[pos])) {
468
struct stat st;
469
471
- ce = the_index.cache[pos];
470
+ ce = the_repository->index->cache[pos];
471
if (!lstat(ce->name, &st)) {
472
/* Conflicting path present; relocate it */
473
struct strbuf new_path = STRBUF_INIT;
@@ -504,12 +503,12 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)
503
if (pos < 0)
504
option = ADD_CACHE_OK_TO_ADD;
505
507
- ce = make_cache_entry(&the_index,
506
+ ce = make_cache_entry(the_repository->index,
507
p->one->mode,
508
&p->one->oid,
509
p->one->path,
510
0, 0);
512
- add_index_entry(&the_index, ce, option);
511
+ add_index_entry(the_repository->index, ce, option);
512
}
513
}
514
diff_flush(&diff_opts);
@@ -518,7 +517,7 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)
517
* Step 4: write the new index to disk
518
*/
519
repo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);
521
- if (write_locked_index(&the_index, &lock,
520
+ if (write_locked_index(the_repository->index, &lock,
521
COMMIT_LOCK | SKIP_IF_UNCHANGED))
522
die(_("could not write index"));
523
}
@@ -539,7 +538,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
538
NULL, NULL, NULL))
539
return error(_("could not write index"));
540
542
- if (write_index_as_tree(&c_tree, &the_index, get_index_file(), 0,
541
+ if (write_index_as_tree(&c_tree, the_repository->index, get_index_file(), 0,
542
NULL))
543
return error(_("cannot apply a stash in the middle of a merge"));
544
@@ -562,14 +561,14 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
561
return error(_("conflicts in index. "
562
"Try without --index."));
563
565
- discard_index(&the_index);
564
+ discard_index(the_repository->index);
565
repo_read_index(the_repository);
567
- if (write_index_as_tree(&index_tree, &the_index,
566
+ if (write_index_as_tree(&index_tree, the_repository->index,
567
get_index_file(), 0, NULL))
568
return error(_("could not save index tree"));
569
570
reset_head();
572
- discard_index(&the_index);
571
+ discard_index(the_repository->index);
572
repo_read_index(the_repository);
573
}
574
}
@@ -875,8 +874,8 @@ static void diff_include_untracked(const struct stash_info *info, struct diff_op
874
}
875
876
unpack_tree_opt.head_idx = -1;
878
- unpack_tree_opt.src_index = &the_index;
879
- unpack_tree_opt.dst_index = &the_index;
877
+ unpack_tree_opt.src_index = the_repository->index;
878
+ unpack_tree_opt.dst_index = the_repository->index;
879
unpack_tree_opt.merge = 1;
880
unpack_tree_opt.fn = stash_worktree_untracked_merge;
881
@@ -1395,7 +1394,7 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b
1394
1395
strbuf_addf(&commit_tree_label, "index on %s\n", msg.buf);
1396
commit_list_insert(head_commit, &parents);
1398
- if (write_index_as_tree(&info->i_tree, &the_index, get_index_file(), 0,
1397
+ if (write_index_as_tree(&info->i_tree, the_repository->index, get_index_file(), 0,
1398
NULL) ||
1399
commit_tree(commit_tree_label.buf, commit_tree_label.len,
1400
&info->i_tree, parents, &info->i_commit, NULL, NULL)) {
@@ -1540,9 +1539,9 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
1539
char *ps_matched = xcalloc(ps->nr, 1);
1540
1541
/* TODO: audit for interaction with sparse-index. */
1543
- ensure_full_index(&the_index);
1544
- for (i = 0; i < the_index.cache_nr; i++)
1545
- ce_path_match(&the_index, the_index.cache[i], ps,
1542
+ ensure_full_index(the_repository->index);
1543
+ for (i = 0; i < the_repository->index->cache_nr; i++)
1544
+ ce_path_match(the_repository->index, the_repository->index->cache[i], ps,
1545
ps_matched);
1546
1547
if (report_path_error(ps_matched, ps)) {
@@ -1612,7 +1611,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
1611
goto done;
1612
}
1613
}
1615
- discard_index(&the_index);
1614
+ discard_index(the_repository->index);
1615
if (ps->nr) {
1616
struct child_process cp_add = CHILD_PROCESS_INIT;
1617
struct child_process cp_diff = CHILD_PROCESS_INIT;
builtin/submodule--helper.c
+10
-11
@@ -1,4 +1,3 @@
1
-#define USE_THE_INDEX_VARIABLE
1
#include "builtin.h"
2
#include "abspath.h"
3
#include "environment.h"
@@ -207,18 +206,18 @@ static int module_list_compute(const char **argv,
206
if (repo_read_index(the_repository) < 0)
207
die(_("index file corrupt"));
208
210
- for (i = 0; i < the_index.cache_nr; i++) {
211
- const struct cache_entry *ce = the_index.cache[i];
209
+ for (i = 0; i < the_repository->index->cache_nr; i++) {
210
+ const struct cache_entry *ce = the_repository->index->cache[i];
211
213
- if (!match_pathspec(&the_index, pathspec, ce->name, ce_namelen(ce),
212
+ if (!match_pathspec(the_repository->index, pathspec, ce->name, ce_namelen(ce),
213
0, ps_matched, 1) ||
214
!S_ISGITLINK(ce->ce_mode))
215
continue;
216
217
ALLOC_GROW(list->entries, list->nr + 1, list->alloc);
218
list->entries[list->nr++] = ce;
220
- while (i + 1 < the_index.cache_nr &&
221
- !strcmp(ce->name, the_index.cache[i + 1]->name))
219
+ while (i + 1 < the_repository->index->cache_nr &&
220
+ !strcmp(ce->name, the_repository->index->cache[i + 1]->name))
221
/*
222
* Skip entries with the same name in different stages
223
* to make sure an entry is returned only once.
@@ -907,7 +906,7 @@ static void generate_submodule_summary(struct summary_cb *info,
906
int fd = open(p->sm_path, O_RDONLY);
907
908
if (fd < 0 || fstat(fd, &st) < 0 ||
910
- index_fd(&the_index, &p->oid_dst, fd, &st, OBJ_BLOB,
909
+ index_fd(the_repository->index, &p->oid_dst, fd, &st, OBJ_BLOB,
910
p->sm_path, 0))
911
error(_("couldn't hash object from '%s'"), p->sm_path);
912
} else {
@@ -3243,21 +3242,21 @@ static void die_on_index_match(const char *path, int force)
3242
char *ps_matched = xcalloc(ps.nr, 1);
3243
3244
/* TODO: audit for interaction with sparse-index. */
3246
- ensure_full_index(&the_index);
3245
+ ensure_full_index(the_repository->index);
3246
3247
/*
3248
* Since there is only one pathspec, we just need to
3249
* check ps_matched[0] to know if a cache entry matched.
3250
*/
3252
- for (i = 0; i < the_index.cache_nr; i++) {
3253
- ce_path_match(&the_index, the_index.cache[i], &ps,
3251
+ for (i = 0; i < the_repository->index->cache_nr; i++) {
3252
+ ce_path_match(the_repository->index, the_repository->index->cache[i], &ps,
3253
ps_matched);
3254
3255
if (ps_matched[0]) {
3256
if (!force)
3257
die(_("'%s' already exists in the index"),
3258
path);
3260
- if (!S_ISGITLINK(the_index.cache[i]->ce_mode))
3259
+ if (!S_ISGITLINK(the_repository->index->cache[i]->ce_mode))
3260
die(_("'%s' already exists in the index "
3261
"and is not a submodule"), path);
3262
break;
builtin/update-index.c
+61
-61
@@ -3,7 +3,7 @@
3
*
4
* Copyright (C) Linus Torvalds, 2005
5
*/
6
-#define USE_THE_INDEX_VARIABLE
6
+
7
#include "builtin.h"
8
#include "bulk-checkin.h"
9
#include "config.h"
@@ -247,16 +247,16 @@ done:
247
static int mark_ce_flags(const char *path, int flag, int mark)
248
{
249
int namelen = strlen(path);
250
- int pos = index_name_pos(&the_index, path, namelen);
250
+ int pos = index_name_pos(the_repository->index, path, namelen);
251
if (0 <= pos) {
252
- mark_fsmonitor_invalid(&the_index, the_index.cache[pos]);
252
+ mark_fsmonitor_invalid(the_repository->index, the_repository->index->cache[pos]);
253
if (mark)
254
- the_index.cache[pos]->ce_flags |= flag;
254
+ the_repository->index->cache[pos]->ce_flags |= flag;
255
else
256
- the_index.cache[pos]->ce_flags &= ~flag;
257
- the_index.cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;
258
- cache_tree_invalidate_path(&the_index, path);
259
- the_index.cache_changed |= CE_ENTRY_CHANGED;
256
+ the_repository->index->cache[pos]->ce_flags &= ~flag;
257
+ the_repository->index->cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;
258
+ cache_tree_invalidate_path(the_repository->index, path);
259
+ the_repository->index->cache_changed |= CE_ENTRY_CHANGED;
260
return 0;
261
}
262
return -1;
@@ -266,7 +266,7 @@ static int remove_one_path(const char *path)
266
{
267
if (!allow_remove)
268
return error("%s: does not exist and --remove not passed", path);
269
- if (remove_file_from_index(&the_index, path))
269
+ if (remove_file_from_index(the_repository->index, path))
270
return error("%s: cannot remove from the index", path);
271
return 0;
272
}
@@ -291,24 +291,24 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len
291
struct cache_entry *ce;
292
293
/* Was the old index entry already up-to-date? */
294
- if (old && !ce_stage(old) && !ie_match_stat(&the_index, old, st, 0))
294
+ if (old && !ce_stage(old) && !ie_match_stat(the_repository->index, old, st, 0))
295
return 0;
296
297
- ce = make_empty_cache_entry(&the_index, len);
297
+ ce = make_empty_cache_entry(the_repository->index, len);
298
memcpy(ce->name, path, len);
299
ce->ce_flags = create_ce_flags(0);
300
ce->ce_namelen = len;
301
- fill_stat_cache_info(&the_index, ce, st);
301
+ fill_stat_cache_info(the_repository->index, ce, st);
302
ce->ce_mode = ce_mode_from_stat(old, st->st_mode);
303
304
- if (index_path(&the_index, &ce->oid, path, st,
304
+ if (index_path(the_repository->index, &ce->oid, path, st,
305
info_only ? 0 : HASH_WRITE_OBJECT)) {
306
discard_cache_entry(ce);
307
return -1;
308
}
309
option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
310
option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
311
- if (add_index_entry(&the_index, ce, option)) {
311
+ if (add_index_entry(the_repository->index, ce, option)) {
312
discard_cache_entry(ce);
313
return error("%s: cannot add to the index - missing --add option?", path);
314
}
@@ -341,11 +341,11 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len
341
static int process_directory(const char *path, int len, struct stat *st)
342
{
343
struct object_id oid;
344
- int pos = index_name_pos(&the_index, path, len);
344
+ int pos = index_name_pos(the_repository->index, path, len);
345
346
/* Exact match: file or existing gitlink */
347
if (pos >= 0) {
348
- const struct cache_entry *ce = the_index.cache[pos];
348
+ const struct cache_entry *ce = the_repository->index->cache[pos];
349
if (S_ISGITLINK(ce->ce_mode)) {
350
351
/* Do nothing to the index if there is no HEAD! */
@@ -360,8 +360,8 @@ static int process_directory(const char *path, int len, struct stat *st)
360
361
/* Inexact match: is there perhaps a subdirectory match? */
362
pos = -pos-1;
363
- while (pos < the_index.cache_nr) {
364
- const struct cache_entry *ce = the_index.cache[pos++];
363
+ while (pos < the_repository->index->cache_nr) {
364
+ const struct cache_entry *ce = the_repository->index->cache[pos++];
365
366
if (strncmp(ce->name, path, len))
367
break;
@@ -391,8 +391,8 @@ static int process_path(const char *path, struct stat *st, int stat_errno)
391
if (has_symlink_leading_path(path, len))
392
return error("'%s' is beyond a symbolic link", path);
393
394
- pos = index_name_pos(&the_index, path, len);
395
- ce = pos < 0 ? NULL : the_index.cache[pos];
394
+ pos = index_name_pos(the_repository->index, path, len);
395
+ ce = pos < 0 ? NULL : the_repository->index->cache[pos];
396
if (ce && ce_skip_worktree(ce)) {
397
/*
398
* working directory version is assumed "good"
@@ -400,7 +400,7 @@ static int process_path(const char *path, struct stat *st, int stat_errno)
400
* On the other hand, removing it from index should work
401
*/
402
if (!ignore_skip_worktree_entries && allow_remove &&
403
- remove_file_from_index(&the_index, path))
403
+ remove_file_from_index(the_repository->index, path))
404
return error("%s: cannot remove from the index", path);
405
return 0;
406
}
@@ -428,7 +428,7 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid,
428
return error("Invalid path '%s'", path);
429
430
len = strlen(path);
431
- ce = make_empty_cache_entry(&the_index, len);
431
+ ce = make_empty_cache_entry(the_repository->index, len);
432
433
oidcpy(&ce->oid, oid);
434
memcpy(ce->name, path, len);
@@ -439,7 +439,7 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid,
439
ce->ce_flags |= CE_VALID;
440
option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
441
option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
442
- if (add_index_entry(&the_index, ce, option))
442
+ if (add_index_entry(the_repository->index, ce, option))
443
return error("%s: cannot add to the index - missing --add option?",
444
path);
445
report("add '%s'", path);
@@ -451,11 +451,11 @@ static void chmod_path(char flip, const char *path)
451
int pos;
452
struct cache_entry *ce;
453
454
- pos = index_name_pos(&the_index, path, strlen(path));
454
+ pos = index_name_pos(the_repository->index, path, strlen(path));
455
if (pos < 0)
456
goto fail;
457
- ce = the_index.cache[pos];
458
- if (chmod_index_entry(&the_index, ce, flip) < 0)
457
+ ce = the_repository->index->cache[pos];
458
+ if (chmod_index_entry(the_repository->index, ce, flip) < 0)
459
goto fail;
460
461
report("chmod %cx '%s'", flip, path);
@@ -498,7 +498,7 @@ static void update_one(const char *path)
498
}
499
500
if (force_remove) {
501
- if (remove_file_from_index(&the_index, path))
501
+ if (remove_file_from_index(the_repository->index, path))
502
die("git update-index: unable to remove %s", path);
503
report("remove '%s'", path);
504
return;
@@ -581,7 +581,7 @@ static void read_index_info(int nul_term_line)
581
582
if (!mode) {
583
/* mode == 0 means there is no such path -- remove */
584
- if (remove_file_from_index(&the_index, path_name))
584
+ if (remove_file_from_index(the_repository->index, path_name))
585
die("git update-index: unable to remove %s",
586
ptr);
587
}
@@ -622,12 +622,12 @@ static struct cache_entry *read_one_ent(const char *which,
622
error("%s: not in %s branch.", path, which);
623
return NULL;
624
}
625
- if (!the_index.sparse_index && mode == S_IFDIR) {
625
+ if (!the_repository->index->sparse_index && mode == S_IFDIR) {
626
if (which)
627
error("%s: not a blob in %s branch.", path, which);
628
return NULL;
629
}
630
- ce = make_empty_cache_entry(&the_index, namelen);
630
+ ce = make_empty_cache_entry(the_repository->index, namelen);
631
632
oidcpy(&ce->oid, &oid);
633
memcpy(ce->name, path, namelen);
@@ -642,12 +642,12 @@ static int unresolve_one(const char *path)
642
struct string_list_item *item;
643
int res = 0;
644
645
- if (!the_index.resolve_undo)
645
+ if (!the_repository->index->resolve_undo)
646
return res;
647
- item = string_list_lookup(the_index.resolve_undo, path);
647
+ item = string_list_lookup(the_repository->index->resolve_undo, path);
648
if (!item)
649
return res; /* no resolve-undo record for the path */
650
- res = unmerge_index_entry(&the_index, path, item->util, 0);
650
+ res = unmerge_index_entry(the_repository->index, path, item->util, 0);
651
FREE_AND_NULL(item->util);
652
return res;
653
}
@@ -688,13 +688,13 @@ static int do_reupdate(const char **paths,
688
*/
689
has_head = 0;
690
redo:
691
- for (pos = 0; pos < the_index.cache_nr; pos++) {
692
- const struct cache_entry *ce = the_index.cache[pos];
691
+ for (pos = 0; pos < the_repository->index->cache_nr; pos++) {
692
+ const struct cache_entry *ce = the_repository->index->cache[pos];
693
struct cache_entry *old = NULL;
694
int save_nr;
695
char *path;
696
697
- if (ce_stage(ce) || !ce_path_match(&the_index, ce, &pathspec, NULL))
697
+ if (ce_stage(ce) || !ce_path_match(the_repository->index, ce, &pathspec, NULL))
698
continue;
699
if (has_head)
700
old = read_one_ent(NULL, &head_oid,
@@ -710,7 +710,7 @@ static int do_reupdate(const char **paths,
710
* to process each path individually
711
*/
712
if (S_ISSPARSEDIR(ce->ce_mode)) {
713
- ensure_full_index(&the_index);
713
+ ensure_full_index(the_repository->index);
714
goto redo;
715
}
716
@@ -718,12 +718,12 @@ static int do_reupdate(const char **paths,
718
* path anymore, in which case, under 'allow_remove',
719
* or worse yet 'allow_replace', active_nr may decrease.
720
*/
721
- save_nr = the_index.cache_nr;
721
+ save_nr = the_repository->index->cache_nr;
722
path = xstrdup(ce->name);
723
update_one(path);
724
free(path);
725
discard_cache_entry(old);
726
- if (save_nr != the_index.cache_nr)
726
+ if (save_nr != the_repository->index->cache_nr)
727
goto redo;
728
}
729
clear_pathspec(&pathspec);
@@ -739,9 +739,9 @@ static int refresh(struct refresh_params *o, unsigned int flag)
739
{
740
setup_work_tree();
741
repo_read_index(the_repository);
742
- *o->has_errors |= refresh_index(&the_index, o->flags | flag, NULL,
742
+ *o->has_errors |= refresh_index(the_repository->index, o->flags | flag, NULL,
743
NULL, NULL);
744
- if (has_racy_timestamp(&the_index)) {
744
+ if (has_racy_timestamp(the_repository->index)) {
745
/*
746
* Even if nothing else has changed, updating the file
747
* increases the chance that racy timestamps become
@@ -750,7 +750,7 @@ static int refresh(struct refresh_params *o, unsigned int flag)
750
* refresh_index() as these are no actual errors.
751
* cmd_status() does the same.
752
*/
753
- the_index.cache_changed |= SOMETHING_CHANGED;
753
+ the_repository->index->cache_changed |= SOMETHING_CHANGED;
754
}
755
return 0;
756
}
@@ -787,7 +787,7 @@ static int resolve_undo_clear_callback(const struct option *opt UNUSED,
787
{
788
BUG_ON_OPT_NEG(unset);
789
BUG_ON_OPT_ARG(arg);
790
- resolve_undo_clear_index(&the_index);
790
+ resolve_undo_clear_index(the_repository->index);
791
return 0;
792
}
793
@@ -888,7 +888,7 @@ static enum parse_opt_result unresolve_callback(
888
*has_errors = do_unresolve(ctx->argc, ctx->argv,
889
prefix, prefix ? strlen(prefix) : 0);
890
if (*has_errors)
891
- the_index.cache_changed = 0;
891
+ the_repository->index->cache_changed = 0;
892
893
ctx->argv += ctx->argc - 1;
894
ctx->argc = 1;
@@ -909,7 +909,7 @@ static enum parse_opt_result reupdate_callback(
909
setup_work_tree();
910
*has_errors = do_reupdate(ctx->argv + 1, prefix);
911
if (*has_errors)
912
- the_index.cache_changed = 0;
912
+ the_repository->index->cache_changed = 0;
913
914
ctx->argv += ctx->argc - 1;
915
ctx->argc = 1;
@@ -1056,7 +1056,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1056
if (entries < 0)
1057
die("cache corrupted");
1058
1059
- the_index.updated_skipworktree = 1;
1059
+ the_repository->index->updated_skipworktree = 1;
1060
1061
/*
1062
* Custom copy of parse_options() because we want to handle
@@ -1111,18 +1111,18 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1111
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
1112
if (preferred_index_format) {
1113
if (preferred_index_format < 0) {
1114
- printf(_("%d\n"), the_index.version);
1114
+ printf(_("%d\n"), the_repository->index->version);
1115
} else if (preferred_index_format < INDEX_FORMAT_LB ||
1116
INDEX_FORMAT_UB < preferred_index_format) {
1117
die("index-version %d not in range: %d..%d",
1118
preferred_index_format,
1119
INDEX_FORMAT_LB, INDEX_FORMAT_UB);
1120
} else {
1121
- if (the_index.version != preferred_index_format)
1122
- the_index.cache_changed |= SOMETHING_CHANGED;
1121
+ if (the_repository->index->version != preferred_index_format)
1122
+ the_repository->index->cache_changed |= SOMETHING_CHANGED;
1123
report(_("index-version: was %d, set to %d"),
1124
- the_index.version, preferred_index_format);
1125
- the_index.version = preferred_index_format;
1124
+ the_repository->index->version, preferred_index_format);
1125
+ the_repository->index->version = preferred_index_format;
1126
}
1127
}
1128
@@ -1159,16 +1159,16 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1159
warning(_("core.splitIndex is set to false; "
1160
"remove or change it, if you really want to "
1161
"enable split index"));
1162
- if (the_index.split_index)
1163
- the_index.cache_changed |= SPLIT_INDEX_ORDERED;
1162
+ if (the_repository->index->split_index)
1163
+ the_repository->index->cache_changed |= SPLIT_INDEX_ORDERED;
1164
else
1165
- add_split_index(&the_index);
1165
+ add_split_index(the_repository->index);
1166
} else if (!split_index) {
1167
if (git_config_get_split_index() == 1)
1168
warning(_("core.splitIndex is set to true; "
1169
"remove or change it, if you really want to "
1170
"disable split index"));
1171
- remove_split_index(&the_index);
1171
+ remove_split_index(the_repository->index);
1172
}
1173
1174
prepare_repo_settings(r);
@@ -1180,7 +1180,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1180
warning(_("core.untrackedCache is set to true; "
1181
"remove or change it, if you really want to "
1182
"disable the untracked cache"));
1183
- remove_untracked_cache(&the_index);
1183
+ remove_untracked_cache(the_repository->index);
1184
report(_("Untracked cache disabled"));
1185
break;
1186
case UC_TEST:
@@ -1192,7 +1192,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1192
warning(_("core.untrackedCache is set to false; "
1193
"remove or change it, if you really want to "
1194
"enable the untracked cache"));
1195
- add_untracked_cache(&the_index);
1195
+ add_untracked_cache(the_repository->index);
1196
report(_("Untracked cache enabled for '%s'"), get_git_work_tree());
1197
break;
1198
default:
@@ -1222,7 +1222,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1222
"set it if you really want to "
1223
"enable fsmonitor"));
1224
}
1225
- add_fsmonitor(&the_index);
1225
+ add_fsmonitor(the_repository->index);
1226
report(_("fsmonitor enabled"));
1227
} else if (!fsmonitor) {
1228
enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r);
@@ -1230,17 +1230,17 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1230
warning(_("core.fsmonitor is set; "
1231
"remove it if you really want to "
1232
"disable fsmonitor"));
1233
- remove_fsmonitor(&the_index);
1233
+ remove_fsmonitor(the_repository->index);
1234
report(_("fsmonitor disabled"));
1235
}
1236
1237
- if (the_index.cache_changed || force_write) {
1237
+ if (the_repository->index->cache_changed || force_write) {
1238
if (newfd < 0) {
1239
if (refresh_args.flags & REFRESH_QUIET)
1240
exit(128);
1241
unable_to_lock_die(get_index_file(), lock_error);
1242
}
1243
- if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
1243
+ if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
1244
die("Unable to write new index file");
1245
}
1246
builtin/write-tree.c
+3
-3
@@ -3,7 +3,7 @@
3
*
4
* Copyright (C) Linus Torvalds, 2005
5
*/
6
-#define USE_THE_INDEX_VARIABLE
6
+
7
#include "builtin.h"
8
#include "config.h"
9
#include "environment.h"
@@ -44,8 +44,8 @@ int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
44
prepare_repo_settings(the_repository);
45
the_repository->settings.command_requires_full_index = 0;
46
47
- ret = write_index_as_tree(&oid, &the_index, get_index_file(), flags,
48
- tree_prefix);
47
+ ret = write_index_as_tree(&oid, the_repository->index, get_index_file(),
48
+ flags, tree_prefix);
49
switch (ret) {
50
case 0:
51
printf("%s\n", oid_to_hex(&oid));