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

@ -14,11 +14,11 @@ static int merge_entry(int pos, const char *path)
char ownbuf[4][60];
struct child_process cmd = CHILD_PROCESS_INIT;
if (pos >= active_nr)
if (pos >= the_index.cache_nr)
die("git merge-index: %s not in the cache", path);
found = 0;
do {
const struct cache_entry *ce = active_cache[pos];
const struct cache_entry *ce = the_index.cache[pos];
int stage = ce_stage(ce);
if (strcmp(ce->name, path))
@ -28,7 +28,7 @@ static int merge_entry(int pos, const char *path)
xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%o", ce->ce_mode);
arguments[stage] = hexbuf[stage];
arguments[stage + 4] = ownbuf[stage];
} while (++pos < active_nr);
} while (++pos < the_index.cache_nr);
if (!found)
die("git merge-index: %s not in the cache", path);
@ -62,8 +62,8 @@ static void merge_all(void)
int i;
/* 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];
if (!ce_stage(ce))
continue;
i += merge_entry(i, ce->name)-1;