D971: uncommit: unify functions _uncommitdirstate and _unamenddirstate to one
pulkit (Pulkit Goyal)
phabricator at mercurial-scm.org
Thu Oct 5 22:59:35 UTC 2017
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
The _unamenddirstate() function was inspired by _uncommitdirstate() function as
the logic was same but we were unable to use the latter function directly. So
previous patch introduced the _unamenddirstate() function and now this patch
unifies both the function and we have a _fixdirstate() function.
Adding function in previous patch and unifying in a later patch makes the
reasoning easier and also leaves the last patch dedicated to what it is meant to
be.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D971
AFFECTED FILES
hgext/uncommit.py
CHANGE DETAILS
diff --git a/hgext/uncommit.py b/hgext/uncommit.py
--- a/hgext/uncommit.py
+++ b/hgext/uncommit.py
@@ -90,15 +90,13 @@
newid = repo.commitctx(new)
return newid
-def _uncommitdirstate(repo, oldctx, match):
- """Fix the dirstate after switching the working directory from
- oldctx to a copy of oldctx not containing changed files matched by
- match.
+def _fixdirstate(repo, oldctx, newctx, status):
+ """ fix the dirstate after switching the working directory from oldctx to
+ newctx which can be result of either unamend or uncommit.
"""
- ctx = repo['.']
ds = repo.dirstate
copies = dict(ds.copies())
- s = repo.status(oldctx.p1(), oldctx, match=match)
+ s = status
for f in s.modified:
if ds[f] == 'r':
# modified + removed -> removed
@@ -130,7 +128,7 @@
for dst, src in oldcopies.iteritems())
# Adjust the dirstate copies
for dst, src in copies.iteritems():
- if (src not in ctx or dst in ctx or ds[dst] != 'a'):
+ if (src not in newctx or dst in newctx or ds[dst] != 'a'):
src = None
ds.copy(src, dst)
@@ -185,54 +183,14 @@
with repo.dirstate.parentchange():
repo.dirstate.setparents(newid, node.nullid)
- _uncommitdirstate(repo, old, match)
+ s = repo.status(old.p1(), old, match=match)
+ _fixdirstate(repo, old, repo[newid], s)
def predecessormarkers(ctx):
"""yields the obsolete markers marking the given changeset as a successor"""
for data in ctx.repo().obsstore.predecessors.get(ctx.node(), ()):
yield obsutil.marker(ctx.repo(), data)
-def _unamenddirstate(repo, predctx, curctx):
- """"""
-
- s = repo.status(predctx, curctx)
- ds = repo.dirstate
- copies = dict(ds.copies())
- for f in s.modified:
- if ds[f] == 'r':
- # modified + removed -> removed
- continue
- ds.normallookup(f)
-
- for f in s.added:
- if ds[f] == 'r':
- # added + removed -> unknown
- ds.drop(f)
- elif ds[f] != 'a':
- ds.add(f)
-
- for f in s.removed:
- if ds[f] == 'a':
- # removed + added -> normal
- ds.normallookup(f)
- elif ds[f] != 'r':
- ds.remove(f)
-
- # Merge old parent and old working dir copies
- oldcopies = {}
- for f in (s.modified + s.added):
- src = curctx[f].renamed()
- if src:
- oldcopies[f] = src[0]
- oldcopies.update(copies)
- copies = dict((dst, oldcopies.get(src, src))
- for dst, src in oldcopies.iteritems())
- # Adjust the dirstate copies
- for dst, src in copies.iteritems():
- if (src not in predctx or dst in predctx or ds[dst] != 'a'):
- src = None
- ds.copy(src, dst)
-
@command('^unamend', [])
def unamend(ui, repo, **opts):
"""undo the amend operation on a current changeset
@@ -300,7 +258,8 @@
with dirstate.parentchange():
dirstate.setparents(newprednode, node.nullid)
- _unamenddirstate(repo, newpredctx, curctx)
+ s = repo.status(predctx, curctx)
+ _fixdirstate(repo, curctx, newpredctx, s)
mapping = {curctx.node(): (newprednode,)}
scmutil.cleanupnodes(repo, mapping, 'unamend')
To: pulkit, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list