Patchwork D8616: merge: chain copies with existing copies in working copy

login
register
mail settings
Submitter phabricator
Date June 6, 2020, 1:39 a.m.
Message ID <differential-rev-PHID-DREV-v7nthq6bk2juu5oq7orv-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46478/
State New
Headers show

Comments

phabricator - June 6, 2020, 1:39 a.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This makes the merge code chain and filter copies when grafting with
  copies already in the working copy. For example, if the working copy
  has renamed file A to B and you somehow graft in a change that renames
  B to C, then that will now become a rename from A to C.  That will
  soon be necessary for `hg rebase --collapse`. It seems that we don't
  have any existing cases where chaining makes a difference.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8616

AFFECTED FILES
  mercurial/merge.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1887,9 +1887,12 @@ 
             )
 
         wantfiledata = updatedirstate and not branchmerge
-        copies = {}
+        resulting_copies = {}
         if not overwrite:
-            copies = _extract_copies(actions, branchmerge)
+            existing_copies = wc.p2copies()
+            existing_copies.update(wc.p1copies())
+            new_copies = _extract_copies(actions, branchmerge)
+            resulting_copies = copies.chain(existing_copies, new_copies)
 
         stats, getfiledata = applyupdates(
             repo, actions, wc, p2, overwrite, wantfiledata, labels=labels
@@ -1908,7 +1911,14 @@ 
                 if not branchmerge:
                     repo.dirstate.setbranch(p2.branch())
 
-        for dst, src in copies.items():
+        # This replicates copies.filter() but is modified to work with merges
+        for dst, src in resulting_copies.items():
+            if dst == src:
+                continue
+            if dst not in wc:
+                continue
+            if not (src in wc.p1() or src in wc.p2()):
+                continue
             wc[dst].markcopied(src)
 
     # If we're updating to a location, clean up any stale temporary includes