Skip to content

Commit dc59418

Browse files
avargitster
authored andcommitted
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. 407b942 (commit: discard partial cache before (re-)reading it, 2022-11-08) Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 031b203 commit dc59418

19 files changed

+132
-129
lines changed

builtin/add.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ static int chmod_pathspec(struct pathspec *pathspec, char flip, int show_only)
4242
{
4343
int i, ret = 0;
4444

45-
for (i = 0; i < active_nr; i++) {
46-
struct cache_entry *ce = active_cache[i];
45+
for (i = 0; i < the_index.cache_nr; i++) {
46+
struct cache_entry *ce = the_index.cache[i];
4747
int err;
4848

4949
if (!include_sparse &&
@@ -159,8 +159,8 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
159159
{
160160
int i, retval = 0;
161161

162-
for (i = 0; i < active_nr; i++) {
163-
struct cache_entry *ce = active_cache[i];
162+
for (i = 0; i < the_index.cache_nr; i++) {
163+
struct cache_entry *ce = the_index.cache[i];
164164

165165
if (!include_sparse &&
166166
(ce_skip_worktree(ce) ||

builtin/checkout-index.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ static int checkout_file(const char *name, const char *prefix)
7575
if (pos < 0)
7676
pos = -pos - 1;
7777

78-
while (pos < active_nr) {
79-
struct cache_entry *ce = active_cache[pos];
78+
while (pos < the_index.cache_nr) {
79+
struct cache_entry *ce = the_index.cache[pos];
8080
if (ce_namelen(ce) != namelen ||
8181
memcmp(ce->name, name, namelen))
8282
break;
@@ -136,8 +136,8 @@ static int checkout_all(const char *prefix, int prefix_length)
136136
int i, errs = 0;
137137
struct cache_entry *last_ce = NULL;
138138

139-
for (i = 0; i < active_nr ; i++) {
140-
struct cache_entry *ce = active_cache[i];
139+
for (i = 0; i < the_index.cache_nr ; i++) {
140+
struct cache_entry *ce = the_index.cache[i];
141141

142142
if (S_ISSPARSEDIR(ce->ce_mode)) {
143143
if (!ce_skip_worktree(ce))
@@ -151,7 +151,7 @@ static int checkout_all(const char *prefix, int prefix_length)
151151
*/
152152
if (ignore_skip_worktree) {
153153
ensure_full_index(&the_index);
154-
ce = active_cache[i];
154+
ce = the_index.cache[i];
155155
}
156156
}
157157

builtin/checkout.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
150150
*/
151151
pos = cache_name_pos(ce->name, ce->ce_namelen);
152152
if (pos >= 0) {
153-
struct cache_entry *old = active_cache[pos];
153+
struct cache_entry *old = the_index.cache[pos];
154154
if (ce->ce_mode == old->ce_mode &&
155155
!ce_intent_to_add(old) &&
156156
oideq(&ce->oid, &old->oid)) {
@@ -179,18 +179,18 @@ static int read_tree_some(struct tree *tree, const struct pathspec *pathspec)
179179

180180
static int skip_same_name(const struct cache_entry *ce, int pos)
181181
{
182-
while (++pos < active_nr &&
183-
!strcmp(active_cache[pos]->name, ce->name))
182+
while (++pos < the_index.cache_nr &&
183+
!strcmp(the_index.cache[pos]->name, ce->name))
184184
; /* skip */
185185
return pos;
186186
}
187187

188188
static int check_stage(int stage, const struct cache_entry *ce, int pos,
189189
int overlay_mode)
190190
{
191-
while (pos < active_nr &&
192-
!strcmp(active_cache[pos]->name, ce->name)) {
193-
if (ce_stage(active_cache[pos]) == stage)
191+
while (pos < the_index.cache_nr &&
192+
!strcmp(the_index.cache[pos]->name, ce->name)) {
193+
if (ce_stage(the_index.cache[pos]) == stage)
194194
return 0;
195195
pos++;
196196
}
@@ -207,8 +207,8 @@ static int check_stages(unsigned stages, const struct cache_entry *ce, int pos)
207207
unsigned seen = 0;
208208
const char *name = ce->name;
209209

210-
while (pos < active_nr) {
211-
ce = active_cache[pos];
210+
while (pos < the_index.cache_nr) {
211+
ce = the_index.cache[pos];
212212
if (strcmp(name, ce->name))
213213
break;
214214
seen |= (1 << ce_stage(ce));
@@ -224,10 +224,10 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
224224
const struct checkout *state, int *nr_checkouts,
225225
int overlay_mode)
226226
{
227-
while (pos < active_nr &&
228-
!strcmp(active_cache[pos]->name, ce->name)) {
229-
if (ce_stage(active_cache[pos]) == stage)
230-
return checkout_entry(active_cache[pos], state,
227+
while (pos < the_index.cache_nr &&
228+
!strcmp(the_index.cache[pos]->name, ce->name)) {
229+
if (ce_stage(the_index.cache[pos]) == stage)
230+
return checkout_entry(the_index.cache[pos], state,
231231
NULL, nr_checkouts);
232232
pos++;
233233
}
@@ -244,7 +244,7 @@ static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
244244
static int checkout_merged(int pos, const struct checkout *state,
245245
int *nr_checkouts, struct mem_pool *ce_mem_pool)
246246
{
247-
struct cache_entry *ce = active_cache[pos];
247+
struct cache_entry *ce = the_index.cache[pos];
248248
const char *path = ce->name;
249249
mmfile_t ancestor, ours, theirs;
250250
enum ll_merge_result merge_status;
@@ -257,7 +257,7 @@ static int checkout_merged(int pos, const struct checkout *state,
257257
int renormalize = 0;
258258

259259
memset(threeway, 0, sizeof(threeway));
260-
while (pos < active_nr) {
260+
while (pos < the_index.cache_nr) {
261261
int stage;
262262
stage = ce_stage(ce);
263263
if (!stage || strcmp(path, ce->name))
@@ -266,7 +266,7 @@ static int checkout_merged(int pos, const struct checkout *state,
266266
if (stage == 2)
267267
mode = create_ce_mode(ce->ce_mode);
268268
pos++;
269-
ce = active_cache[pos];
269+
ce = the_index.cache[pos];
270270
}
271271
if (is_null_oid(&threeway[1]) || is_null_oid(&threeway[2]))
272272
return error(_("path '%s' does not have necessary versions"), path);
@@ -392,8 +392,8 @@ static int checkout_worktree(const struct checkout_opts *opts,
392392
if (pc_workers > 1)
393393
init_parallel_checkout();
394394

395-
for (pos = 0; pos < active_nr; pos++) {
396-
struct cache_entry *ce = active_cache[pos];
395+
for (pos = 0; pos < the_index.cache_nr; pos++) {
396+
struct cache_entry *ce = the_index.cache[pos];
397397
if (ce->ce_flags & CE_MATCHED) {
398398
if (!ce_stage(ce)) {
399399
errs |= checkout_entry(ce, &state,
@@ -541,13 +541,13 @@ static int checkout_paths(const struct checkout_opts *opts,
541541
* Make sure all pathspecs participated in locating the paths
542542
* to be checked out.
543543
*/
544-
for (pos = 0; pos < active_nr; pos++)
544+
for (pos = 0; pos < the_index.cache_nr; pos++)
545545
if (opts->overlay_mode)
546-
mark_ce_for_checkout_overlay(active_cache[pos],
546+
mark_ce_for_checkout_overlay(the_index.cache[pos],
547547
ps_matched,
548548
opts);
549549
else
550-
mark_ce_for_checkout_no_overlay(active_cache[pos],
550+
mark_ce_for_checkout_no_overlay(the_index.cache[pos],
551551
ps_matched,
552552
opts);
553553

@@ -562,8 +562,8 @@ static int checkout_paths(const struct checkout_opts *opts,
562562
unmerge_marked_index(&the_index);
563563

564564
/* Any unmerged paths? */
565-
for (pos = 0; pos < active_nr; pos++) {
566-
const struct cache_entry *ce = active_cache[pos];
565+
for (pos = 0; pos < the_index.cache_nr; pos++) {
566+
const struct cache_entry *ce = the_index.cache[pos];
567567
if (ce->ce_flags & CE_MATCHED) {
568568
if (!ce_stage(ce))
569569
continue;
@@ -868,7 +868,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
868868
}
869869
}
870870

871-
if (!cache_tree_fully_valid(active_cache_tree))
871+
if (!cache_tree_fully_valid(the_index.cache_tree))
872872
cache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
873873

874874
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))

builtin/commit.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ static int list_paths(struct string_list *list, const char *with_tree,
272272

273273
/* TODO: audit for interaction with sparse-index. */
274274
ensure_full_index(&the_index);
275-
for (i = 0; i < active_nr; i++) {
276-
const struct cache_entry *ce = active_cache[i];
275+
for (i = 0; i < the_index.cache_nr; i++) {
276+
const struct cache_entry *ce = the_index.cache[i];
277277
struct string_list_item *item;
278278

279279
if (ce->ce_flags & CE_UPDATE)
@@ -461,8 +461,8 @@ static const char *prepare_index(const char **argv, const char *prefix,
461461
if (!only && !pathspec.nr) {
462462
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
463463
refresh_cache_or_die(refresh_flags);
464-
if (active_cache_changed
465-
|| !cache_tree_fully_valid(active_cache_tree))
464+
if (the_index.cache_changed
465+
|| !cache_tree_fully_valid(the_index.cache_tree))
466466
update_main_cache_tree(WRITE_TREE_SILENT);
467467
if (write_locked_index(&the_index, &index_lock,
468468
COMMIT_LOCK | SKIP_IF_UNCHANGED))
@@ -998,10 +998,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
998998

999999
/* TODO: audit for interaction with sparse-index. */
10001000
ensure_full_index(&the_index);
1001-
for (i = 0; i < active_nr; i++)
1002-
if (ce_intent_to_add(active_cache[i]))
1001+
for (i = 0; i < the_index.cache_nr; i++)
1002+
if (ce_intent_to_add(the_index.cache[i]))
10031003
ita_nr++;
1004-
committable = active_nr - ita_nr > 0;
1004+
committable = the_index.cache_nr - ita_nr > 0;
10051005
} else {
10061006
/*
10071007
* Unless the user did explicitly request a submodule
@@ -1823,7 +1823,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
18231823
append_merge_tag_headers(parents, &tail);
18241824
}
18251825

1826-
if (commit_tree_extended(sb.buf, sb.len, &active_cache_tree->oid,
1826+
if (commit_tree_extended(sb.buf, sb.len, &the_index.cache_tree->oid,
18271827
parents, &oid, author_ident.buf, NULL,
18281828
sign_commit, extra)) {
18291829
rollback_index_files();

builtin/fsck.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -961,26 +961,26 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
961961
read_cache();
962962
/* TODO: audit for interaction with sparse-index. */
963963
ensure_full_index(&the_index);
964-
for (i = 0; i < active_nr; i++) {
964+
for (i = 0; i < the_index.cache_nr; i++) {
965965
unsigned int mode;
966966
struct blob *blob;
967967
struct object *obj;
968968

969-
mode = active_cache[i]->ce_mode;
969+
mode = the_index.cache[i]->ce_mode;
970970
if (S_ISGITLINK(mode))
971971
continue;
972972
blob = lookup_blob(the_repository,
973-
&active_cache[i]->oid);
973+
&the_index.cache[i]->oid);
974974
if (!blob)
975975
continue;
976976
obj = &blob->object;
977977
obj->flags |= USED;
978978
fsck_put_object_name(&fsck_walk_options, &obj->oid,
979-
":%s", active_cache[i]->name);
979+
":%s", the_index.cache[i]->name);
980980
mark_object_reachable(obj);
981981
}
982-
if (active_cache_tree)
983-
fsck_cache_tree(active_cache_tree);
982+
if (the_index.cache_tree)
983+
fsck_cache_tree(the_index.cache_tree);
984984
fsck_resolve_undo(&the_index);
985985
}
986986

builtin/merge-index.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ static int merge_entry(int pos, const char *path)
1414
char ownbuf[4][60];
1515
struct child_process cmd = CHILD_PROCESS_INIT;
1616

17-
if (pos >= active_nr)
17+
if (pos >= the_index.cache_nr)
1818
die("git merge-index: %s not in the cache", path);
1919
found = 0;
2020
do {
21-
const struct cache_entry *ce = active_cache[pos];
21+
const struct cache_entry *ce = the_index.cache[pos];
2222
int stage = ce_stage(ce);
2323

2424
if (strcmp(ce->name, path))
@@ -28,7 +28,7 @@ static int merge_entry(int pos, const char *path)
2828
xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%o", ce->ce_mode);
2929
arguments[stage] = hexbuf[stage];
3030
arguments[stage + 4] = ownbuf[stage];
31-
} while (++pos < active_nr);
31+
} while (++pos < the_index.cache_nr);
3232
if (!found)
3333
die("git merge-index: %s not in the cache", path);
3434

@@ -62,8 +62,8 @@ static void merge_all(void)
6262
int i;
6363
/* TODO: audit for interaction with sparse-index. */
6464
ensure_full_index(&the_index);
65-
for (i = 0; i < active_nr; i++) {
66-
const struct cache_entry *ce = active_cache[i];
65+
for (i = 0; i < the_index.cache_nr; i++) {
66+
const struct cache_entry *ce = the_index.cache[i];
6767
if (!ce_stage(ce))
6868
continue;
6969
i += merge_entry(i, ce->name)-1;

builtin/merge.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
694694
if (!trees[nr_trees++])
695695
return -1;
696696
opts.fn = threeway_merge;
697-
cache_tree_free(&active_cache_tree);
697+
cache_tree_free(&the_index.cache_tree);
698698
for (i = 0; i < nr_trees; i++) {
699699
parse_tree(trees[i]);
700700
init_tree_desc(t+i, trees[i]->buffer, trees[i]->size);
@@ -784,8 +784,8 @@ static int count_unmerged_entries(void)
784784
{
785785
int i, ret = 0;
786786

787-
for (i = 0; i < active_nr; i++)
788-
if (ce_stage(active_cache[i]))
787+
for (i = 0; i < the_index.cache_nr; i++)
788+
if (ce_stage(the_index.cache[i]))
789789
ret++;
790790

791791
return ret;

builtin/mv.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void prepare_move_submodule(const char *src, int first,
8787
const char **submodule_gitfile)
8888
{
8989
struct strbuf submodule_dotgit = STRBUF_INIT;
90-
if (!S_ISGITLINK(active_cache[first]->ce_mode))
90+
if (!S_ISGITLINK(the_index.cache[first]->ce_mode))
9191
die(_("Directory %s is in index and no submodule?"), src);
9292
if (!is_staging_gitmodules_ok(&the_index))
9393
die(_("Please stage your changes to .gitmodules or stash them to proceed"));
@@ -111,8 +111,8 @@ static int index_range_of_same_dir(const char *src, int length,
111111
die(_("%.*s is in index"), len_w_slash, src_w_slash);
112112

113113
first = -1 - first;
114-
for (last = first; last < active_nr; last++) {
115-
const char *path = active_cache[last]->name;
114+
for (last = first; last < the_index.cache_nr; last++) {
115+
const char *path = the_index.cache[last]->name;
116116
if (strncmp(path, src_w_slash, len_w_slash))
117117
break;
118118
}
@@ -143,7 +143,7 @@ static int empty_dir_has_sparse_contents(const char *name)
143143
pos = -pos - 1;
144144
if (pos >= the_index.cache_nr)
145145
goto free_return;
146-
ce = active_cache[pos];
146+
ce = the_index.cache[pos];
147147
if (strncmp(with_slash, ce->name, length))
148148
goto free_return;
149149
if (ce_skip_worktree(ce))
@@ -268,7 +268,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
268268
bad = _("bad source");
269269
goto act_on_entry;
270270
}
271-
ce = active_cache[pos];
271+
ce = the_index.cache[pos];
272272
if (!ce_skip_worktree(ce)) {
273273
bad = _("bad source");
274274
goto act_on_entry;
@@ -331,7 +331,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
331331
dst_len = strlen(dst);
332332

333333
for (j = 0; j < last - first; j++) {
334-
const struct cache_entry *ce = active_cache[first + j];
334+
const struct cache_entry *ce = the_index.cache[first + j];
335335
const char *path = ce->name;
336336
source[argc + j] = path;
337337
destination[argc + j] =
@@ -472,7 +472,8 @@ 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 = ie_modified(&the_index,
475-
active_cache[pos], &st,
475+
the_index.cache[pos],
476+
&st,
476477
0);
477478
rename_index_entry_at(&the_index, pos, dst);
478479

@@ -489,7 +490,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
489490
path_in_sparse_checkout(dst, &the_index)) {
490491
/* from out-of-cone to in-cone */
491492
int dst_pos = cache_name_pos(dst, strlen(dst));
492-
struct cache_entry *dst_ce = active_cache[dst_pos];
493+
struct cache_entry *dst_ce = the_index.cache[dst_pos];
493494

494495
dst_ce->ce_flags &= ~CE_SKIP_WORKTREE;
495496

@@ -500,7 +501,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
500501
!path_in_sparse_checkout(dst, &the_index)) {
501502
/* from in-cone to out-of-cone */
502503
int dst_pos = cache_name_pos(dst, strlen(dst));
503-
struct cache_entry *dst_ce = active_cache[dst_pos];
504+
struct cache_entry *dst_ce = the_index.cache[dst_pos];
504505

505506
/*
506507
* if src is clean, it will suffice to remove it

0 commit comments

Comments
 (0)