unpack-trees: add 'skip_cache_tree_update' option

Add (disabled by default) option to skip the 'cache_tree_update()' at the end of 'unpack_trees()'. In many cases, this cache tree update is redundant because the caller of 'unpack_trees()' immediately follows it with 'prime_cache_tree()', rebuilding the entire cache tree from scratch. While these operations aren't the most expensive part of operations like 'git reset', the duplicate calls still create a minor unnecessary slowdown. Introduce an option for callers to skip the 'cache_tree_update()' in 'unpack_trees()' if it is redundant (that is, if 'prime_cache_tree()' is called afterwards). At the moment, no 'unpack_trees()' callers use the new option; they will be updated in subsequent patches. Signed-off-by: Victoria Dye <vdye@github.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Victoria Dye committed Nov 10, 2022 at 19:06 UTC 68fcd48bafa1ef51b1ba40a41cb0fcdbad7acce1
2 files changed +4 -2
unpack-trees.c
+2 -1
@@ -2043,7 +2043,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
2043 if (!ret) {
2044 if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0))
2045 cache_tree_verify(the_repository, &o->result);
2046 - if (!cache_tree_fully_valid(o->result.cache_tree))
2046 + if (!o->skip_cache_tree_update &&
2047 + !cache_tree_fully_valid(o->result.cache_tree))
2048 cache_tree_update(&o->result,
2049 WRITE_TREE_SILENT |
2050 WRITE_TREE_REPAIR);
unpack-trees.h
+2 -1
@@ -71,7 +71,8 @@ struct unpack_trees_options {
71 quiet,
72 exiting_early,
73 show_all_errors,
74 - dry_run;
74 + dry_run,
75 + skip_cache_tree_update;
76 enum unpack_trees_reset_type reset;
77 const char *prefix;
78 int cache_bottom;