cache-tree API: remove redundant update_main_cache_tree()

Remove the redundant update_main_cache_tree() function, and make its users use cache_tree_update() instead. The behavior of populating the "the_index.cache_tree" if it wasn't present already was needed when this function was introduced in [1], but it hasn't been needed since [2]; The "cache_tree_update()" will now lazy-allocate, so there's no need for the wrapper. 1. 996277c5206 (Refactor cache_tree_update idiom from commit, 2011-12-06) 2. fb0882648e0 (cache-tree: clean up cache_tree_update(), 2021-01-23) Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 10, 2023 at 11:28 UTC fcb864bce70573380e6409c4ca25d1bdf16b0841
3 files changed +8 -15
builtin/commit.c
+5 -5
@@ -414,7 +414,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
414 discard_index(&the_index);
415 read_index_from(&the_index, get_lock_file_path(&index_lock),
416 get_git_dir());
417 - if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {
417 + if (cache_tree_update(&the_index, WRITE_TREE_SILENT) == 0) {
418 if (reopen_lock_file(&index_lock) < 0)
419 die(_("unable to write index file"));
420 if (write_locked_index(&the_index, &index_lock, 0))
@@ -444,7 +444,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
444 LOCK_DIE_ON_ERROR);
445 add_files_to_cache(also ? prefix : NULL, &pathspec, 0);
446 refresh_cache_or_die(refresh_flags);
447 - update_main_cache_tree(WRITE_TREE_SILENT);
447 + cache_tree_update(&the_index, WRITE_TREE_SILENT);
448 if (write_locked_index(&the_index, &index_lock, 0))
449 die(_("unable to write new_index file"));
450 commit_style = COMMIT_NORMAL;
@@ -467,7 +467,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
467 refresh_cache_or_die(refresh_flags);
468 if (the_index.cache_changed
469 || !cache_tree_fully_valid(the_index.cache_tree))
470 - update_main_cache_tree(WRITE_TREE_SILENT);
470 + cache_tree_update(&the_index, WRITE_TREE_SILENT);
471 if (write_locked_index(&the_index, &index_lock,
472 COMMIT_LOCK | SKIP_IF_UNCHANGED))
473 die(_("unable to write new_index file"));
@@ -516,7 +516,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
516 repo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR);
517 add_remove_files(&partial);
518 refresh_index(&the_index, REFRESH_QUIET, NULL, NULL, NULL);
519 - update_main_cache_tree(WRITE_TREE_SILENT);
519 + cache_tree_update(&the_index, WRITE_TREE_SILENT);
520 if (write_locked_index(&the_index, &index_lock, 0))
521 die(_("unable to write new_index file"));
522
@@ -1079,7 +1079,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
1079 }
1080 read_index_from(&the_index, index_file, get_git_dir());
1081
1082 - if (update_main_cache_tree(0)) {
1082 + if (cache_tree_update(&the_index, 0)) {
1083 error(_("Error building trees"));
1084 return 0;
1085 }
cache-tree.h
-10
@@ -53,14 +53,4 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state,
53 void prime_cache_tree(struct repository *, struct index_state *, struct tree *);
54
55 int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);
56 -
57 -#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS
58 -static inline int update_main_cache_tree(int flags)
59 -{
60 - if (!the_index.cache_tree)
61 - the_index.cache_tree = cache_tree();
62 - return cache_tree_update(&the_index, flags);
63 -}
64 -#endif
65 -
56 #endif
contrib/coccinelle/index-compatibility.cocci
+3
@@ -94,6 +94,9 @@ identifier ACT = active_cache_tree;
94 |
95 - cache_name_pos
96 + index_name_pos
97 +|
98 +- update_main_cache_tree
99 ++ cache_tree_update
100 )
101 (
102 + &the_index,