diff options
author | Junio C Hamano <junkio@cox.net> | 2005-06-10 18:37:47 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-12 20:40:20 -0700 |
commit | e7f9bc411c8519468c33e1d882fb02cbe9c1ea55 (patch) | |
tree | 9085834cbda44fd94b4a1e9133f60af7872deea6 /read-tree.c | |
parent | 03efa6d9a4c974c502dbad457749ad316aac9cc6 (diff) | |
download | git-e7f9bc411c8519468c33e1d882fb02cbe9c1ea55.tar.gz git-e7f9bc411c8519468c33e1d882fb02cbe9c1ea55.tar.xz |
[PATCH] read-tree: fix too strong index requirement #5ALT
This fixes too strong index requirement 3-way merge enforces in
one case: the same file is added in both branches.
In this case, the original code insisted that if the index file
has that path, it must match our branch and be up-to-date.
However in this particular case, it only has to match it, and
can be dirty. We just need to make sure that we keep the
work-tree copy instead of checking out the merge result.
The resolution of such a path, however, cannot be left to
outside script, because we will not keep the original stage0
entries for unmerged paths when read-tree finishes, and at that
point, the knowledge of "if we resolve it to match the new file
added in both branches, the merge succeeds and the work tree
would not lose information, but we should _not_ update the work
tree from the resulting index file" is lost. For this reason,
the now code needs to resolve this case (#5ALT) internally.
This affects some existing tests in the test suite, but all in
positive ways. In t1000 (3-way test), this #5ALT case now gets
one stage0 entry, instead of an identical stage2 and stage3
entry pair, for such a path, and one test that checked for merge
failure (because the test assumed the "stricter-than-necessary"
behaviour) does not have to fail anymore. In t1005 (emu23
test), two tests that involves a case where the work tree
already had a change introduced in the upstream (aka "merged
head"), the merge succeeds instead of failing.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'read-tree.c')
-rw-r--r-- | read-tree.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/read-tree.c b/read-tree.c index f2a8bb53a..ecd40cc39 100644 --- a/read-tree.c +++ b/read-tree.c @@ -102,7 +102,7 @@ static void reject_merge(struct cache_entry *ce) die("Entry '%s' would be overwritten by merge. Cannot merge.", ce->name); } -static int merged_entry(struct cache_entry *merge, struct cache_entry *old, struct cache_entry **dst) +static int merged_entry_internal(struct cache_entry *merge, struct cache_entry *old, struct cache_entry **dst, int allow_dirty) { merge->ce_flags |= htons(CE_UPDATE); if (old) { @@ -115,7 +115,7 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old, stru */ if (same(old, merge)) { *merge = *old; - } else { + } else if (!allow_dirty) { verify_uptodate(old); } } @@ -124,6 +124,16 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old, stru return 1; } +static int merged_entry_allow_dirty(struct cache_entry *merge, struct cache_entry *old, struct cache_entry **dst) +{ + return merged_entry_internal(merge, old, dst, 1); +} + +static int merged_entry(struct cache_entry *merge, struct cache_entry *old, struct cache_entry **dst) +{ + return merged_entry_internal(merge, old, dst, 0); +} + static int deleted_entry(struct cache_entry *ce, struct cache_entry *old, struct cache_entry **dst) { if (old) @@ -140,6 +150,12 @@ static int threeway_merge(struct cache_entry *stages[4], struct cache_entry **ds struct cache_entry *merge; int count; + /* #5ALT */ + if (!a && b && c && same(b, c)) { + if (old && !same(b, old)) + return -1; + return merged_entry_allow_dirty(b, old, dst); + } /* * If we have an entry in the index cache ("old"), then we want * to make sure that it matches any entries in stage 2 ("first |