unamend: fix unamending of renamed rename
authorMartin von Zweigbergk <martinvonz@google.com>
Sun, 20 Jan 2019 22:00:25 -0800
changeset 41341 19c590ce8661
parent 41340 c9f1fd82a826
child 41342 fe83040400b7
unamend: fix unamending of renamed rename Before this patch, we were passing in the result of a status call for a different set of commits than what we calculated copies for, which seemed suspicous to me. The rewritten version gets status and copy information from the same sets of commits. Differential Revision: https://phab.mercurial-scm.org/D5661
hgext/uncommit.py
tests/test-unamend.t
--- a/hgext/uncommit.py	Sun Jan 20 22:00:21 2019 -0800
+++ b/hgext/uncommit.py	Sun Jan 20 22:00:25 2019 -0800
@@ -93,13 +93,13 @@
                          extra=ctx.extra())
     return repo.commitctx(new)
 
-def _fixdirstate(repo, oldctx, newctx, status):
+def _fixdirstate(repo, oldctx, newctx, match=None):
     """ fix the dirstate after switching the working directory from oldctx to
     newctx which can be result of either unamend or uncommit.
     """
     ds = repo.dirstate
     copies = dict(ds.copies())
-    s = status
+    s = newctx.status(oldctx, match=match)
     for f in s.modified:
         if ds[f] == 'r':
             # modified + removed -> removed
@@ -121,11 +121,7 @@
             ds.remove(f)
 
     # Merge old parent and old working dir copies
-    oldcopies = {}
-    for f in (s.modified + s.added):
-        src = oldctx[f].renamed()
-        if src:
-            oldcopies[f] = src[0]
+    oldcopies = copiesmod.pathcopies(newctx, oldctx, match)
     oldcopies.update(copies)
     copies = dict((dst, oldcopies.get(src, src))
                   for dst, src in oldcopies.iteritems())
@@ -181,8 +177,7 @@
 
             with repo.dirstate.parentchange():
                 repo.dirstate.setparents(newid, node.nullid)
-                s = old.p1().status(old, match=match)
-                _fixdirstate(repo, old, repo[newid], s)
+                _fixdirstate(repo, old, repo[newid], match)
 
             scmutil.cleanupnodes(repo, mapping, 'uncommit', fixphase=True)
 
@@ -245,8 +240,7 @@
 
         with dirstate.parentchange():
             dirstate.setparents(newprednode, node.nullid)
-            s = repo.status(predctx, curctx)
-            _fixdirstate(repo, curctx, newpredctx, s)
+            _fixdirstate(repo, curctx, newpredctx)
 
         mapping = {curctx.node(): (newprednode,)}
         scmutil.cleanupnodes(repo, mapping, 'unamend', fixphase=True)
--- a/tests/test-unamend.t	Sun Jan 20 22:00:21 2019 -0800
+++ b/tests/test-unamend.t	Sun Jan 20 22:00:25 2019 -0800
@@ -385,9 +385,9 @@
   A b
     a
   R a
-BROKEN: should indicate that b was renamed to c
   $ hg st --copies
   A c
+    b
   R b
   $ hg revert -qa
   $ rm c
@@ -405,7 +405,7 @@
   A b
     a
   R a
-BROKEN: should indicate that b was renamed to d
   $ hg st --copies
   A d
+    b
   R b