summaryrefslogtreecommitdiff
path: root/unpack-trees.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-03-16 11:42:50 -0700
committerJunio C Hamano <gitster@pobox.com>2008-03-16 14:25:53 -0700
commit7f8ab8dc07ba4e892d0c2b5e7ac8436f9e845920 (patch)
tree005c400fe384d494b3d87843d5cf0235ea7939a1 /unpack-trees.c
parent198724ad4ef0630892e8dbbab92e92ff4f979075 (diff)
downloadgit-7f8ab8dc07ba4e892d0c2b5e7ac8436f9e845920.tar.gz
Don't update unchanged merge entries
In commit 34110cd4e394e3f92c01a4709689b384c34645d8 ("Make 'unpack_trees()' have a separate source and destination index") I introduced a really stupid bug in that it would always add merged entries with the CE_UPDATE flag set. That caused us to always re-write the file, even when it was already up-to-date in the source index. Not only is that really stupid from a performance angle, but more importantly it's actively wrong: if we have dirty state in the tree when we merge, overwriting it with the result of the merge will incorrectly overwrite that dirty state. This trivially fixes the problem - simply don't set the CE_UPDATE flag when the merge result matches the old state. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'unpack-trees.c')
-rw-r--r--unpack-trees.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/unpack-trees.c b/unpack-trees.c
index 93019abdc1..4b359e0832 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -595,16 +595,19 @@ static int verify_absent(struct cache_entry *ce, const char *action,
static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
struct unpack_trees_options *o)
{
+ int update = CE_UPDATE;
+
if (old) {
/*
* See if we can re-use the old CE directly?
* That way we get the uptodate stat info.
*
- * This also removes the UPDATE flag on
- * a match.
+ * This also removes the UPDATE flag on a match; otherwise
+ * we will end up overwriting local changes in the work tree.
*/
if (same(old, merge)) {
copy_cache_entry(merge, old);
+ update = 0;
} else {
if (verify_uptodate(old, o))
return -1;
@@ -617,7 +620,7 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
invalidate_ce_path(merge, o);
}
- add_entry(o, merge, CE_UPDATE, CE_STAGEMASK);
+ add_entry(o, merge, update, CE_STAGEMASK);
return 1;
}