git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] cache-tree: populate cache-tree on successful merge

From
David Turner <dturner@twopensource.com>
Date
Jul 28, 2015, 19:30 UTC
Message-ID
<1438111840-6403-1-git-send-email-dturner@twopensource.com>

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: David Turner <dturner@twopensource.com>
Signed-off-by: Brian Degenhardt <bmd@bmdhacks.com>
---

This patch is by my colleague, Brian Degenhardt (as part of his work on git at Twitter). I'm sending it with his and Twitter's approval.

---
 t/t0090-cache-tree.sh | 24 ++++++++++++++++++++++++
 unpack-trees.c        |  7 +++++++
 2 files changed, 31 insertions(+)
diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
index 601d02d..055cc19 100755
--- a/t/t0090-cache-tree.sh
+++ b/t/t0090-cache-tree.sh
@@ -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 &&
diff --git a/unpack-trees.c b/unpack-trees.c
index 2927660..befc247 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1156,6 +1156,13 @@ 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 (!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 {
-- 
2.0.4.315.gad8727a-twtrsrc
Next: Junio C Hamano
Message 1 of 10 in “cache-tree: populate cache-tree on successful merge”
  1. cache-tree: populate cache-tree on successful mergeDavid Turner, Jul 28, 2015
  2. Junio C HamanoJul 28, 2015
  3. David TurnerJul 28, 2015
  4. Junio C HamanoJul 28, 2015
  5. Junio C HamanoJul 28, 2015
  6. David TurnerJul 28, 2015
  7. Junio C HamanoJul 28, 2015
  8. Junio C HamanoJul 28, 2015
  9. David TurnerJul 28, 2015
  10. Junio C HamanoJul 28, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.