unpack-trees: populate cache-tree on successful merge

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>

Brian Degenhardt committed Jul 28, 2015 at 15:30 UTC 52fca2184df8398f0ba212cd6a0ec1fb123b7473
2 files changed +32
t/t0090-cache-tree.sh
+24
@@ -199,6 +199,30 @@ test_expect_success 'checkout -B gives cache-tree' '
199 test_cache_tree
200 '
201
202 +test_expect_success 'merge --ff-only maintains cache-tree' '
203 + git checkout current &&
204 + git checkout -b changes &&
205 + test_commit llamas &&
206 + test_commit pachyderm &&
207 + test_cache_tree &&
208 + git checkout current &&
209 + test_cache_tree &&
210 + git merge --ff-only changes &&
211 + test_cache_tree
212 +'
213 +
214 +test_expect_success 'merge maintains cache-tree' '
215 + git checkout current &&
216 + git checkout -b changes2 &&
217 + test_commit alpacas &&
218 + test_cache_tree &&
219 + git checkout current &&
220 + test_commit struthio &&
221 + test_cache_tree &&
222 + git merge changes2 &&
223 + test_cache_tree
224 +'
225 +
226 test_expect_success 'partial commit gives cache-tree' '
227 git checkout -b partial no-children &&
228 test_commit one &&
unpack-trees.c
+8
@@ -1155,6 +1155,14 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1155 o->src_index = NULL;
1156 ret = check_updates(o) ? (-2) : 0;
1157 if (o->dst_index) {
1158 + if (!ret) {
1159 + if (!o->result.cache_tree)
1160 + o->result.cache_tree = cache_tree();
1161 + if (!cache_tree_fully_valid(o->result.cache_tree))
1162 + cache_tree_update(&o->result,
1163 + WRITE_TREE_SILENT |
1164 + WRITE_TREE_REPAIR);
1165 + }
1166 discard_index(o->dst_index);
1167 *o->dst_index = o->result;
1168 } else {