cocci & cache.h: apply variable section of "pending" index-compatibility

Mostly apply the part of "index-compatibility.pending.cocci" that
renames the global variables like "active_nr", which are a shorthand
to referencing (in that case) a struct member as "the_index.cache_nr".

In doing so move more of "index-compatibility.pending.cocci" to
"index-compatibility.cocci".

In the case of "active_nr" we'd have a textual conflict with
"ab/various-leak-fixes" in "next"[1]. Let's exclude that specific case
while moving the rule over from "pending".

1. 407b94280f8 (commit: discard partial cache before (re-)reading it,
   2022-11-08)

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason
2022-11-19 14:07:34 +01:00
committed by Junio C Hamano
parent 031b2033e0
commit dc594180d9
19 changed files with 132 additions and 129 deletions

View File

@ -272,8 +272,8 @@ static int list_paths(struct string_list *list, const char *with_tree,
/* TODO: audit for interaction with sparse-index. */
ensure_full_index(&the_index);
for (i = 0; i < active_nr; i++) {
const struct cache_entry *ce = active_cache[i];
for (i = 0; i < the_index.cache_nr; i++) {
const struct cache_entry *ce = the_index.cache[i];
struct string_list_item *item;
if (ce->ce_flags & CE_UPDATE)
@ -461,8 +461,8 @@ static const char *prepare_index(const char **argv, const char *prefix,
if (!only && !pathspec.nr) {
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
refresh_cache_or_die(refresh_flags);
if (active_cache_changed
|| !cache_tree_fully_valid(active_cache_tree))
if (the_index.cache_changed
|| !cache_tree_fully_valid(the_index.cache_tree))
update_main_cache_tree(WRITE_TREE_SILENT);
if (write_locked_index(&the_index, &index_lock,
COMMIT_LOCK | SKIP_IF_UNCHANGED))
@ -998,10 +998,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
/* TODO: audit for interaction with sparse-index. */
ensure_full_index(&the_index);
for (i = 0; i < active_nr; i++)
if (ce_intent_to_add(active_cache[i]))
for (i = 0; i < the_index.cache_nr; i++)
if (ce_intent_to_add(the_index.cache[i]))
ita_nr++;
committable = active_nr - ita_nr > 0;
committable = the_index.cache_nr - ita_nr > 0;
} else {
/*
* Unless the user did explicitly request a submodule
@ -1823,7 +1823,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
append_merge_tag_headers(parents, &tail);
}
if (commit_tree_extended(sb.buf, sb.len, &active_cache_tree->oid,
if (commit_tree_extended(sb.buf, sb.len, &the_index.cache_tree->oid,
parents, &oid, author_ident.buf, NULL,
sign_commit, extra)) {
rollback_index_files();