]> git.ipfire.org Git - thirdparty/git.git/commitdiff
unpack-trees: add 'skip_cache_tree_update' option
authorVictoria Dye <vdye@github.com>
Thu, 10 Nov 2022 19:06:02 +0000 (19:06 +0000)
committerTaylor Blau <me@ttaylorr.com>
Fri, 11 Nov 2022 02:49:34 +0000 (21:49 -0500)
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>
unpack-trees.c
unpack-trees.h

index bae812156c4fedb8e296e422d4cb6a8af1a2dada..8a762aa0772eb4f7e107da6807092fe0a2be1a61 100644 (file)
@@ -2043,7 +2043,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
                if (!ret) {
                        if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0))
                                cache_tree_verify(the_repository, &o->result);
-                       if (!cache_tree_fully_valid(o->result.cache_tree))
+                       if (!o->skip_cache_tree_update &&
+                           !cache_tree_fully_valid(o->result.cache_tree))
                                cache_tree_update(&o->result,
                                                  WRITE_TREE_SILENT |
                                                  WRITE_TREE_REPAIR);
index efb9edfbb2717b4739247ecdd58a104e1d44cfd2..6ab0d74c84dc5ca3004e8b3b160dde98d1805e5d 100644 (file)
@@ -71,7 +71,8 @@ struct unpack_trees_options {
                     quiet,
                     exiting_early,
                     show_all_errors,
-                    dry_run;
+                    dry_run,
+                    skip_cache_tree_update;
        enum unpack_trees_reset_type reset;
        const char *prefix;
        int cache_bottom;