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

Paul Morelle paul.morelle at octobus.net
Fri Oct 6 08:48:49 UTC 2017


# HG changeset patch
# User Paul Morelle <madprog at htkc.org>
# Date 1507209094 -7200
#      Thu Oct 05 15:11:34 2017 +0200
# Node ID bbba17e8f85bdae96c769c7b4c506e9631165b66
# Parent  c67db5dc131d0facdfdadc8c3344a8f3e689867d
# EXP-Topic issue-5540
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 c67db5dc131d -r bbba17e8f85b hgext/strip.py
--- a/hgext/strip.py	Sun Oct 01 12:12:56 2017 +0100
+++ 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