D6484: states: moved cmdutil.unfinishedstates to state.py

taapas1128 (Taapas Agrawal) phabricator at mercurial-scm.org
Sun Jun 9 08:56:45 EDT 2019


taapas1128 updated this revision to Diff 15402.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6484?vs=15392&id=15402

REVISION DETAIL
  https://phab.mercurial-scm.org/D6484

AFFECTED FILES
  hgext/absorb.py
  hgext/fix.py
  hgext/histedit.py
  hgext/phabricator.py
  hgext/rebase.py
  hgext/record.py
  hgext/shelve.py
  hgext/strip.py
  hgext/transplant.py
  mercurial/cmdutil.py
  mercurial/commands.py
  mercurial/state.py

CHANGE DETAILS

diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -19,6 +19,8 @@
 
 from __future__ import absolute_import
 
+from .i18n import _
+
 from . import (
     error,
     util,
@@ -85,3 +87,44 @@
     def exists(self):
         """check whether the state file exists or not"""
         return self._repo.vfs.exists(self.fname)
+
+# A list of state files kept by multistep operations like graft.
+# Since graft cannot be aborted, it is considered 'clearable' by update.
+# note: bisect is intentionally excluded
+# (state file, clearable, allowcommit, error, hint)
+unfinishedstates = [
+    ('graftstate', True, False, _('graft in progress'),
+     _("use 'hg graft --continue' or 'hg graft --stop' to stop")),
+    ('updatestate', True, False, _('last update was interrupted'),
+     _("use 'hg update' to get a consistent checkout"))
+    ]
+
+def checkunfinished(repo, commit=False):
+    '''Look for an unfinished multistep operation, like graft, and abort
+    if found. It's probably good to check this right before
+    bailifchanged().
+    '''
+    # Check for non-clearable states first, so things like rebase will take
+    # precedence over update.
+    for f, clearable, allowcommit, msg, hint in unfinishedstates:
+        if clearable or (commit and allowcommit):
+            continue
+        if repo.vfs.exists(f):
+            raise error.Abort(msg, hint=hint)
+
+    for f, clearable, allowcommit, msg, hint in unfinishedstates:
+        if not clearable or (commit and allowcommit):
+            continue
+        if repo.vfs.exists(f):
+            raise error.Abort(msg, hint=hint)
+
+def clearunfinished(repo):
+    '''Check for unfinished operations (as above), and clear the ones
+    that are clearable.
+    '''
+    for f, clearable, allowcommit, msg, hint in unfinishedstates:
+        if not clearable and repo.vfs.exists(f):
+            raise error.Abort(msg, hint=hint)
+    for f, clearable, allowcommit, msg, hint in unfinishedstates:
+        if clearable and repo.vfs.exists(f):
+            util.unlink(repo.vfs.join(f))
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -617,7 +617,7 @@
     if date:
         opts['date'] = dateutil.parsedate(date)
 
-    cmdutil.checkunfinished(repo)
+    statemod.checkunfinished(repo)
     cmdutil.bailifchanged(repo)
     node = scmutil.revsingle(repo, rev).node()
 
@@ -846,7 +846,7 @@
         """common used update sequence"""
         if noupdate:
             return
-        cmdutil.checkunfinished(repo)
+        statemod.checkunfinished(repo)
         cmdutil.bailifchanged(repo)
         return hg.clean(repo, node, show_stats=show_stats)
 
@@ -1663,7 +1663,7 @@
         # Let --subrepos on the command line override config setting.
         ui.setconfig('ui', 'commitsubrepos', True, 'commit')
 
-    cmdutil.checkunfinished(repo, commit=True)
+    statemod.checkunfinished(repo, commit=True)
 
     branch = repo[None].branch()
     bheads = repo.branchheads(branch)
@@ -1693,7 +1693,7 @@
         # Note: eventually this guard will be removed. Please do not expect
         # this behavior to remain.
         if not obsolete.isenabled(repo, obsolete.createmarkersopt):
-            cmdutil.checkunfinished(repo)
+            statemod.checkunfinished(repo)
 
         node = cmdutil.amend(ui, repo, old, extra, pats, opts)
         if node == old.node():
@@ -2472,7 +2472,7 @@
     else:
         if not revs:
             raise error.Abort(_('no revisions specified'))
-        cmdutil.checkunfinished(repo)
+        statemod.checkunfinished(repo)
         cmdutil.bailifchanged(repo)
         revs = scmutil.revrange(repo, revs)
 
@@ -3474,7 +3474,7 @@
 
     with repo.wlock():
         if update:
-            cmdutil.checkunfinished(repo)
+            statemod.checkunfinished(repo)
             if (exact or not opts.get('force')):
                 cmdutil.bailifchanged(repo)
 
@@ -6122,8 +6122,7 @@
         updatecheck = 'none'
 
     with repo.wlock():
-        cmdutil.clearunfinished(repo)
-
+        statemod.clearunfinished(repo)
         if date:
             rev = cmdutil.finddate(ui, repo, date)
 
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -42,6 +42,7 @@
     rewriteutil,
     scmutil,
     smartset,
+    state as statemod,
     subrepoutil,
     templatekw,
     templater,
@@ -265,7 +266,7 @@
         will be left in place, so the user can continue working.
         """
 
-        checkunfinished(repo, commit=True)
+        statemod.checkunfinished(repo, commit=True)
         wctx = repo[None]
         merge = len(wctx.parents()) > 1
         if merge:
@@ -3289,47 +3290,6 @@
 #  - (desturl,   destbranch,   destpeer,   outgoing)
 summaryremotehooks = util.hooks()
 
-# A list of state files kept by multistep operations like graft.
-# Since graft cannot be aborted, it is considered 'clearable' by update.
-# note: bisect is intentionally excluded
-# (state file, clearable, allowcommit, error, hint)
-unfinishedstates = [
-    ('graftstate', True, False, _('graft in progress'),
-     _("use 'hg graft --continue' or 'hg graft --stop' to stop")),
-    ('updatestate', True, False, _('last update was interrupted'),
-     _("use 'hg update' to get a consistent checkout"))
-    ]
-
-def checkunfinished(repo, commit=False):
-    '''Look for an unfinished multistep operation, like graft, and abort
-    if found. It's probably good to check this right before
-    bailifchanged().
-    '''
-    # Check for non-clearable states first, so things like rebase will take
-    # precedence over update.
-    for f, clearable, allowcommit, msg, hint in unfinishedstates:
-        if clearable or (commit and allowcommit):
-            continue
-        if repo.vfs.exists(f):
-            raise error.Abort(msg, hint=hint)
-
-    for f, clearable, allowcommit, msg, hint in unfinishedstates:
-        if not clearable or (commit and allowcommit):
-            continue
-        if repo.vfs.exists(f):
-            raise error.Abort(msg, hint=hint)
-
-def clearunfinished(repo):
-    '''Check for unfinished operations (as above), and clear the ones
-    that are clearable.
-    '''
-    for f, clearable, allowcommit, msg, hint in unfinishedstates:
-        if not clearable and repo.vfs.exists(f):
-            raise error.Abort(msg, hint=hint)
-    for f, clearable, allowcommit, msg, hint in unfinishedstates:
-        if clearable and repo.vfs.exists(f):
-            util.unlink(repo.vfs.join(f))
-
 afterresolvedstates = [
     ('graftstate',
      _('hg graft --continue')),
diff --git a/hgext/transplant.py b/hgext/transplant.py
--- a/hgext/transplant.py
+++ b/hgext/transplant.py
@@ -35,6 +35,7 @@
     revset,
     scmutil,
     smartset,
+    state as statemod,
     util,
     vfs as vfsmod,
 )
@@ -675,7 +676,7 @@
         if not tp.canresume():
             raise error.Abort(_('no transplant to continue'))
     else:
-        cmdutil.checkunfinished(repo)
+        statemod.checkunfinished(repo)
         cmdutil.bailifchanged(repo)
 
     sourcerepo = opts.get('source')
@@ -757,7 +758,7 @@
     return n and nodemod.hex(n) or ''
 
 def extsetup(ui):
-    cmdutil.unfinishedstates.append(
+    statemod.unfinishedstates.append(
         ['transplant/journal', True, False, _('transplant in progress'),
          _("use 'hg transplant --continue' or 'hg update' to abort")])
 
diff --git a/hgext/strip.py b/hgext/strip.py
--- a/hgext/strip.py
+++ b/hgext/strip.py
@@ -18,6 +18,7 @@
     registrar,
     repair,
     scmutil,
+    state as statemod,
     util,
 )
 nullid = nodemod.nullid
@@ -47,7 +48,7 @@
     return inclsubs
 
 def checklocalchanges(repo, force=False, excsuffix=''):
-    cmdutil.checkunfinished(repo)
+    statemod.checkunfinished(repo)
     s = repo.status()
     if not force:
         if s.modified or s.added or s.removed or s.deleted:
diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -48,6 +48,7 @@
     registrar,
     repair,
     scmutil,
+    state as statemod,
     templatefilters,
     util,
     vfs as vfsmod,
@@ -445,7 +446,7 @@
 def createcmd(ui, repo, pats, opts):
     """subcommand that creates a new shelve"""
     with repo.wlock():
-        cmdutil.checkunfinished(repo)
+        statemod.checkunfinished(repo)
         return _docreatecmd(ui, repo, pats, opts)
 
 def _docreatecmd(ui, repo, pats, opts):
@@ -935,7 +936,7 @@
     abortf = opts.get('abort')
     continuef = opts.get('continue')
     if not abortf and not continuef:
-        cmdutil.checkunfinished(repo)
+        statemod.checkunfinished(repo)
     shelved = list(shelved)
     if opts.get("name"):
         shelved.append(opts["name"])
@@ -1139,9 +1140,10 @@
         return createcmd(ui, repo, pats, opts)
 
 def extsetup(ui):
-    cmdutil.unfinishedstates.append(
+    statemod.unfinishedstates.append(
         [shelvedstate._filename, False, False,
          _('unshelve already in progress'),
          _("use 'hg unshelve --continue' or 'hg unshelve --abort'")])
     cmdutil.afterresolvedstates.append(
         [shelvedstate._filename, _('hg unshelve --continue')])
+
diff --git a/hgext/record.py b/hgext/record.py
--- a/hgext/record.py
+++ b/hgext/record.py
@@ -19,6 +19,7 @@
     error,
     extensions,
     registrar,
+    state as statemod,
 )
 
 cmdtable = {}
@@ -119,7 +120,7 @@
 
     overrides = {('experimental', 'crecord'): False}
     with ui.configoverride(overrides, 'record'):
-        cmdutil.checkunfinished(repo)
+        statemod.checkunfinished(repo)
         cmdutil.dorecord(ui, repo, committomq, cmdsuggest, False,
                          cmdutil.recordfilter, *pats, **opts)
 
diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -1064,7 +1064,7 @@
         raise error.Abort(_('cannot specify both a revision and a source'))
 
     if not inmemory:
-        cmdutil.checkunfinished(repo)
+        statemod.checkunfinished(repo)
         cmdutil.bailifchanged(repo)
 
     if ui.configbool('commands', 'rebase.requiredest') and not destf:
@@ -1144,7 +1144,7 @@
            rebase_rebasing_wcp=rebasingwcp)
     if inmemory and rebasingwcp:
         # Check these since we did not before.
-        cmdutil.checkunfinished(repo)
+        statemod.checkunfinished(repo)
         cmdutil.bailifchanged(repo)
 
     if not destf:
@@ -1819,7 +1819,7 @@
                 ui.debug('--update and --rebase are not compatible, ignoring '
                          'the update flag\n')
 
-            cmdutil.checkunfinished(repo)
+            statemod.checkunfinished(repo)
             cmdutil.bailifchanged(repo, hint=_('cannot pull with rebase: '
                 'please commit or shelve your changes first'))
 
@@ -1947,7 +1947,7 @@
     entry[1].append(('t', 'tool', '',
                      _("specify merge tool for rebase")))
     cmdutil.summaryhooks.add('rebase', summaryhook)
-    cmdutil.unfinishedstates.append(
+    statemod.unfinishedstates.append(
         ['rebasestate', False, False, _('rebase in progress'),
          _("use 'hg rebase --continue' or 'hg rebase --abort'")])
     cmdutil.afterresolvedstates.append(
diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -64,6 +64,7 @@
     registrar,
     scmutil,
     smartset,
+    state as statemod,
     tags,
     templateutil,
     url as urlmod,
@@ -522,7 +523,7 @@
     if not revs:
         raise error.Abort(_(b'phabsend requires at least one changeset'))
     if opts.get(b'amend'):
-        cmdutil.checkunfinished(repo)
+        statemod.checkunfinished(repo)
 
     # {newnode: (oldnode, olddiff, olddrev}
     oldmap = getoldnodedrevmap(repo, [repo[r].node() for r in revs])
diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -1483,7 +1483,7 @@
     try:
         keep = opts.get('keep')
         revs = opts.get('rev', [])[:]
-        cmdutil.checkunfinished(repo)
+        statemod.checkunfinished(repo)
         cmdutil.bailifchanged(repo)
 
         if os.path.exists(os.path.join(repo.path, 'histedit-state')):
@@ -1915,7 +1915,7 @@
     rules = opts.get('commands', '')
     force = opts.get('force')
 
-    cmdutil.checkunfinished(repo)
+    statemod.checkunfinished(repo)
     cmdutil.bailifchanged(repo)
 
     topmost = repo.dirstate.p1()
@@ -2288,7 +2288,7 @@
 
 def extsetup(ui):
     cmdutil.summaryhooks.add('histedit', summaryhook)
-    cmdutil.unfinishedstates.append(
+    statemod.unfinishedstates.append(
         ['histedit-state', False, True, _('histedit in progress'),
          _("use 'hg histedit --continue' or 'hg histedit --abort'")])
     cmdutil.afterresolvedstates.append(
diff --git a/hgext/fix.py b/hgext/fix.py
--- a/hgext/fix.py
+++ b/hgext/fix.py
@@ -101,6 +101,7 @@
     pycompat,
     registrar,
     scmutil,
+    state as statemod,
     util,
     worker,
 )
@@ -299,7 +300,7 @@
     for rev in revs:
         checkfixablectx(ui, repo, repo[rev])
     if revs:
-        cmdutil.checkunfinished(repo)
+        statemod.checkunfinished(repo)
         checknodescendants(repo, revs)
     if opts.get('working_dir'):
         revs.add(wdirrev)
diff --git a/hgext/absorb.py b/hgext/absorb.py
--- a/hgext/absorb.py
+++ b/hgext/absorb.py
@@ -51,6 +51,7 @@
     pycompat,
     registrar,
     scmutil,
+    state as statemod,
     util,
 )
 from mercurial.utils import (
@@ -1008,7 +1009,7 @@
 
     with repo.wlock(), repo.lock():
         if not opts['dry_run']:
-            cmdutil.checkunfinished(repo)
+            statemod.checkunfinished(repo)
 
         state = absorb(ui, repo, pats=pats, opts=opts)
         if sum(s[0] for s in state.chunkstats.values()) == 0:



To: taapas1128, durin42, martinvonz, #hg-reviewers
Cc: pulkit, mjpieters, Kwan, mercurial-devel


More information about the Mercurial-devel mailing list