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

login
register
mail settings
Submitter Paul Morelle
Date Oct. 10, 2017, 9:44 a.m.
Message ID <adaf1c0e81c0d4f1f9dc.1507628682@taranis.localdomain>
Download mbox | patch
Permalink /patch/24698/
State Accepted
Headers show

Comments

Paul Morelle - Oct. 10, 2017, 9:44 a.m.
# HG changeset patch
# User Paul Morelle <paul.morelle@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.
Yuya Nishihara - Oct. 11, 2017, 12:58 p.m.
On Tue, 10 Oct 2017 11:44:42 +0200, Paul Morelle wrote:
> # HG changeset patch
> # User Paul Morelle <paul.morelle@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

Queued this, thanks.

Patch

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