Skip to content

Commit 07047d6

Browse files
avargitster
authored andcommitted
cocci: apply "pending" index-compatibility to some "builtin/*.c"
Apply "index-compatibility.pending.cocci" rule to "builtin/*", but exclude those where we conflict with in-flight changes. As a result some of them end up using only "the_index", so let's have them use the more narrow "USE_THE_INDEX_VARIABLE" rather than "USE_THE_INDEX_COMPATIBILITY_MACROS". Manual changes not made by coccinelle, that were squashed in: * Whitespace-wrap argument lists for repo_hold_locked_index(), repo_read_index_preload() and repo_refresh_and_write_index(), in cases where the line became too long after the transformation. * Change "refresh_cache()" to "refresh_index()" in a comment in "builtin/update-index.c". * For those whose call was followed by perror("<macro-name>"), change it to perror("<function-name>"), referring to the new function. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bdafeae commit 07047d6

30 files changed

+213
-202
lines changed

builtin/add.c

Lines changed: 4 additions & 4 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"
@@ -312,7 +312,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
312312

313313
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
314314

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

318318
repo_init_revisions(the_repository, &rev, prefix);
@@ -544,7 +544,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
544544
prepare_repo_settings(the_repository);
545545
the_repository->settings.command_requires_full_index = 0;
546546

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

549549
/*
550550
* Check the "pathspec '%s' did not match any files" block
@@ -587,7 +587,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
587587
(!(addremove || take_worktree_changes)
588588
? ADD_CACHE_IGNORE_REMOVAL : 0));
589589

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

593593
die_in_unpopulated_submodule(&the_index, prefix);

builtin/am.c

Lines changed: 11 additions & 10 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)) {
@@ -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;

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: 5 additions & 4 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;
@@ -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);

builtin/checkout.c

Lines changed: 6 additions & 6 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 "advice.h"
44
#include "blob.h"
@@ -148,7 +148,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
148148
* entry in place. Whether it is UPTODATE or not, checkout_entry will
149149
* do the right thing.
150150
*/
151-
pos = cache_name_pos(ce->name, ce->ce_namelen);
151+
pos = index_name_pos(&the_index, ce->name, ce->ce_namelen);
152152
if (pos >= 0) {
153153
struct cache_entry *old = the_index.cache[pos];
154154
if (ce->ce_mode == old->ce_mode &&
@@ -529,7 +529,7 @@ static int checkout_paths(const struct checkout_opts *opts,
529529
}
530530

531531
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
532-
if (read_cache_preload(&opts->pathspec) < 0)
532+
if (repo_read_index_preload(the_repository, &opts->pathspec, 0) < 0)
533533
return error(_("index file corrupt"));
534534

535535
if (opts->source_tree)
@@ -741,8 +741,8 @@ static int merge_working_tree(const struct checkout_opts *opts,
741741
struct lock_file lock_file = LOCK_INIT;
742742
struct tree *new_tree;
743743

744-
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
745-
if (read_cache_preload(NULL) < 0)
744+
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
745+
if (repo_read_index_preload(the_repository, NULL, 0) < 0)
746746
return error(_("index file corrupt"));
747747

748748
resolve_undo_clear_index(&the_index);
@@ -762,7 +762,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
762762
struct unpack_trees_options topts;
763763
const struct object_id *old_commit_oid;
764764

765-
refresh_cache(REFRESH_QUIET);
765+
refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
766766

767767
if (unmerged_index(&the_index)) {
768768
error(_("you need to resolve your current index first"));

builtin/clean.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Based on git-clean.sh by Pavel Roskin
77
*/
88

9-
#define USE_THE_INDEX_COMPATIBILITY_MACROS
9+
#define USE_THE_INDEX_VARIABLE
1010
#include "builtin.h"
1111
#include "cache.h"
1212
#include "config.h"
@@ -1012,7 +1012,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
10121012
prepare_repo_settings(the_repository);
10131013
the_repository->settings.command_requires_full_index = 0;
10141014

1015-
if (read_cache() < 0)
1015+
if (repo_read_index(the_repository) < 0)
10161016
die(_("index file corrupt"));
10171017

10181018
pl = add_pattern_list(&dir, EXC_CMDL, "--exclude option");

builtin/clone.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Clone a repository into a different directory that does not yet exist.
99
*/
1010

11-
#define USE_THE_INDEX_COMPATIBILITY_MACROS
11+
#define USE_THE_INDEX_VARIABLE
1212
#include "builtin.h"
1313
#include "config.h"
1414
#include "lockfile.h"
@@ -703,7 +703,7 @@ static int checkout(int submodule_progress, int filter_submodules)
703703
/* We need to be in the new work tree for the checkout */
704704
setup_work_tree();
705705

706-
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
706+
repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
707707

708708
memset(&opts, 0, sizeof opts);
709709
opts.update = 1;

builtin/commit.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static void create_base_index(const struct commit *current_head)
316316
struct tree_desc t;
317317

318318
if (!current_head) {
319-
discard_cache();
319+
discard_index(&the_index);
320320
return;
321321
}
322322

@@ -343,7 +343,7 @@ static void refresh_cache_or_die(int refresh_flags)
343343
* refresh_flags contains REFRESH_QUIET, so the only errors
344344
* are for unmerged entries.
345345
*/
346-
if (refresh_cache(refresh_flags | REFRESH_IN_PORCELAIN))
346+
if (refresh_index(&the_index, refresh_flags | REFRESH_IN_PORCELAIN, NULL, NULL, NULL))
347347
die_resolve_conflict("commit");
348348
}
349349

@@ -382,12 +382,13 @@ static const char *prepare_index(const char **argv, const char *prefix,
382382
(!amend || (fixup_message && strcmp(fixup_prefix, "amend"))))))
383383
die(_("No paths with --include/--only does not make sense."));
384384

385-
if (read_cache_preload(&pathspec) < 0)
385+
if (repo_read_index_preload(the_repository, &pathspec, 0) < 0)
386386
die(_("index file corrupt"));
387387

388388
if (interactive) {
389389
char *old_index_env = NULL, *old_repo_index_file;
390-
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
390+
repo_hold_locked_index(the_repository, &index_lock,
391+
LOCK_DIE_ON_ERROR);
391392

392393
refresh_cache_or_die(refresh_flags);
393394

@@ -410,8 +411,9 @@ static const char *prepare_index(const char **argv, const char *prefix,
410411
unsetenv(INDEX_ENVIRONMENT);
411412
FREE_AND_NULL(old_index_env);
412413

413-
discard_cache();
414-
read_cache_from(get_lock_file_path(&index_lock));
414+
discard_index(&the_index);
415+
read_index_from(&the_index, get_lock_file_path(&index_lock),
416+
get_git_dir());
415417
if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {
416418
if (reopen_lock_file(&index_lock) < 0)
417419
die(_("unable to write index file"));
@@ -438,7 +440,8 @@ static const char *prepare_index(const char **argv, const char *prefix,
438440
* (B) on failure, rollback the real index.
439441
*/
440442
if (all || (also && pathspec.nr)) {
441-
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
443+
repo_hold_locked_index(the_repository, &index_lock,
444+
LOCK_DIE_ON_ERROR);
442445
add_files_to_cache(also ? prefix : NULL, &pathspec, 0);
443446
refresh_cache_or_die(refresh_flags);
444447
update_main_cache_tree(WRITE_TREE_SILENT);
@@ -459,7 +462,8 @@ static const char *prepare_index(const char **argv, const char *prefix,
459462
* We still need to refresh the index here.
460463
*/
461464
if (!only && !pathspec.nr) {
462-
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
465+
repo_hold_locked_index(the_repository, &index_lock,
466+
LOCK_DIE_ON_ERROR);
463467
refresh_cache_or_die(refresh_flags);
464468
if (the_index.cache_changed
465469
|| !cache_tree_fully_valid(the_index.cache_tree))
@@ -505,13 +509,13 @@ static const char *prepare_index(const char **argv, const char *prefix,
505509
if (list_paths(&partial, !current_head ? NULL : "HEAD", &pathspec))
506510
exit(1);
507511

508-
discard_cache();
509-
if (read_cache() < 0)
512+
discard_index(&the_index);
513+
if (repo_read_index(the_repository) < 0)
510514
die(_("cannot read the index"));
511515

512-
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
516+
repo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR);
513517
add_remove_files(&partial);
514-
refresh_cache(REFRESH_QUIET);
518+
refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
515519
update_main_cache_tree(WRITE_TREE_SILENT);
516520
if (write_locked_index(&the_index, &index_lock, 0))
517521
die(_("unable to write new_index file"));
@@ -523,14 +527,14 @@ static const char *prepare_index(const char **argv, const char *prefix,
523527

524528
create_base_index(current_head);
525529
add_remove_files(&partial);
526-
refresh_cache(REFRESH_QUIET);
530+
refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
527531

528532
if (write_locked_index(&the_index, &false_lock, 0))
529533
die(_("unable to write temporary index file"));
530534

531-
discard_cache();
535+
discard_index(&the_index);
532536
ret = get_lock_file_path(&false_lock);
533-
read_cache_from(ret);
537+
read_index_from(&the_index, ret, get_git_dir());
534538
out:
535539
string_list_clear(&partial, 0);
536540
clear_pathspec(&pathspec);
@@ -1068,9 +1072,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
10681072
* and could have updated it. We must do this before we invoke
10691073
* the editor and after we invoke run_status above.
10701074
*/
1071-
discard_cache();
1075+
discard_index(&the_index);
10721076
}
1073-
read_cache_from(index_file);
1077+
read_index_from(&the_index, index_file, get_git_dir());
10741078

10751079
if (update_main_cache_tree(0)) {
10761080
error(_("Error building trees"));
@@ -1556,7 +1560,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
15561560
&s.pathspec, NULL, NULL);
15571561

15581562
if (use_optional_locks())
1559-
fd = hold_locked_index(&index_lock, 0);
1563+
fd = repo_hold_locked_index(the_repository, &index_lock, 0);
15601564
else
15611565
fd = -1;
15621566

builtin/describe.c

Lines changed: 4 additions & 3 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 "cache.h"
33
#include "config.h"
44
#include "lockfile.h"
@@ -653,10 +653,11 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
653653
int fd, result;
654654

655655
setup_work_tree();
656-
read_cache();
656+
repo_read_index(the_repository);
657657
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,
658658
NULL, NULL, NULL);
659-
fd = hold_locked_index(&index_lock, 0);
659+
fd = repo_hold_locked_index(the_repository,
660+
&index_lock, 0);
660661
if (0 <= fd)
661662
repo_update_index_if_able(the_repository, &index_lock);
662663

0 commit comments

Comments
 (0)