Skip to content

Commit fcb864b

Browse files
avargitster
authored andcommitted
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. 996277c (Refactor cache_tree_update idiom from commit, 2011-12-06) 2. fb08826 (cache-tree: clean up cache_tree_update(), 2021-01-23) Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9937086 commit fcb864b

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

builtin/commit.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
414414
discard_index(&the_index);
415415
read_index_from(&the_index, get_lock_file_path(&index_lock),
416416
get_git_dir());
417-
if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {
417+
if (cache_tree_update(&the_index, WRITE_TREE_SILENT) == 0) {
418418
if (reopen_lock_file(&index_lock) < 0)
419419
die(_("unable to write index file"));
420420
if (write_locked_index(&the_index, &index_lock, 0))
@@ -444,7 +444,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
444444
LOCK_DIE_ON_ERROR);
445445
add_files_to_cache(also ? prefix : NULL, &pathspec, 0);
446446
refresh_cache_or_die(refresh_flags);
447-
update_main_cache_tree(WRITE_TREE_SILENT);
447+
cache_tree_update(&the_index, WRITE_TREE_SILENT);
448448
if (write_locked_index(&the_index, &index_lock, 0))
449449
die(_("unable to write new_index file"));
450450
commit_style = COMMIT_NORMAL;
@@ -467,7 +467,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
467467
refresh_cache_or_die(refresh_flags);
468468
if (the_index.cache_changed
469469
|| !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);
471471
if (write_locked_index(&the_index, &index_lock,
472472
COMMIT_LOCK | SKIP_IF_UNCHANGED))
473473
die(_("unable to write new_index file"));
@@ -516,7 +516,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
516516
repo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR);
517517
add_remove_files(&partial);
518518
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);
520520
if (write_locked_index(&the_index, &index_lock, 0))
521521
die(_("unable to write new_index file"));
522522

@@ -1079,7 +1079,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
10791079
}
10801080
read_index_from(&the_index, index_file, get_git_dir());
10811081

1082-
if (update_main_cache_tree(0)) {
1082+
if (cache_tree_update(&the_index, 0)) {
10831083
error(_("Error building trees"));
10841084
return 0;
10851085
}

cache-tree.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,4 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state,
5353
void prime_cache_tree(struct repository *, struct index_state *, struct tree *);
5454

5555
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-
6656
#endif

contrib/coccinelle/index-compatibility.cocci

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ identifier ACT = active_cache_tree;
9494
|
9595
- cache_name_pos
9696
+ index_name_pos
97+
|
98+
- update_main_cache_tree
99+
+ cache_tree_update
97100
)
98101
(
99102
+ &the_index,

0 commit comments

Comments
 (0)