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

Paul Morelle paul.morelle at octobus.net
Fri Oct 6 16:17:16 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 ae82f66cd58f85264e756f7a718ae9fbae5f17db
# Parent  a57c938e7ac8f391a62de6c7c4d5cf0e81b2dcf4
# EXP-Topic issue-5540
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r ae82f66cd58f
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 a57c938e7ac8 -r ae82f66cd58f hgext/strip.py
--- a/hgext/strip.py	Fri Sep 29 15:48:34 2017 +0000
+++ 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 _find_update_target(repo, revs):
+    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
+
+    return urev
+
 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 = _find_update_target(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 = _find_update_target(repo, revs)
             uctx = repo[urev]
 
             # only reset the dirstate for files that would actually change


More information about the Mercurial-devel mailing list