]> git.ipfire.org Git - thirdparty/git.git/commitdiff
cocci & cache-tree.h: migrate "write_cache_as_tree" to "*_index_*"
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Fri, 10 Feb 2023 10:28:37 +0000 (11:28 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Feb 2023 19:37:49 +0000 (11:37 -0800)
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 0e6550a2c63 (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 <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/am.c
builtin/merge.c
builtin/stash.c
builtin/write-tree.c
cache-tree.h
contrib/coccinelle/index-compatibility.cocci

index 82a41cbfc4e9ce2538644b9247dfc3a3bbe60888..8b3dcb66f08aa208fc790185ea0cd9ce383ed121 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Based on git-am.sh by Junio C Hamano.
  */
-#define USE_THE_INDEX_COMPATIBILITY_MACROS
+#define USE_THE_INDEX_VARIABLE
 #include "cache.h"
 #include "config.h"
 #include "builtin.h"
@@ -1655,7 +1655,7 @@ static void do_commit(const struct am_state *state)
        if (!state->no_verify && run_hooks("pre-applypatch"))
                exit(1);
 
-       if (write_cache_as_tree(&tree, 0, NULL))
+       if (write_index_as_tree(&tree, &the_index, get_index_file(), 0, NULL))
                die(_("git write-tree failed to write a tree"));
 
        if (!get_oid_commit("HEAD", &parent)) {
@@ -2063,7 +2063,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
        if (fast_forward_to(head_tree, head_tree, 1))
                return -1;
 
-       if (write_cache_as_tree(&index, 0, NULL))
+       if (write_index_as_tree(&index, &the_index, get_index_file(), 0, NULL))
                return -1;
 
        index_tree = parse_tree_indirect(&index);
index 74de2ebd2b33f967ff85988779bbf85819fe9a3c..d7cc8dc8aedb672c63e4df0e623582a5922b1b54 100644 (file)
@@ -706,7 +706,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
 
 static void write_tree_trivial(struct object_id *oid)
 {
-       if (write_cache_as_tree(oid, 0, NULL))
+       if (write_index_as_tree(oid, &the_index, get_index_file(), 0, NULL))
                die(_("git write-tree failed to write a tree"));
 }
 
index 839569a98033f1cf2e8eb74b2eb6fc1770eba8fc..78d69da8cf7ab51a0d3e1ac37646f241aa301a32 100644 (file)
@@ -1,4 +1,4 @@
-#define USE_THE_INDEX_COMPATIBILITY_MACROS
+#define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "parse-options.h"
@@ -528,7 +528,8 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
                                         NULL, NULL, NULL))
                return -1;
 
-       if (write_cache_as_tree(&c_tree, 0, NULL))
+       if (write_index_as_tree(&c_tree, &the_index, get_index_file(), 0,
+                               NULL))
                return error(_("cannot apply a stash in the middle of a merge"));
 
        if (index) {
@@ -552,7 +553,8 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
 
                        discard_index(&the_index);
                        repo_read_index(the_repository);
-                       if (write_cache_as_tree(&index_tree, 0, NULL))
+                       if (write_index_as_tree(&index_tree, &the_index,
+                                               get_index_file(), 0, NULL))
                                return error(_("could not save index tree"));
 
                        reset_head();
@@ -1377,7 +1379,8 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b
 
        strbuf_addf(&commit_tree_label, "index on %s\n", msg.buf);
        commit_list_insert(head_commit, &parents);
-       if (write_cache_as_tree(&info->i_tree, 0, NULL) ||
+       if (write_index_as_tree(&info->i_tree, &the_index, get_index_file(), 0,
+                               NULL) ||
            commit_tree(commit_tree_label.buf, commit_tree_label.len,
                        &info->i_tree, parents, &info->i_commit, NULL, NULL)) {
                if (!quiet)
index 45d61707e7d11e60e5ba2e6da90017fb38b30dc3..078010315f004647f22865db68f5cab63a799f8f 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#define USE_THE_INDEX_COMPATIBILITY_MACROS
+#define USE_THE_INDEX_VARIABLE
 #include "builtin.h"
 #include "cache.h"
 #include "config.h"
@@ -38,7 +38,8 @@ int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
        argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
                             write_tree_usage, 0);
 
-       ret = write_cache_as_tree(&oid, flags, tree_prefix);
+       ret = write_index_as_tree(&oid, &the_index, get_index_file(), flags,
+                                 tree_prefix);
        switch (ret) {
        case 0:
                printf("%s\n", oid_to_hex(&oid));
index 8efeccebfc9f0bf8c9cfda1aa4ac531108b52650..84890c9ff32ce82bc7b960f5fa39698e939c1de9 100644 (file)
@@ -55,11 +55,6 @@ void prime_cache_tree(struct repository *, struct index_state *, struct tree *);
 int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);
 
 #ifdef USE_THE_INDEX_COMPATIBILITY_MACROS
-static inline int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix)
-{
-       return write_index_as_tree(oid, &the_index, get_index_file(), flags, prefix);
-}
-
 static inline int update_main_cache_tree(int flags)
 {
        if (!the_index.cache_tree)
index 1d37546fdbd6feaddb690840b3a0fbb3556aabad..e245d805dcdefa7c31be594bff78fd8d47de25e9 100644 (file)
@@ -135,3 +135,14 @@ identifier ACT = active_cache_tree;
   ...
 + , NULL, NULL, NULL
   )
+
+@@
+expression O;
+@@
+- write_cache_as_tree
++ write_index_as_tree
+  (
+- O,
++ O, &the_index, get_index_file(),
+  ...
+  )