# HG changeset patch # User Martin von Zweigbergk # Date 2019-01-21 06:00:25 # Node ID 19c590ce86613239de1b1a370c08f6b4cda644e4 # Parent c9f1fd82a826c7b765581ae57a7ffab94805de1e 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 diff --git a/hgext/uncommit.py b/hgext/uncommit.py --- a/hgext/uncommit.py +++ b/hgext/uncommit.py @@ -93,13 +93,13 @@ def _commitfiltered(repo, ctx, match, ke 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 @@ def _fixdirstate(repo, oldctx, newctx, s 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 @@ def uncommit(ui, repo, *pats, **opts): 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 @@ def unamend(ui, repo, **opts): 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) diff --git a/tests/test-unamend.t b/tests/test-unamend.t --- a/tests/test-unamend.t +++ b/tests/test-unamend.t @@ -385,9 +385,9 @@ Rename a->b, then amend b->c. After unam 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 @@ Rename a->b, then amend b->c, and workin A b a R a -BROKEN: should indicate that b was renamed to d $ hg st --copies A d + b R b