[PATCH 1 of 2 V3] strip: factor out update target selection

Paul Morelle paul.morelle at octobus.net
Tue Oct 10 09:44:42 UTC 2017


# HG changeset patch
# User Paul Morelle <paul.morelle at octobus.net>
# Date 1507209094 -7200
#      Thu Oct 05 15:11:34 2017 +0200
# Node ID adaf1c0e81c0d4f1f9dcf5c98de4410e21d76966
# Parent  8cef8f7d51d0f1e99889779ec1320d5c9c3b91de
# EXP-Topic issue-5540
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r adaf1c0e81c0
strip: factor out update target selection

The same algorithm was used in two places: one to find out which commit shall
become the parent of wdir, and the other to prepare the wdir when keeping
changes. Factoring it out prevents inconsistent changes in either occurrence.

diff -r 8cef8f7d51d0 -r adaf1c0e81c0 hgext/strip.py
--- a/hgext/strip.py	Thu Oct 05 20:41:50 2017 -0700
+++ b/hgext/strip.py	Thu Oct 05 15:11:34 2017 +0200
@@ -58,16 +58,21 @@
             raise error.Abort(_("local changed subrepos found" + excsuffix))
     return s
 
+def _findupdatetarget(repo, nodes):
+    unode, p2 = repo.changelog.parents(nodes[0])
+
+    if (util.safehasattr(repo, 'mq') and p2 != nullid
+        and p2 in [x.node for x in repo.mq.applied]):
+        unode = p2
+
+    return unode
+
 def strip(ui, repo, revs, update=True, backup=True, force=None, bookmarks=None):
     with repo.wlock(), repo.lock():
 
         if update:
             checklocalchanges(repo, force=force)
-            urev, p2 = repo.changelog.parents(revs[0])
-            if (util.safehasattr(repo, 'mq') and
-                p2 != nullid
-                and p2 in [x.node for x in repo.mq.applied]):
-                urev = p2
+            urev = _findupdatetarget(repo, revs)
             hg.clean(repo, urev)
             repo.dirstate.write(repo.currenttransaction())
 
@@ -196,10 +201,7 @@
 
         revs = sorted(rootnodes)
         if update and opts.get('keep'):
-            urev, p2 = repo.changelog.parents(revs[0])
-            if (util.safehasattr(repo, 'mq') and p2 != nullid
-                and p2 in [x.node for x in repo.mq.applied]):
-                urev = p2
+            urev = _findupdatetarget(repo, revs)
             uctx = repo[urev]
 
             # only reset the dirstate for files that would actually change


More information about the Mercurial-devel mailing list