Patchwork [2,of,9,standalone-strip] mq: extract checksubstate from the queue class

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 25, 2013, 9:26 p.m.
Message ID <c29d0955623f64388447.1380144405@vulgaris>
Download mbox | patch
Permalink /patch/2631/
State Accepted
Commit 76796fe65badd0040b6fd8605178be38a3500011
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 1380101083 -7200
#      Wed Sep 25 11:24:43 2013 +0200
# Node ID c29d0955623f6438844740dcdb9982c9055f4926
# Parent  9c5cdf575aad77dd2e4f0ba155abecfeae85de51
mq: extract checksubstate from the queue class

This function does not need any of the the `mq.queue` method or attributes. It
is indirectly used by the `strip` command. We are trying to extract this command
in a standalone extension as discussed in issue issue3824.

Patch

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -943,27 +943,10 @@  class queue(object):
             if repo.dirstate.p1() != top:
                 raise util.Abort(_("working directory revision is not qtip"))
             return top, patch
         return None, None
 
-    def checksubstate(self, repo, baserev=None):
-        '''return list of subrepos at a different revision than substate.
-        Abort if any subrepos have uncommitted changes.'''
-        inclsubs = []
-        wctx = repo[None]
-        if baserev:
-            bctx = repo[baserev]
-        else:
-            bctx = wctx.parents()[0]
-        for s in sorted(wctx.substate):
-            if wctx.sub(s).dirty(True):
-                raise util.Abort(
-                    _("uncommitted changes in subrepository %s") % s)
-            elif s not in bctx.substate or bctx.sub(s).dirty():
-                inclsubs.append(s)
-        return inclsubs
-
     def putsubstate2changes(self, substatestate, changes):
         for files in changes[:3]:
             if '.hgsubstate' in files:
                 return # already listed up
         # not yet listed up
@@ -985,11 +968,11 @@  class queue(object):
         m, a, r, d = repo.status()[:4]
         if not force:
             if (m or a or r or d):
                 _("local changes found") # i18n tool detection
                 raise util.Abort(_("local changes found" + excsuffix))
-            if self.checksubstate(repo):
+            if checksubstate(repo):
                 _("local changed subrepos found") # i18n tool detection
                 raise util.Abort(_("local changed subrepos found" + excsuffix))
         return m, a, r, d
 
     _reserved = ('series', 'status', 'guards', '.', '..')
@@ -1029,11 +1012,11 @@  class queue(object):
         if date:
             date = util.parsedate(date)
         diffopts = self.diffopts({'git': opts.get('git')})
         if opts.get('checkname', True):
             self.checkpatchname(patchfn)
-        inclsubs = self.checksubstate(repo)
+        inclsubs = checksubstate(repo)
         if inclsubs:
             inclsubs.append('.hgsubstate')
             substatestate = repo.dirstate['.hgsubstate']
         if opts.get('include') or opts.get('exclude') or pats:
             if inclsubs:
@@ -1503,11 +1486,11 @@  class queue(object):
                                  hint=_('see "hg help phases" for details'))
 
             cparents = repo.changelog.parents(top)
             patchparent = self.qparents(repo, top)
 
-            inclsubs = self.checksubstate(repo, hex(patchparent))
+            inclsubs = checksubstate(repo, hex(patchparent))
             if inclsubs:
                 inclsubs.append('.hgsubstate')
                 substatestate = repo.dirstate['.hgsubstate']
 
             ph = patchheader(self.join(patchfn), self.plainmode)
@@ -2929,10 +2912,28 @@  def save(ui, repo, **opts):
         del q.applied[:]
         q.applieddirty = True
         q.savedirty()
     return 0
 
+def checksubstate(repo, baserev=None):
+    '''return list of subrepos at a different revision than substate.
+    Abort if any subrepos have uncommitted changes.'''
+    inclsubs = []
+    wctx = repo[None]
+    if baserev:
+        bctx = repo[baserev]
+    else:
+        bctx = wctx.parents()[0]
+    for s in sorted(wctx.substate):
+        if wctx.sub(s).dirty(True):
+            raise util.Abort(
+                _("uncommitted changes in subrepository %s") % s)
+        elif s not in bctx.substate or bctx.sub(s).dirty():
+            inclsubs.append(s)
+    return inclsubs
+
+
 @command("strip",
          [
           ('r', 'rev', [], _('strip specified revision (optional, '
                                'can specify revisions without this '
                                'option)'), _('REV')),