cache-tree: wrap the_index based wrappers with #ifdef

This puts update_main_cache_tree() and write_cache_as_tree() in the same group of "index compat" functions that assume the_index implicitly, which should only be used within builtin/ or t/helper. sequencer.c is also updated to not use these functions. As of now, no files outside builtin/ use these functions anymore. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Aug 13, 2018 at 18:14 UTC 07096c969678a999c24816805d72bf7e0e840384
3 files changed +16 -17
cache-tree.c
-12
@@ -652,11 +652,6 @@ out:
652 return ret;
653 }
654
655 -int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix)
656 -{
657 - return write_index_as_tree(oid, &the_index, get_index_file(), flags, prefix);
658 -}
659 -
655 static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
656 {
657 struct tree_desc desc;
@@ -723,10 +718,3 @@ int cache_tree_matches_traversal(struct cache_tree *root,
718 return it->entry_count;
719 return 0;
720 }
726 -
727 -int update_main_cache_tree(int flags)
728 -{
729 - if (!the_index.cache_tree)
730 - the_index.cache_tree = cache_tree();
731 - return cache_tree_update(&the_index, flags);
732 -}
cache-tree.h
+14 -3
@@ -33,8 +33,6 @@ struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
33 int cache_tree_fully_valid(struct cache_tree *);
34 int cache_tree_update(struct index_state *, int);
35
36 -int update_main_cache_tree(int);
37 -
36 /* bitmasks to write_cache_as_tree flags */
37 #define WRITE_TREE_MISSING_OK 1
38 #define WRITE_TREE_IGNORE_CACHE_TREE 2
@@ -48,9 +46,22 @@ int update_main_cache_tree(int);
46 #define WRITE_TREE_PREFIX_ERROR (-3)
47
48 int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix);
51 -int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix);
49 void prime_cache_tree(struct index_state *, struct tree *);
50
51 int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);
52
53 +#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS
54 +static inline int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix)
55 +{
56 + return write_index_as_tree(oid, &the_index, get_index_file(), flags, prefix);
57 +}
58 +
59 +static inline int update_main_cache_tree(int flags)
60 +{
61 + if (!the_index.cache_tree)
62 + the_index.cache_tree = cache_tree();
63 + return cache_tree_update(&the_index, flags);
64 +}
65 +#endif
66 +
67 #endif
sequencer.c
+2 -2
@@ -1244,7 +1244,7 @@ static int try_to_commit(struct strbuf *msg, const char *author,
1244 commit_list_insert(current_head, &parents);
1245 }
1246
1247 - if (write_cache_as_tree(&tree, 0, NULL)) {
1247 + if (write_index_as_tree(&tree, &the_index, get_index_file(), 0, NULL)) {
1248 res = error(_("git write-tree failed to write a tree"));
1249 goto out;
1250 }
@@ -1630,7 +1630,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
1630 * that represents the "current" state for merge-recursive
1631 * to work on.
1632 */
1633 - if (write_cache_as_tree(&head, 0, NULL))
1633 + if (write_index_as_tree(&head, &the_index, get_index_file(), 0, NULL))
1634 return error(_("your index file is unmerged."));
1635 } else {
1636 unborn = get_oid("HEAD", &head);