Skip to content

Commit 031b203

Browse files
avargitster
authored andcommitted
cocci & cache.h: apply a selection of "pending" index-compatibility
Apply a selection of rules in "index-compatibility.pending.cocci" tree-wide, and in doing so migrate them to "index-compatibility.cocci". As in preceding commits the only manual changes here are the macro removals in "cache.h", and the update to the '*.cocci" rules. The rest of the C code changes are the result of applying those updated rules. Move rules for some rarely used cache compatibility macros from "index-compatibility.pending.cocci" to "index-compatibility.cocci" and apply them. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0e6550a commit 031b203

File tree

11 files changed

+40
-41
lines changed

11 files changed

+40
-41
lines changed

builtin/checkout.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
160160
}
161161
}
162162

163-
add_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
163+
add_index_entry(&the_index, ce,
164+
ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
164165
return 0;
165166
}
166167

@@ -744,7 +745,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
744745
if (read_cache_preload(NULL) < 0)
745746
return error(_("index file corrupt"));
746747

747-
resolve_undo_clear();
748+
resolve_undo_clear_index(&the_index);
748749
if (opts->new_orphan_branch && opts->orphan_from_empty_tree) {
749750
if (new_branch_info->commit)
750751
BUG("'switch --orphan' should never accept a commit as starting point");

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ static void add_remove_files(struct string_list *list)
305305
if (add_to_index(&the_index, p->string, &st, 0))
306306
die(_("updating files failed"));
307307
} else
308-
remove_file_from_cache(p->string);
308+
remove_file_from_index(&the_index, p->string);
309309
}
310310
}
311311

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13971397
else
13981398
die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists)."));
13991399
}
1400-
resolve_undo_clear();
1400+
resolve_undo_clear_index(&the_index);
14011401

14021402
if (option_edit < 0)
14031403
option_edit = default_edit_option();

builtin/mv.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
471471
pos = cache_name_pos(src, strlen(src));
472472
assert(pos >= 0);
473473
if (!(mode & SPARSE) && !lstat(src, &st))
474-
sparse_and_dirty = ce_modified(active_cache[pos], &st, 0);
474+
sparse_and_dirty = ie_modified(&the_index,
475+
active_cache[pos], &st,
476+
0);
475477
rename_index_entry_at(&the_index, pos, dst);
476478

477479
if (ignore_sparse &&

builtin/read-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
192192
die(_("You need to resolve your current index first"));
193193
stage = opts.merge = 1;
194194
}
195-
resolve_undo_clear();
195+
resolve_undo_clear_index(&the_index);
196196

197197
for (i = 0; i < argc; i++) {
198198
const char *arg = argv[i];

builtin/reset.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,
145145
struct cache_entry *ce;
146146

147147
if (!is_in_reset_tree && !intent_to_add) {
148-
remove_file_from_cache(one->path);
148+
remove_file_from_index(&the_index, one->path);
149149
continue;
150150
}
151151

@@ -172,7 +172,8 @@ static void update_index_from_diff(struct diff_queue_struct *q,
172172
ce->ce_flags |= CE_INTENT_TO_ADD;
173173
set_object_name_for_intent_to_add_entry(ce);
174174
}
175-
add_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
175+
add_index_entry(&the_index, ce,
176+
ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
176177
}
177178
}
178179

builtin/rm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static int check_local_mod(struct object_id *head, int index_only)
168168
* Is the index different from the file in the work tree?
169169
* If it's a submodule, is its work tree modified?
170170
*/
171-
if (ce_match_stat(ce, &st, 0) ||
171+
if (ie_match_stat(&the_index, ce, &st, 0) ||
172172
(S_ISGITLINK(ce->ce_mode) &&
173173
bad_to_remove_submodule(ce->name,
174174
SUBMODULE_REMOVAL_DIE_ON_ERROR |
@@ -386,7 +386,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
386386
if (!quiet)
387387
printf("rm '%s'\n", path);
388388

389-
if (remove_file_from_cache(path))
389+
if (remove_file_from_index(&the_index, path))
390390
die(_("git rm: unable to remove %s"), path);
391391
}
392392

builtin/update-index.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static int remove_one_path(const char *path)
256256
{
257257
if (!allow_remove)
258258
return error("%s: does not exist and --remove not passed", path);
259-
if (remove_file_from_cache(path))
259+
if (remove_file_from_index(&the_index, path))
260260
return error("%s: cannot remove from the index", path);
261261
return 0;
262262
}
@@ -281,7 +281,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len
281281
struct cache_entry *ce;
282282

283283
/* Was the old index entry already up-to-date? */
284-
if (old && !ce_stage(old) && !ce_match_stat(old, st, 0))
284+
if (old && !ce_stage(old) && !ie_match_stat(&the_index, old, st, 0))
285285
return 0;
286286

287287
ce = make_empty_cache_entry(&the_index, len);
@@ -298,7 +298,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len
298298
}
299299
option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
300300
option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
301-
if (add_cache_entry(ce, option)) {
301+
if (add_index_entry(&the_index, ce, option)) {
302302
discard_cache_entry(ce);
303303
return error("%s: cannot add to the index - missing --add option?", path);
304304
}
@@ -390,7 +390,7 @@ static int process_path(const char *path, struct stat *st, int stat_errno)
390390
* On the other hand, removing it from index should work
391391
*/
392392
if (!ignore_skip_worktree_entries && allow_remove &&
393-
remove_file_from_cache(path))
393+
remove_file_from_index(&the_index, path))
394394
return error("%s: cannot remove from the index", path);
395395
return 0;
396396
}
@@ -429,7 +429,7 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid,
429429
ce->ce_flags |= CE_VALID;
430430
option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
431431
option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
432-
if (add_cache_entry(ce, option))
432+
if (add_index_entry(&the_index, ce, option))
433433
return error("%s: cannot add to the index - missing --add option?",
434434
path);
435435
report("add '%s'", path);
@@ -488,7 +488,7 @@ static void update_one(const char *path)
488488
}
489489

490490
if (force_remove) {
491-
if (remove_file_from_cache(path))
491+
if (remove_file_from_index(&the_index, path))
492492
die("git update-index: unable to remove %s", path);
493493
report("remove '%s'", path);
494494
return;
@@ -571,7 +571,7 @@ static void read_index_info(int nul_term_line)
571571

572572
if (!mode) {
573573
/* mode == 0 means there is no such path -- remove */
574-
if (remove_file_from_cache(path_name))
574+
if (remove_file_from_index(&the_index, path_name))
575575
die("git update-index: unable to remove %s",
576576
ptr);
577577
}
@@ -686,13 +686,13 @@ static int unresolve_one(const char *path)
686686
goto free_return;
687687
}
688688

689-
remove_file_from_cache(path);
690-
if (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) {
689+
remove_file_from_index(&the_index, path);
690+
if (add_index_entry(&the_index, ce_2, ADD_CACHE_OK_TO_ADD)) {
691691
error("%s: cannot add our version to the index.", path);
692692
ret = -1;
693693
goto free_return;
694694
}
695-
if (!add_cache_entry(ce_3, ADD_CACHE_OK_TO_ADD))
695+
if (!add_index_entry(&the_index, ce_3, ADD_CACHE_OK_TO_ADD))
696696
return 0;
697697
error("%s: cannot add their version to the index.", path);
698698
ret = -1;
@@ -850,7 +850,7 @@ static int resolve_undo_clear_callback(const struct option *opt,
850850
{
851851
BUG_ON_OPT_NEG(unset);
852852
BUG_ON_OPT_ARG(arg);
853-
resolve_undo_clear();
853+
resolve_undo_clear_index(&the_index);
854854
return 0;
855855
}
856856

cache.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,8 @@ extern struct index_state the_index;
446446
#define read_cache_preload(pathspec) repo_read_index_preload(the_repository, (pathspec), 0)
447447
#define discard_cache() discard_index(&the_index)
448448
#define cache_name_pos(name, namelen) index_name_pos(&the_index,(name),(namelen))
449-
#define add_cache_entry(ce, option) add_index_entry(&the_index, (ce), (option))
450-
#define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))
451449
#define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)
452450
#define refresh_and_write_cache(refresh_flags, write_flags, gentle) repo_refresh_and_write_index(the_repository, (refresh_flags), (write_flags), (gentle), NULL, NULL, NULL)
453-
#define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))
454-
#define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))
455-
#define resolve_undo_clear() resolve_undo_clear_index(&the_index)
456451
#define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))
457452
#endif
458453

contrib/coccinelle/index-compatibility.cocci

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@
3939
|
4040
- add_file_to_cache
4141
+ add_file_to_index
42+
|
43+
- add_cache_entry
44+
+ add_index_entry
45+
|
46+
- remove_file_from_cache
47+
+ remove_file_from_index
48+
|
49+
- ce_match_stat
50+
+ ie_match_stat
51+
|
52+
- ce_modified
53+
+ ie_modified
54+
|
55+
- resolve_undo_clear
56+
+ resolve_undo_clear_index
4257
)
4358
(
4459
+ &the_index,

0 commit comments

Comments
 (0)