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

@ -239,14 +239,14 @@ static int mark_ce_flags(const char *path, int flag, int mark)
int namelen = strlen(path);
int pos = cache_name_pos(path, namelen);
if (0 <= pos) {
mark_fsmonitor_invalid(&the_index, active_cache[pos]);
mark_fsmonitor_invalid(&the_index, the_index.cache[pos]);
if (mark)
active_cache[pos]->ce_flags |= flag;
the_index.cache[pos]->ce_flags |= flag;
else
active_cache[pos]->ce_flags &= ~flag;
active_cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;
the_index.cache[pos]->ce_flags &= ~flag;
the_index.cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;
cache_tree_invalidate_path(&the_index, path);
active_cache_changed |= CE_ENTRY_CHANGED;
the_index.cache_changed |= CE_ENTRY_CHANGED;
return 0;
}
return -1;
@ -335,7 +335,7 @@ static int process_directory(const char *path, int len, struct stat *st)
/* Exact match: file or existing gitlink */
if (pos >= 0) {
const struct cache_entry *ce = active_cache[pos];
const struct cache_entry *ce = the_index.cache[pos];
if (S_ISGITLINK(ce->ce_mode)) {
/* Do nothing to the index if there is no HEAD! */
@ -350,8 +350,8 @@ static int process_directory(const char *path, int len, struct stat *st)
/* Inexact match: is there perhaps a subdirectory match? */
pos = -pos-1;
while (pos < active_nr) {
const struct cache_entry *ce = active_cache[pos++];
while (pos < the_index.cache_nr) {
const struct cache_entry *ce = the_index.cache[pos++];
if (strncmp(ce->name, path, len))
break;
@ -382,7 +382,7 @@ static int process_path(const char *path, struct stat *st, int stat_errno)
return error("'%s' is beyond a symbolic link", path);
pos = cache_name_pos(path, len);
ce = pos < 0 ? NULL : active_cache[pos];
ce = pos < 0 ? NULL : the_index.cache[pos];
if (ce && ce_skip_worktree(ce)) {
/*
* working directory version is assumed "good"
@ -444,7 +444,7 @@ static void chmod_path(char flip, const char *path)
pos = cache_name_pos(path, strlen(path));
if (pos < 0)
goto fail;
ce = active_cache[pos];
ce = the_index.cache[pos];
if (chmod_index_entry(&the_index, ce, flip) < 0)
goto fail;
@ -642,8 +642,8 @@ static int unresolve_one(const char *path)
if (0 <= pos) {
/* already merged */
pos = unmerge_index_entry_at(&the_index, pos);
if (pos < active_nr) {
const struct cache_entry *ce = active_cache[pos];
if (pos < the_index.cache_nr) {
const struct cache_entry *ce = the_index.cache[pos];
if (ce_stage(ce) &&
ce_namelen(ce) == namelen &&
!memcmp(ce->name, path, namelen))
@ -656,8 +656,8 @@ static int unresolve_one(const char *path)
* want to do anything in the former case.
*/
pos = -pos-1;
if (pos < active_nr) {
const struct cache_entry *ce = active_cache[pos];
if (pos < the_index.cache_nr) {
const struct cache_entry *ce = the_index.cache[pos];
if (ce_namelen(ce) == namelen &&
!memcmp(ce->name, path, namelen)) {
fprintf(stderr,
@ -752,8 +752,8 @@ static int do_reupdate(const char **paths,
*/
has_head = 0;
redo:
for (pos = 0; pos < active_nr; pos++) {
const struct cache_entry *ce = active_cache[pos];
for (pos = 0; pos < the_index.cache_nr; pos++) {
const struct cache_entry *ce = the_index.cache[pos];
struct cache_entry *old = NULL;
int save_nr;
char *path;
@ -782,12 +782,12 @@ static int do_reupdate(const char **paths,
* path anymore, in which case, under 'allow_remove',
* or worse yet 'allow_replace', active_nr may decrease.
*/
save_nr = active_nr;
save_nr = the_index.cache_nr;
path = xstrdup(ce->name);
update_one(path);
free(path);
discard_cache_entry(old);
if (save_nr != active_nr)
if (save_nr != the_index.cache_nr)
goto redo;
}
clear_pathspec(&pathspec);
@ -813,7 +813,7 @@ static int refresh(struct refresh_params *o, unsigned int flag)
* refresh_cache() as these are no actual errors.
* cmd_status() does the same.
*/
active_cache_changed |= SOMETHING_CHANGED;
the_index.cache_changed |= SOMETHING_CHANGED;
}
return 0;
}
@ -951,7 +951,7 @@ static enum parse_opt_result unresolve_callback(
*has_errors = do_unresolve(ctx->argc, ctx->argv,
prefix, prefix ? strlen(prefix) : 0);
if (*has_errors)
active_cache_changed = 0;
the_index.cache_changed = 0;
ctx->argv += ctx->argc - 1;
ctx->argc = 1;
@ -972,7 +972,7 @@ static enum parse_opt_result reupdate_callback(
setup_work_tree();
*has_errors = do_reupdate(ctx->argv + 1, prefix);
if (*has_errors)
active_cache_changed = 0;
the_index.cache_changed = 0;
ctx->argv += ctx->argc - 1;
ctx->argc = 1;
@ -1178,7 +1178,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
INDEX_FORMAT_LB, INDEX_FORMAT_UB);
if (the_index.version != preferred_index_format)
active_cache_changed |= SOMETHING_CHANGED;
the_index.cache_changed |= SOMETHING_CHANGED;
the_index.version = preferred_index_format;
}
@ -1290,7 +1290,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
report(_("fsmonitor disabled"));
}
if (active_cache_changed || force_write) {
if (the_index.cache_changed || force_write) {
if (newfd < 0) {
if (refresh_args.flags & REFRESH_QUIET)
exit(128);