Patchwork [8,of,9,standalone-strip] mq: extract `mq.queue.strip`

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 25, 2013, 9:26 p.m.
Message ID <80275daf409fb1712ee1.1380144411@vulgaris>
Download mbox | patch
Permalink /patch/2637/
State Accepted
Commit f0fc4d5797e1b12db6125bed48dcd3a76a6398ee
Headers show

Comments

Pierre-Yves David - Sept. 25, 2013, 9:26 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1380110857 -7200
#      Wed Sep 25 14:07:37 2013 +0200
# Node ID 80275daf409fb1712ee1448b3d74e9f005dc369d
# Parent  b85be8af20fcedd3127f9077e022368a4a1cbc1f
mq: extract `mq.queue.strip`

It does not depend on `mq.queue` anymore.

Patch

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -601,11 +601,11 @@  class queue(object):
 
         self.ui.warn(_("patch didn't work out, merging %s\n") % patch)
 
         # apply failed, strip away that rev and merge.
         hg.clean(repo, head)
-        self.strip(repo, [n], update=False, backup='strip')
+        strip(self.ui, repo, [n], update=False, backup='strip')
 
         ctx = repo[rev]
         ret = hg.merge(repo, rev)
         if ret:
             raise util.Abort(_("update returned %d") % ret)
@@ -1101,28 +1101,10 @@  class queue(object):
                 raise
             self.removeundo(repo)
         finally:
             release(wlock)
 
-    def strip(self, repo, revs, update=True, backup="all", force=None):
-        wlock = lock = None
-        try:
-            wlock = repo.wlock()
-            lock = repo.lock()
-
-            if update:
-                checklocalchanges(repo, force=force)
-                urev, p2 = repo.changelog.parents(revs[0])
-                if p2 != nullid and p2 in [x.node for x in self.applied]:
-                    urev = p2
-                hg.clean(repo, urev)
-                repo.dirstate.write()
-
-            repair.strip(self.ui, repo, revs, backup)
-        finally:
-            release(lock, wlock)
-
     def isapplied(self, patch):
         """returns (index, rev, patch)"""
         for i, a in enumerate(self.applied):
             if a.name == patch:
                 return (i, a.node, a.name)
@@ -1441,11 +1423,11 @@  class queue(object):
                     repo.dirstate.normal(f)
                 repo.setparents(qp, nullid)
             for patch in reversed(self.applied[start:end]):
                 self.ui.status(_("popping %s\n") % patch.name)
             del self.applied[start:end]
-            self.strip(repo, [rev], update=False, backup='strip')
+            strip(self.ui, repo, [rev], update=False, backup='strip')
             for s, state in repo['.'].substate.items():
                 repo['.'].sub(s).get(state)
             if self.applied:
                 self.ui.write(_("now at: %s\n") % self.applied[-1].name)
             else:
@@ -1644,12 +1626,11 @@  class queue(object):
 
                 # assumes strip can roll itself back if interrupted
                 repo.setparents(*cparents)
                 self.applied.pop()
                 self.applieddirty = True
-                self.strip(repo, [top], update=False,
-                           backup='strip')
+                strip(self.ui, repo, [top], update=False, backup='strip')
             except: # re-raises
                 repo.dirstate.invalidate()
                 raise
 
             try:
@@ -1817,11 +1798,11 @@  class queue(object):
                 pp = repo.dirstate.parents()
                 if rev in pp:
                     update = True
                 else:
                     update = False
-                self.strip(repo, [rev], update=update, backup='strip')
+                strip(self.ui, repo, [rev], update=update, backup='strip')
         if qpp:
             self.ui.warn(_("saved queue repository parents: %s %s\n") %
                          (short(qpp[0]), short(qpp[1])))
             if qupdate:
                 self.ui.status(_("updating queue directory\n"))
@@ -2298,11 +2279,11 @@  def clone(ui, source, dest=None, **opts)
     if dr.local():
         repo = dr.local()
         if qbase:
             ui.note(_('stripping applied patches from destination '
                       'repository\n'))
-            repo.mq.strip(repo, [qbase], update=False, backup=None)
+            strip(ui, repo, [qbase], update=False, backup=None)
         if not opts.get('noupdate'):
             ui.note(_('updating destination repository\n'))
             hg.update(repo, repo.changelog.tip())
 
 @command("qcommit|qci",
@@ -2942,10 +2923,28 @@  def checklocalchanges(repo, force=False,
         if checksubstate(repo):
             _("local changed subrepos found") # i18n tool detection
             raise util.Abort(_("local changed subrepos found" + excsuffix))
     return m, a, r, d
 
+def strip(ui, repo, revs, update=True, backup="all", force=None):
+    wlock = lock = None
+    try:
+        wlock = repo.wlock()
+        lock = repo.lock()
+
+        if update:
+            checklocalchanges(repo, force=force)
+            urev, p2 = repo.changelog.parents(revs[0])
+            if p2 != nullid and p2 in [x.node for x in repo.mq.applied]:
+                urev = p2
+            hg.clean(repo, urev)
+            repo.dirstate.write()
+
+        repair.strip(ui, repo, revs, backup)
+    finally:
+        release(lock, wlock)
+
 
 @command("strip",
          [
           ('r', 'rev', [], _('strip specified revision (optional, '
                                'can specify revisions without this '
@@ -2960,11 +2959,11 @@  def checklocalchanges(repo, force=False,
           ('n', '', None, _('ignored  (DEPRECATED)')),
           ('k', 'keep', None, _("do not modify working copy during strip")),
           ('B', 'bookmark', '', _("remove revs only reachable from given"
                                   " bookmark"))],
           _('hg strip [-k] [-f] [-n] [-B bookmark] [-r] REV...'))
-def strip(ui, repo, *revs, **opts):
+def stripcmd(ui, repo, *revs, **opts):
     """strip changesets and all their descendants from the repository
 
     The strip command removes the specified changesets and all their
     descendants. If the working directory has uncommitted changes, the
     operation is aborted unless the --force flag is supplied, in which
@@ -3093,12 +3092,11 @@  def strip(ui, repo, *revs, **opts):
             bookmarks.setcurrent(repo, None)
         del marks[mark]
         marks.write()
         ui.write(_("bookmark '%s' deleted\n") % mark)
 
-    repo.mq.strip(repo, revs, backup=backup, update=update,
-                  force=opts.get('force'))
+    strip(ui, repo, revs, backup=backup, update=update, force=opts.get('force'))
 
     return 0
 
 @command("qselect",
          [('n', 'none', None, _('disable all guards')),