cache-tree: populate cache-tree on successful merge
PATCH 1/1 cache-tree: 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.
---
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(+)
t/t0090-cache-tree.sh +24 -0
@@ -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 &&
unpack-trees.c +7 -0
@@ -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 {
Signature · 1 line
2.0.4.315.gad8727a-twtrsrc
Quoted 4 lines · David Turner
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.
Wouldn't it make repeated calls to "git merge" and friends to build a long history slower, when the user does not run "git status" in between? E.g. "git cherry-pick -4 $other_topic", where you would not even have a chance to run "git status" in the middle. What do the pros-and-cons look like?
Quoted 7 lines · Junio C Hamano
Quoted 4 lines · David Turner
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.
Quoted 5 lines
Wouldn't it make repeated calls to "git merge" and friends to build a long history slower, when the user does not run "git status" in between? E.g. "git cherry-pick -4 $other_topic", where you would not even have a chance to run "git status" in the middle. What do the pros-and-cons look like?
I have not benchmarked, but I suspect it would not make those slower.
The work done to produce the cache-tree is work that the commit would otherwise have to do. So we're spending extra time in one place to eliminate that work in a different place.
Quoted 3 lines · David Turner
The work done to produce the cache-tree is work that the commit would otherwise have to do. So we're spending extra time in one place to eliminate that work in a different place.
Good point. Thanks.
Quoted 7 lines · Junio C Hamano
Quoted 3 lines · David Turner
The work done to produce the cache-tree is work that the commit would otherwise have to do. So we're spending extra time in one place to eliminate that work in a different place.
Good point. Thanks.
Hmm, I forgot about another codepath. What about operations that are purely done to pouplate the index, without necessarily creating a tree out of the index?
The most worrisome is "git checkout $branch" (two-tree merge).
Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · David Turner
The work done to produce the cache-tree is work that the commit would otherwise have to do. So we're spending extra time in one place to eliminate that work in a different place.
Quoted 7 lines
Quoted 1 line
Good point. Thanks.
Hmm, I forgot about another codepath. What about operations that are purely done to pouplate the index, without necessarily creating a tree out of the index?
The most worrisome is "git checkout $branch" (two-tree merge).
Git checkout $branch already populates the cache-tree; this is due to patches I added last year:
commit aecf567cbfb6ab46e82f7f5df36fb6a2dd5bee69
Author: David Turner <[email protected]> Date: Sat Jul 5 21:06:56 2014 -0700
cache-tree: create/update cache-tree on checkout
When git checkout checks out a branch, create or update the cache-tree so that subsequent operations are faster.
----
Admittedly, we do not test for the case where we must do a two-way merge during a checkout, but I just tested that case, and it appears that we do already populate the cache-tree in that case.
Quoted 4 lines · David Turner
Git checkout $branch already populates the cache-tree; this is due to patches I added last year:
commit
aecf567cbfb6ab46e82f7f5df36fb6a2dd5bee69
Heh, our mails crossed ;-)
Thanks.
Quoted 11 lines · David Turner
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 <[email protected]>Signed-off-by Brian Degenhardt <[email protected]>---
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.
I'd need to tweak the From:/Author: line then, and flip the order of the sign-off, as Brian wrote and signed off then David relayed (as attached).
Quoted 5 lines
unpack-trees.c +0
-0
unpack-trees.c int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options · line 1164
Quoted 9 lines
unpack-trees.c +6
-0@@ -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 ); + }
This does the cache-tree thing unconditionally, not "on successful merge". cache_tree_update() would refuse when it sees an unmerged entry, but somehow the discrepancy between the title and the code bothers me.
By the way, I wonder if we can lose/revert aecf567c (cache-tree:
create/update cache-tree on checkout, 2014-07-05), now the underlying unpack_trees() does the necessary cache_tree_update() when a branch is checked out.
Thanks.
-- >8 --
From: Brian Degenhardt <[email protected]>
Date: Tue, 28 Jul 2015 15:30:40 -0400
Subject: [PATCH] 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.
--- t/t0090-cache-tree.sh | 24 ++++++++++++++++++++++++ unpack-trees.c | 8 ++++++++ 2 files changed, 32 insertions(+)
t/t0090-cache-tree.sh +24 -0
@@ -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 &&
unpack-trees.c +8 -0
@@ -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 {
Signature · 1 line
2.5.0-370-gf964943
Quoted 11 lines · Junio C Hamano
Quoted 9 lines · David Turner
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 <[email protected]>Signed-off-by Brian Degenhardt <[email protected]>---
Quoted 6 lines
Quoted 2 lines
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.
I'd need to tweak the From:/Author: line then, and flip the order of the sign-off, as Brian wrote and signed off then David relayed (as attached).
Where do I put an Author: line? In the commit message above the signoffs? As an email header? I didn't see an option to git send-email that would do this. I don't want to use the From: header because I want to be the point-of-contact for these patches.
Quoted 20 lines
Quoted 5 lines
unpack-trees.c +0
-0unpack-trees.c int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options · line 1164
Quoted 9 lines
unpack-trees.c +6
-0@@ -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 ); + }This does the cache-tree thing unconditionally, not "on successful merge".
cache_tree_update()would refuse when it sees an unmerged entry, but somehow the discrepancy between the title and the code bothers me.
Quoted 4 lines
By the way, I wonder if we can lose/revert
aecf567c(cache-tree:
create/update cache-tree on checkout, 2014-07-05), now the underlyingunpack_trees()does the necessarycache_tree_update()when a branch is checked out.
Well, the tests still pass, so I guess so. That is, we still need the WRITE_TREE_REPAIR bit, but not the update check.
Will re-roll once I hear back on the author line.
Quoted 15 lines · David Turner
Quoted 14 lines · Junio C Hamano
Quoted 11 lines · David Turner
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 <[email protected]>Signed-off-by Brian Degenhardt <[email protected]>---
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.
Quoted 8 lines
Quoted 3 lines
I'd need to tweak the From:/Author: line then, and flip the order of the sign-off, as Brian wrote and signed off then David relayed (as attached).
Where do I put an Author: line? In the commit message above the signoffs? As an email header? I didn't see an option to git send-email that would do this. I don't want to use the From: header because I want to be the point-of-contact for these patches.
The message you are responding to would have been a good example of forcing the author, subject and author-date to be different from the e-mail headers. That is, if you did "git am -s -c" on my message you responded to, you would have seen a new commit authored by Brian; and anybody responding to the message would have sent that e-mail to me (and [email protected]).
I think that is the arrangement you are looking for.
Delete everything before and including the "-- >8 --" line from my message you responded to and then the person who applies does not have to say "-c" but just with "git am -s" the same thing would have happened. E-mail coming from (and reply going to) you, but resulting commit would be authored by Brian.
"git send-email", if you are sending somebody else's commit, should automatically add the in-body header "From: Brian ..." as the first line of the body, with a blank line and the body of the commit log.
Quoted 9 lines
Quoted 4 lines
By the way, I wonder if we can lose/revert
aecf567c(cache-tree:
create/update cache-tree on checkout, 2014-07-05), now the underlyingunpack_trees()does the necessarycache_tree_update()when a branch is checked out.Well, the tests still pass, so I guess so. That is, we still need the
WRITE_TREE_REPAIRbit, but not the update check.Will re-roll once I hear back on the author line.
Let's not do the "drop cache-tree generation from checkout" in the same patch. It can be done as a separate patch but I do not think it is a very high priority.
With that understanding, what I have received from you (with a minor tweak shown in the message you are responding to) is already fine, I think.
Thanks.