Skip to content

Commit 041df69

Browse files
committed
Merge branch 'ab/fewer-the-index-macros'
Progress on removing 'the_index' convenience wrappers. * ab/fewer-the-index-macros: cocci: apply "pending" index-compatibility to some "builtin/*.c" cache.h & test-tool.h: add & use "USE_THE_INDEX_VARIABLE" {builtin/*,repository}.c: add & use "USE_THE_INDEX_VARIABLE" cocci: apply "pending" index-compatibility to "t/helper/*.c" cocci & cache.h: apply variable section of "pending" index-compatibility cocci & cache.h: apply a selection of "pending" index-compatibility cocci: add a index-compatibility.pending.cocci read-cache API & users: make discard_index() return void cocci & cache.h: remove rarely used "the_index" compat macros builtin/{grep,log}.: don't define "USE_THE_INDEX_COMPATIBILITY_MACROS" cache.h: remove unused "the_index" compat macros
2 parents 613999c + 07047d6 commit 041df69

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+532
-366
lines changed

add-interactive.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,8 @@ static int get_modified_files(struct repository *r,
530530
struct collection_status s = { 0 };
531531
int i;
532532

533-
if (discard_index(r->index) < 0 ||
534-
repo_read_index_preload(r, ps, 0) < 0)
533+
discard_index(r->index);
534+
if (repo_read_index_preload(r, ps, 0) < 0)
535535
return error(_("could not read index"));
536536

537537
prefix_item_list_clear(files);
@@ -1156,8 +1156,8 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
11561156
_("staged"), _("unstaged"), _("path"));
11571157
opts.list_opts.header = header.buf;
11581158

1159-
if (discard_index(r->index) < 0 ||
1160-
repo_read_index(r) < 0 ||
1159+
discard_index(r->index);
1160+
if (repo_read_index(r) < 0 ||
11611161
repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,
11621162
NULL, NULL, NULL) < 0)
11631163
warning(_("could not refresh index"));

add-patch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,8 @@ int run_add_p(struct repository *r, enum add_p_mode mode,
17501750
s.mode = &patch_mode_add;
17511751
s.revision = revision;
17521752

1753-
if (discard_index(r->index) < 0 || repo_read_index(r) < 0 ||
1753+
discard_index(r->index);
1754+
if (repo_read_index(r) < 0 ||
17541755
(!s.mode->index_only &&
17551756
repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1,
17561757
NULL, NULL, NULL) < 0) ||

builtin/add.c

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

45-
for (i = 0; i < active_nr; i++) {
46-
struct cache_entry *ce = active_cache[i];
45+
for (i = 0; i < the_index.cache_nr; i++) {
46+
struct cache_entry *ce = the_index.cache[i];
4747
int err;
4848

4949
if (!include_sparse &&
@@ -55,7 +55,7 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
5555
continue;
5656

5757
if (!show_only)
58-
err = chmod_cache_entry(ce, flip);
58+
err = chmod_index_entry(&the_index, ce, flip);
5959
else
6060
err = S_ISREG(ce->ce_mode) ? 0 : -1;
6161

@@ -159,8 +159,8 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
159159
{
160160
int i, retval = 0;
161161

162-
for (i = 0; i < active_nr; i++) {
163-
struct cache_entry *ce = active_cache[i];
162+
for (i = 0; i < the_index.cache_nr; i++) {
163+
struct cache_entry *ce = the_index.cache[i];
164164

165165
if (!include_sparse &&
166166
(ce_skip_worktree(ce) ||
@@ -172,7 +172,8 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
172172
continue; /* do not touch non blobs */
173173
if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
174174
continue;
175-
retval |= add_file_to_cache(ce->name, flags | ADD_CACHE_RENORMALIZE);
175+
retval |= add_file_to_index(&the_index, ce->name,
176+
flags | ADD_CACHE_RENORMALIZE);
176177
}
177178

178179
return retval;
@@ -311,7 +312,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
311312

312313
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
313314

314-
if (read_cache() < 0)
315+
if (repo_read_index(the_repository) < 0)
315316
die(_("Could not read the index"));
316317

317318
repo_init_revisions(the_repository, &rev, prefix);
@@ -543,7 +544,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
543544
prepare_repo_settings(the_repository);
544545
the_repository->settings.command_requires_full_index = 0;
545546

546-
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
547+
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
547548

548549
/*
549550
* Check the "pathspec '%s' did not match any files" block
@@ -586,7 +587,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
586587
(!(addremove || take_worktree_changes)
587588
? ADD_CACHE_IGNORE_REMOVAL : 0));
588589

589-
if (read_cache_preload(&pathspec) < 0)
590+
if (repo_read_index_preload(the_repository, &pathspec, 0) < 0)
590591
die(_("index file corrupt"));
591592

592593
die_in_unpopulated_submodule(&the_index, prefix);

builtin/am.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,8 +1519,8 @@ static int run_apply(const struct am_state *state, const char *index_file)
15191519

15201520
if (index_file) {
15211521
/* Reload index as apply_all_patches() will have modified it. */
1522-
discard_cache();
1523-
read_cache_from(index_file);
1522+
discard_index(&the_index);
1523+
read_index_from(&the_index, index_file, get_git_dir());
15241524
}
15251525

15261526
return 0;
@@ -1562,8 +1562,8 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
15621562
if (build_fake_ancestor(state, index_path))
15631563
return error("could not build fake ancestor");
15641564

1565-
discard_cache();
1566-
read_cache_from(index_path);
1565+
discard_index(&the_index);
1566+
read_index_from(&the_index, index_path, get_git_dir());
15671567

15681568
if (write_index_as_tree(&orig_tree, &the_index, index_path, 0, NULL))
15691569
return error(_("Repository lacks necessary blobs to fall back on 3-way merge."));
@@ -1596,8 +1596,8 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
15961596

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

1599-
discard_cache();
1600-
read_cache();
1599+
discard_index(&the_index);
1600+
repo_read_index(the_repository);
16011601

16021602
/*
16031603
* This is not so wrong. Depending on which base we picked, orig_tree
@@ -1781,7 +1781,8 @@ static void am_run(struct am_state *state, int resume)
17811781

17821782
unlink(am_path(state, "dirtyindex"));
17831783

1784-
if (refresh_and_write_cache(REFRESH_QUIET, 0, 0) < 0)
1784+
if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,
1785+
NULL, NULL, NULL) < 0)
17851786
die(_("unable to write index file"));
17861787

17871788
if (repo_index_has_changes(the_repository, NULL, &sb)) {
@@ -1930,7 +1931,7 @@ static void am_resolve(struct am_state *state, int allow_empty)
19301931
}
19311932
}
19321933

1933-
if (unmerged_cache()) {
1934+
if (unmerged_index(&the_index)) {
19341935
printf_ln(_("You still have unmerged paths in your index.\n"
19351936
"You should 'git add' each file with resolved conflicts to mark them as such.\n"
19361937
"You might run `git rm` on a file to accept \"deleted by them\" for it."));
@@ -1967,9 +1968,9 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)
19671968
if (parse_tree(head) || parse_tree(remote))
19681969
return -1;
19691970

1970-
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
1971+
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
19711972

1972-
refresh_cache(REFRESH_QUIET);
1973+
refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
19731974

19741975
memset(&opts, 0, sizeof(opts));
19751976
opts.head_idx = 1;
@@ -2007,7 +2008,7 @@ static int merge_tree(struct tree *tree)
20072008
if (parse_tree(tree))
20082009
return -1;
20092010

2010-
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
2011+
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
20112012

20122013
memset(&opts, 0, sizeof(opts));
20132014
opts.head_idx = 1;
@@ -2045,7 +2046,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
20452046
if (!remote_tree)
20462047
return error(_("Could not parse object '%s'."), oid_to_hex(remote));
20472048

2048-
read_cache_unmerged();
2049+
repo_read_index_unmerged(the_repository);
20492050

20502051
if (fast_forward_to(head_tree, head_tree, 1))
20512052
return -1;

builtin/cat-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (C) Linus Torvalds, 2005
55
*/
6-
#define USE_THE_INDEX_COMPATIBILITY_MACROS
6+
#define USE_THE_INDEX_VARIABLE
77
#include "cache.h"
88
#include "config.h"
99
#include "builtin.h"

builtin/check-attr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#define USE_THE_INDEX_COMPATIBILITY_MACROS
1+
#define USE_THE_INDEX_VARIABLE
22
#include "builtin.h"
33
#include "cache.h"
44
#include "config.h"
@@ -115,7 +115,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
115115
argc = parse_options(argc, argv, prefix, check_attr_options,
116116
check_attr_usage, PARSE_OPT_KEEP_DASHDASH);
117117

118-
if (read_cache() < 0) {
118+
if (repo_read_index(the_repository) < 0) {
119119
die("invalid cache");
120120
}
121121

builtin/check-ignore.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#define USE_THE_INDEX_COMPATIBILITY_MACROS
1+
#define USE_THE_INDEX_VARIABLE
22
#include "builtin.h"
33
#include "cache.h"
44
#include "config.h"
@@ -179,7 +179,7 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix)
179179
die(_("--non-matching is only valid with --verbose"));
180180

181181
/* read_cache() is only necessary so we can watch out for submodules. */
182-
if (!no_index && read_cache() < 0)
182+
if (!no_index && repo_read_index(the_repository) < 0)
183183
die(_("index file corrupt"));
184184

185185
setup_standard_excludes(&dir);

builtin/checkout-index.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright (C) 2005 Linus Torvalds
55
*
66
*/
7-
#define USE_THE_INDEX_COMPATIBILITY_MACROS
7+
#define USE_THE_INDEX_VARIABLE
88
#include "builtin.h"
99
#include "config.h"
1010
#include "dir.h"
@@ -65,7 +65,7 @@ static void write_tempfile_record(const char *name, const char *prefix)
6565
static int checkout_file(const char *name, const char *prefix)
6666
{
6767
int namelen = strlen(name);
68-
int pos = cache_name_pos(name, namelen);
68+
int pos = index_name_pos(&the_index, name, namelen);
6969
int has_same_name = 0;
7070
int is_file = 0;
7171
int is_skipped = 1;
@@ -75,8 +75,8 @@ static int checkout_file(const char *name, const char *prefix)
7575
if (pos < 0)
7676
pos = -pos - 1;
7777

78-
while (pos < active_nr) {
79-
struct cache_entry *ce = active_cache[pos];
78+
while (pos < the_index.cache_nr) {
79+
struct cache_entry *ce = the_index.cache[pos];
8080
if (ce_namelen(ce) != namelen ||
8181
memcmp(ce->name, name, namelen))
8282
break;
@@ -136,8 +136,8 @@ static int checkout_all(const char *prefix, int prefix_length)
136136
int i, errs = 0;
137137
struct cache_entry *last_ce = NULL;
138138

139-
for (i = 0; i < active_nr ; i++) {
140-
struct cache_entry *ce = active_cache[i];
139+
for (i = 0; i < the_index.cache_nr ; i++) {
140+
struct cache_entry *ce = the_index.cache[i];
141141

142142
if (S_ISSPARSEDIR(ce->ce_mode)) {
143143
if (!ce_skip_worktree(ce))
@@ -151,7 +151,7 @@ static int checkout_all(const char *prefix, int prefix_length)
151151
*/
152152
if (ignore_skip_worktree) {
153153
ensure_full_index(&the_index);
154-
ce = active_cache[i];
154+
ce = the_index.cache[i];
155155
}
156156
}
157157

@@ -249,7 +249,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
249249
prepare_repo_settings(the_repository);
250250
the_repository->settings.command_requires_full_index = 0;
251251

252-
if (read_cache() < 0) {
252+
if (repo_read_index(the_repository) < 0) {
253253
die("invalid cache");
254254
}
255255

@@ -270,7 +270,8 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
270270
if (index_opt && !state.base_dir_len && !to_tempfile) {
271271
state.refresh_cache = 1;
272272
state.istate = &the_index;
273-
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
273+
repo_hold_locked_index(the_repository, &lock_file,
274+
LOCK_DIE_ON_ERROR);
274275
}
275276

276277
get_parallel_checkout_configs(&pc_workers, &pc_threshold);

0 commit comments

Comments
 (0)