]> git.ipfire.org Git - thirdparty/git.git/commitdiff
unpack-trees: populate cache-tree on successful merge
authorBrian Degenhardt <bmd@bmdhacks.com>
Tue, 28 Jul 2015 19:30:40 +0000 (15:30 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Jul 2015 20:43:13 +0000 (13:43 -0700)
When we unpack trees into an existing index, we discard the old
index and replace it with the new, merged index.  Ensure that this
index has its cache-tree populated.  This will make subsequent git
status and commit commands faster.

Signed-off-by: Brian Degenhardt <bmd@bmdhacks.com>
Signed-off-by: David Turner <dturner@twopensource.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t0090-cache-tree.sh
unpack-trees.c

index 601d02d71f735b4247528cc45b0ea055299ee7a0..055cc19000784bdb820e7ae53ba48987ead0367a 100755 (executable)
@@ -199,6 +199,30 @@ test_expect_success 'checkout -B gives cache-tree' '
        test_cache_tree
 '
 
+test_expect_success 'merge --ff-only maintains cache-tree' '
+       git checkout current &&
+       git checkout -b changes &&
+       test_commit llamas &&
+       test_commit pachyderm &&
+       test_cache_tree &&
+       git checkout current &&
+       test_cache_tree &&
+       git merge --ff-only changes &&
+       test_cache_tree
+'
+
+test_expect_success 'merge maintains cache-tree' '
+       git checkout current &&
+       git checkout -b changes2 &&
+       test_commit alpacas &&
+       test_cache_tree &&
+       git checkout current &&
+       test_commit struthio &&
+       test_cache_tree &&
+       git merge changes2 &&
+       test_cache_tree
+'
+
 test_expect_success 'partial commit gives cache-tree' '
        git checkout -b partial no-children &&
        test_commit one &&
index be84ba2607ad2dbdb17397869c459418abad78e4..d92f903402f0f8c448b689d26d3d5a97afc56f67 100644 (file)
@@ -1155,6 +1155,14 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
        o->src_index = NULL;
        ret = check_updates(o) ? (-2) : 0;
        if (o->dst_index) {
+               if (!ret) {
+                       if (!o->result.cache_tree)
+                               o->result.cache_tree = cache_tree();
+                       if (!cache_tree_fully_valid(o->result.cache_tree))
+                               cache_tree_update(&o->result,
+                                                 WRITE_TREE_SILENT |
+                                                 WRITE_TREE_REPAIR);
+               }
                discard_index(o->dst_index);
                *o->dst_index = o->result;
        } else {