Skip to content

Commit fbc1ed6

Browse files
avargitster
authored andcommitted
cocci & cache.h: remove rarely used "the_index" compat macros
Since 4aab5b4 (Make read-cache.c "the_index" free., 2007-04-01) we've been undergoing a slow migration away from these macros, but haven't made much progress since f8adbec (cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch, 2019-01-24). Let's move forward a bit by changing the users of those macros that are rare enough that we can convert them in one go, and then remove the compatibility shim. The only manual change to the C code here is to "cache.h", the rest is all the result of applying the new "index-compatibility.cocci". Even though it's a one-off, let's keep the coccinelle rules for now. We'll extend them in subsequent commits, and this will help anything that's in-flight or out-of-tree to migrate. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8f56511 commit fbc1ed6

File tree

13 files changed

+65
-29
lines changed

13 files changed

+65
-29
lines changed

builtin/add.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -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;

builtin/am.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,7 +1930,7 @@ static void am_resolve(struct am_state *state, int allow_empty)
19301930
}
19311931
}
19321932

1933-
if (unmerged_cache()) {
1933+
if (unmerged_index(&the_index)) {
19341934
printf_ln(_("You still have unmerged paths in your index.\n"
19351935
"You should 'git add' each file with resolved conflicts to mark them as such.\n"
19361936
"You might run `git rm` on a file to accept \"deleted by them\" for it."));
@@ -2045,7 +2045,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
20452045
if (!remote_tree)
20462046
return error(_("Could not parse object '%s'."), oid_to_hex(remote));
20472047

2048-
read_cache_unmerged();
2048+
repo_read_index_unmerged(the_repository);
20492049

20502050
if (fast_forward_to(head_tree, head_tree, 1))
20512051
return -1;

builtin/checkout.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ static void init_topts(struct unpack_trees_options *topts, int merge,
722722

723723
setup_unpack_trees_porcelain(topts, "checkout");
724724

725-
topts->initial_checkout = is_cache_unborn();
725+
topts->initial_checkout = is_index_unborn(&the_index);
726726
topts->update = 1;
727727
topts->merge = 1;
728728
topts->quiet = merge && old_commit;
@@ -763,7 +763,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
763763

764764
refresh_cache(REFRESH_QUIET);
765765

766-
if (unmerged_cache()) {
766+
if (unmerged_index(&the_index)) {
767767
error(_("you need to resolve your current index first"));
768768
return 1;
769769
}

builtin/clean.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
10311031
struct stat st;
10321032
const char *rel;
10331033

1034-
if (!cache_name_is_other(ent->name, ent->len))
1034+
if (!index_name_is_other(&the_index, ent->name, ent->len))
10351035
continue;
10361036

10371037
if (lstat(ent->name, &st))

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ static void add_remove_files(struct string_list *list)
302302
continue;
303303

304304
if (!lstat(p->string, &st)) {
305-
if (add_to_cache(p->string, &st, 0))
305+
if (add_to_index(&the_index, p->string, &st, 0))
306306
die(_("updating files failed"));
307307
} else
308308
remove_file_from_cache(p->string);

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13751375
goto done;
13761376
}
13771377

1378-
if (read_cache_unmerged())
1378+
if (repo_read_index_unmerged(the_repository))
13791379
die_resolve_conflict("merge");
13801380

13811381
if (file_exists(git_path_merge_head(the_repository))) {

builtin/mv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
343343
argc += last - first;
344344
goto act_on_entry;
345345
}
346-
if (!(ce = cache_file_exists(src, length, 0))) {
346+
if (!(ce = index_file_exists(&the_index, src, length, 0))) {
347347
bad = _("not under version control");
348348
goto act_on_entry;
349349
}
@@ -472,7 +472,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
472472
assert(pos >= 0);
473473
if (!(mode & SPARSE) && !lstat(src, &st))
474474
sparse_and_dirty = ce_modified(active_cache[pos], &st, 0);
475-
rename_cache_entry_at(pos, dst);
475+
rename_index_entry_at(&the_index, pos, dst);
476476

477477
if (ignore_sparse &&
478478
core_apply_sparse_checkout &&

builtin/pull.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
10301030
if (opt_rebase < 0)
10311031
opt_rebase = config_get_rebase(&rebase_unspecified);
10321032

1033-
if (read_cache_unmerged())
1033+
if (repo_read_index_unmerged(the_repository))
10341034
die_resolve_conflict("pull");
10351035

10361036
if (file_exists(git_path_merge_head(the_repository)))
@@ -1043,7 +1043,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
10431043
if (opt_autostash == -1)
10441044
opt_autostash = config_autostash;
10451045

1046-
if (is_null_oid(&orig_head) && !is_cache_unborn())
1046+
if (is_null_oid(&orig_head) && !is_index_unborn(&the_index))
10471047
die(_("Updating an unborn branch with changes added to the index."));
10481048

10491049
if (!opt_autostash)

builtin/read-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
188188
*/
189189

190190
if (opts.reset || opts.merge || opts.prefix) {
191-
if (read_cache_unmerged() && (opts.prefix || opts.merge))
191+
if (repo_read_index_unmerged(the_repository) && (opts.prefix || opts.merge))
192192
die(_("You need to resolve your current index first"));
193193
stage = opts.merge = 1;
194194
}
@@ -232,7 +232,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
232232
break;
233233
case 2:
234234
opts.fn = twoway_merge;
235-
opts.initial_checkout = is_cache_unborn();
235+
opts.initial_checkout = is_index_unborn(&the_index);
236236
break;
237237
case 3:
238238
default:

builtin/reset.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t
8484
BUG("invalid reset_type passed to reset_index");
8585
}
8686

87-
read_cache_unmerged();
87+
repo_read_index_unmerged(the_repository);
8888

8989
if (reset_type == KEEP) {
9090
struct object_id head_oid;
@@ -220,7 +220,7 @@ static void set_reflog_message(struct strbuf *sb, const char *action,
220220

221221
static void die_if_unmerged_cache(int reset_type)
222222
{
223-
if (is_merge() || unmerged_cache())
223+
if (is_merge() || unmerged_index(&the_index))
224224
die(_("Cannot do a %s reset in the middle of a merge."),
225225
_(reset_type_names[reset_type]));
226226

0 commit comments

Comments
 (0)