Skip to content

Commit 9937086

Browse files
avargitster
authored andcommitted
cocci & cache-tree.h: migrate "write_cache_as_tree" to "*_index_*"
Add a trivial rule for "write_cache_as_tree" to "index-compatibility.cocci", and apply it. This was left out of the rules added in 0e6550a (cocci: add a index-compatibility.pending.cocci, 2022-11-19) because this compatibility wrapper lived in "cache-tree.h", not "cache.h" But it's like the other "USE_THE_INDEX_COMPATIBILITY_MACROS", so let's migrate it too. The replacement of "USE_THE_INDEX_COMPATIBILITY_MACROS" here with "USE_THE_INDEX_VARIABLE" is a manual change on top, now that these files only use "&the_index", and don't need any compatibility macros (or functions). The wrapping of some argument lists is likewise manual, as coccinelle would otherwise give us overly long argument lists. The reason for putting the "O" in the cocci rule on the "-" and "+" lines is because I couldn't get correct whitespacing otherwise, i.e. I'd end up with "oid,&the_index", not "oid, &the_index". Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent babed89 commit 9937086

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed

builtin/am.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Based on git-am.sh by Junio C Hamano.
55
*/
6-
#define USE_THE_INDEX_COMPATIBILITY_MACROS
6+
#define USE_THE_INDEX_VARIABLE
77
#include "cache.h"
88
#include "config.h"
99
#include "builtin.h"
@@ -1655,7 +1655,7 @@ static void do_commit(const struct am_state *state)
16551655
if (!state->no_verify && run_hooks("pre-applypatch"))
16561656
exit(1);
16571657

1658-
if (write_cache_as_tree(&tree, 0, NULL))
1658+
if (write_index_as_tree(&tree, &the_index, get_index_file(), 0, NULL))
16591659
die(_("git write-tree failed to write a tree"));
16601660

16611661
if (!get_oid_commit("HEAD", &parent)) {
@@ -2063,7 +2063,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
20632063
if (fast_forward_to(head_tree, head_tree, 1))
20642064
return -1;
20652065

2066-
if (write_cache_as_tree(&index, 0, NULL))
2066+
if (write_index_as_tree(&index, &the_index, get_index_file(), 0, NULL))
20672067
return -1;
20682068

20692069
index_tree = parse_tree_indirect(&index);

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
706706

707707
static void write_tree_trivial(struct object_id *oid)
708708
{
709-
if (write_cache_as_tree(oid, 0, NULL))
709+
if (write_index_as_tree(oid, &the_index, get_index_file(), 0, NULL))
710710
die(_("git write-tree failed to write a tree"));
711711
}
712712

builtin/stash.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#define USE_THE_INDEX_COMPATIBILITY_MACROS
1+
#define USE_THE_INDEX_VARIABLE
22
#include "builtin.h"
33
#include "config.h"
44
#include "parse-options.h"
@@ -528,7 +528,8 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
528528
NULL, NULL, NULL))
529529
return -1;
530530

531-
if (write_cache_as_tree(&c_tree, 0, NULL))
531+
if (write_index_as_tree(&c_tree, &the_index, get_index_file(), 0,
532+
NULL))
532533
return error(_("cannot apply a stash in the middle of a merge"));
533534

534535
if (index) {
@@ -552,7 +553,8 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
552553

553554
discard_index(&the_index);
554555
repo_read_index(the_repository);
555-
if (write_cache_as_tree(&index_tree, 0, NULL))
556+
if (write_index_as_tree(&index_tree, &the_index,
557+
get_index_file(), 0, NULL))
556558
return error(_("could not save index tree"));
557559

558560
reset_head();
@@ -1377,7 +1379,8 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b
13771379

13781380
strbuf_addf(&commit_tree_label, "index on %s\n", msg.buf);
13791381
commit_list_insert(head_commit, &parents);
1380-
if (write_cache_as_tree(&info->i_tree, 0, NULL) ||
1382+
if (write_index_as_tree(&info->i_tree, &the_index, get_index_file(), 0,
1383+
NULL) ||
13811384
commit_tree(commit_tree_label.buf, commit_tree_label.len,
13821385
&info->i_tree, parents, &info->i_commit, NULL, NULL)) {
13831386
if (!quiet)

builtin/write-tree.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (C) Linus Torvalds, 2005
55
*/
6-
#define USE_THE_INDEX_COMPATIBILITY_MACROS
6+
#define USE_THE_INDEX_VARIABLE
77
#include "builtin.h"
88
#include "cache.h"
99
#include "config.h"
@@ -38,7 +38,8 @@ int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
3838
argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
3939
write_tree_usage, 0);
4040

41-
ret = write_cache_as_tree(&oid, flags, tree_prefix);
41+
ret = write_index_as_tree(&oid, &the_index, get_index_file(), flags,
42+
tree_prefix);
4243
switch (ret) {
4344
case 0:
4445
printf("%s\n", oid_to_hex(&oid));

cache-tree.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ void prime_cache_tree(struct repository *, struct index_state *, struct tree *);
5555
int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);
5656

5757
#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS
58-
static inline int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix)
59-
{
60-
return write_index_as_tree(oid, &the_index, get_index_file(), flags, prefix);
61-
}
62-
6358
static inline int update_main_cache_tree(int flags)
6459
{
6560
if (!the_index.cache_tree)

contrib/coccinelle/index-compatibility.cocci

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,14 @@ identifier ACT = active_cache_tree;
135135
...
136136
+ , NULL, NULL, NULL
137137
)
138+
139+
@@
140+
expression O;
141+
@@
142+
- write_cache_as_tree
143+
+ write_index_as_tree
144+
(
145+
- O,
146+
+ O, &the_index, get_index_file(),
147+
...
148+
)

0 commit comments

Comments
 (0)