Patchwork D6503: statecheck: added support for STATES

login
register
mail settings
Submitter phabricator
Date June 13, 2019, 1:21 p.m.
Message ID <f795cdfdc9ee6c8c44eea079ef912fe0@localhost.localdomain>
Download mbox | patch
Permalink /patch/40472/
State Not Applicable
Headers show

Comments

phabricator - June 13, 2019, 1:21 p.m.
Herald added a reviewer: martinvonz.
Herald added a subscriber: mjpieters.
taapas1128 edited the summary of this revision.
taapas1128 updated this revision to Diff 15480.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6503?vs=15440&id=15480

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6503/new/

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

AFFECTED FILES
  hgext/histedit.py
  hgext/rebase.py
  hgext/shelve.py
  hgext/transplant.py
  mercurial/cmdutil.py
  mercurial/state.py
  tests/test-graft.t
  tests/test-histedit-fold.t
  tests/test-rebase-conflicts.t
  tests/test-shelve.t

CHANGE DETAILS




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

Patch

diff --git a/tests/test-shelve.t b/tests/test-shelve.t
--- a/tests/test-shelve.t
+++ b/tests/test-shelve.t
@@ -375,8 +375,7 @@ 
   # 
   # To mark files as resolved:  hg resolve --mark FILE
   
-  # To continue:    hg unshelve --continue
-  # To abort:       hg unshelve --abort
+  # use 'hg unshelve --continue' or 'hg unshelve --abort'
   
 
 ensure that we have a merge with unresolved conflicts
diff --git a/tests/test-rebase-conflicts.t b/tests/test-rebase-conflicts.t
--- a/tests/test-rebase-conflicts.t
+++ b/tests/test-rebase-conflicts.t
@@ -80,8 +80,7 @@ 
   # 
   # To mark files as resolved:  hg resolve --mark FILE
   
-  # To continue:    hg rebase --continue
-  # To abort:       hg rebase --abort
+  # use 'hg rebase --continue' or 'hg rebase --abort'
   
 
 Try to continue without solving the conflict:
diff --git a/tests/test-histedit-fold.t b/tests/test-histedit-fold.t
--- a/tests/test-histedit-fold.t
+++ b/tests/test-histedit-fold.t
@@ -306,8 +306,7 @@ 
   # 
   # To mark files as resolved:  hg resolve --mark FILE
   
-  # To continue:    hg histedit --continue
-  # To abort:       hg histedit --abort
+  # use 'hg histedit --continue' or 'hg histedit --abort'
   
   $ hg resolve -l
   U file
diff --git a/tests/test-graft.t b/tests/test-graft.t
--- a/tests/test-graft.t
+++ b/tests/test-graft.t
@@ -278,8 +278,7 @@ 
   # 
   # To mark files as resolved:  hg resolve --mark FILE
   
-  # To continue:    hg graft --continue
-  # To abort:       hg graft --abort
+  # use 'hg graft --continue' or 'hg graft --stop' to stop
   
 
 Commit while interrupted should fail:
diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -22,6 +22,7 @@ 
 from .i18n import _
 
 from . import (
+    cmdutil,
     error,
     util,
 )
@@ -134,18 +135,53 @@ 
         return self._cmdmsg
 
     def isunfinished(self, repo):
-        """determines whether a multi-step operation is in progress or not"""
-        return repo.vfs.exists(self._fname)
+        """determines whether a multi-step operation is in progress
+        or not
+        mergecheck flag helps in determining state specifically for merge
+        """
+        if self._cmdname == 'merge':
+            return len(repo[None].parents()) > 1
+        else:
+            return repo.vfs.exists(self._fname)
 
 # A list of statecheck objects for multistep operations like graft.
 unfinishedstates = []
-unfinishedstates.append(
-    statecheck('graft', 'graftstate', clearable=True, allowcommit=False,
-    cmdhint=_("use 'hg graft --continue' or 'hg graft --stop' to stop")))
-unfinishedstates.append(
-    statecheck('update', 'updatestate', clearable=True, allowcommit=False,
-               cmdmsg=_('last update was interrupted'),
-               cmdhint=_("use 'hg update' to get a consistent checkout")))
+graftdata = {
+    'cmdname': 'graft',
+    'fname': 'graftstate',
+    'clearable': True,
+    'allowcommit': False,
+    'cmdhint': _("use 'hg graft --continue' or 'hg graft --stop' to stop")
+}
+cmdutil.addunfinished(**graftdata)
+bisectdata = {
+    'cmdname': 'bisect',
+    'fname': 'bisect.state',
+    'clearable': False,
+    'allowcommit': True,
+    'cmdhint': _('To mark the changeset good:    hg bisect --good\n'
+                 'To mark the changeset bad:     hg bisect --bad\n'
+                 'To abort:                      hg bisect --reset\n')
+}
+cmdutil.addunfinished(**bisectdata)
+updatedata = {
+    'cmdname': 'update',
+    'fname': 'updatestate',
+    'clearable': True,
+    'allowcommit':False,
+    'cmdmsg': _('last update was interrupted'),
+    'cmdhint':_("use 'hg update' to get a consistent checkout")
+}
+cmdutil.addunfinished(**updatedata)
+mergedata = {
+    'cmdname': 'merge',
+    'fname': None,
+    'clearable': True,
+    'allowcommit': True,
+    'cmdhint': _('To continue:    hg commit\n'
+                 'To abort:       hg merge --abort')
+}
+cmdutil.addunfinished(**mergedata)
 
 def checkunfinished(repo, commit=False):
     '''Look for an unfinished multistep operation, like graft, and abort
@@ -155,13 +191,15 @@ 
     # Check for non-clearable states first, so things like rebase will take
     # precedence over update.
     for state in unfinishedstates:
-        if state._clearable or (commit and state._allowcommit):
+        if (state._clearable or (commit and state._allowcommit) or
+            state._cmdname == 'bisect'):
             continue
         if state.isunfinished(repo):
             raise error.Abort(state.msg(), hint=state.hint())
 
     for s in unfinishedstates:
-        if not s._clearable or (commit and s._allowcommit):
+        if (not s._clearable or (commit and s._allowcommit) or
+            s._cmdname == 'bisect'):
             continue
         if s.isunfinished(repo):
             raise error.Abort(s.msg(), hint=s.hint())
@@ -171,70 +209,23 @@ 
     that are clearable.
     '''
     for state in unfinishedstates:
+        if (state._cmdname == 'merge' or state._cmdname == 'bisect'):
+            continue
         if not state._clearable and state.isunfinished(repo):
             raise error.Abort(state.msg(), hint=state.hint())
 
     for s in unfinishedstates:
+        if (s._cmdname == 'merge' or s._cmdname == 'bisect'):
+            continue
         if s._clearable and s.isunfinished(repo):
             util.unlink(repo.vfs.join(s._fname))
 
-def _commentlines(raw):
-    '''Surround lineswith a comment char and a new line'''
-    lines = raw.splitlines()
-    commentedlines = ['# %s' % line for line in lines]
-    return '\n'.join(commentedlines) + '\n'
-
-def _helpmessage(continuecmd, abortcmd):
-    msg = _('To continue:    %s\n'
-            'To abort:       %s') % (continuecmd, abortcmd)
-    return _commentlines(msg)
-
-def _rebasemsg():
-    return _helpmessage('hg rebase --continue', 'hg rebase --abort')
-
-def _histeditmsg():
-    return _helpmessage('hg histedit --continue', 'hg histedit --abort')
-
-def _unshelvemsg():
-    return _helpmessage('hg unshelve --continue', 'hg unshelve --abort')
-
-def _graftmsg():
-    return _helpmessage('hg graft --continue', 'hg graft --abort')
-
-def _mergemsg():
-    return _helpmessage('hg commit', 'hg merge --abort')
-
-def _bisectmsg():
-    msg = _('To mark the changeset good:    hg bisect --good\n'
-            'To mark the changeset bad:     hg bisect --bad\n'
-            'To abort:                      hg bisect --reset\n')
-    return _commentlines(msg)
-
-def fileexistspredicate(filename):
-    return lambda repo: repo.vfs.exists(filename)
-
-def _mergepredicate(repo):
-    return len(repo[None].parents()) > 1
-
-STATES = (
-    # (state, predicate to detect states, helpful message function)
-    ('histedit', fileexistspredicate('histedit-state'), _histeditmsg),
-    ('bisect', fileexistspredicate('bisect.state'), _bisectmsg),
-    ('graft', fileexistspredicate('graftstate'), _graftmsg),
-    ('unshelve', fileexistspredicate('shelvedstate'), _unshelvemsg),
-    ('rebase', fileexistspredicate('rebasestate'), _rebasemsg),
-    # The merge state is part of a list that will be iterated over.
-    # They need to be last because some of the other unfinished states may also
-    # be in a merge or update state (eg. rebase, histedit, graft, etc).
-    # We want those to have priority.
-    ('merge', _mergepredicate, _mergemsg),
-)
-
-def _getrepostate(repo):
+def getrepostate(repo):
     # experimental config: commands.status.skipstates
     skip = set(repo.ui.configlist('commands', 'status.skipstates'))
-    for state, statedetectionpredicate, msgfn in STATES:
-        if state in skip:
-            continue
-        if statedetectionpredicate(repo):
-            return (state, statedetectionpredicate, msgfn)
+    for state in unfinishedstates:
+        if (state._cmdname == 'merge' or state._cmdname == 'update' or
+            state._cmdname in skip):
+            continue
+        if state.isunfinished(repo):
+            return (state._cmdname, state.hint())
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -619,19 +619,26 @@ 
 
     return _commentlines(msg)
 
+def addunfinished(**cmddata):
+    cmdname = cmddata['cmdname']
+    statecheckobj = statemod.statecheck(**cmddata)
+    if cmdname=='merge' or cmdname=='bisect':
+        statemod.unfinishedstates.append(statecheckobj)
+    else:
+        statemod.unfinishedstates.insert(0,statecheckobj)
+
 def morestatus(repo, fm):
-    statetuple = statemod._getrepostate(repo)
+    statetuple = statemod.getrepostate(repo)
     label = 'status.morestatus'
     if statetuple:
-        state, statedetectionpredicate, helpfulmsg = statetuple
+        state, helpfulmsg = statetuple
         statemsg = _('The repository is in an unfinished *%s* state.') % state
         fm.plain('%s\n' % _commentlines(statemsg), label=label)
         conmsg = _conflictsmsg(repo)
         if conmsg:
             fm.plain('%s\n' % conmsg, label=label)
         if helpfulmsg:
-            helpmsg = helpfulmsg()
-            fm.plain('%s\n' % helpmsg, label=label)
+            fm.plain('%s\n' % _commentlines(helpfulmsg), label=label)
 
 def findpossible(cmd, table, strict=False):
     """
diff --git a/hgext/transplant.py b/hgext/transplant.py
--- a/hgext/transplant.py
+++ b/hgext/transplant.py
@@ -758,10 +758,14 @@ 
     return n and nodemod.hex(n) or ''
 
 def extsetup(ui):
-    statemod.unfinishedstates.append(
-        statemod.statecheck('transplant', 'transplant/journal', clearable=True,
-        allowcommit=False,
-        cmdhint=_("use 'hg transplant --continue' or 'hg update' to abort")))
+    transplantdata = {
+        'cmdname': 'transplant',
+        'fname': 'transplant/journal',
+        'clearable': True,
+        'allowcommit': False,
+        'cmdhint': _("use 'hg transplant --continue' or 'hg update' to abort")
+    }
+    cmdutil.addunfinished(**transplantdata)
 
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = [revsettransplanted, kwtransplanted]
diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -1140,9 +1140,14 @@ 
         return createcmd(ui, repo, pats, opts)
 
 def extsetup(ui):
-    statemod.unfinishedstates.append(
-        statemod.statecheck('unshelve',shelvedstate._filename, clearable=False,
-        allowcommit=False, cmdmsg=_('unshelve already in progress')))
+    unshelvedata = {
+        'cmdname': 'unshelve',
+        'fname': shelvedstate._filename,
+        'clearable': False,
+        'allowcommit': False,
+        'cmdmsg': _('unshelve already in progress')
+    }
+    cmdutil.addunfinished(**unshelvedata)
     cmdutil.afterresolvedstates.append(
         [shelvedstate._filename, _('hg unshelve --continue')])
 
diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -64,6 +64,14 @@ 
 
 cmdtable = {}
 command = registrar.command(cmdtable)
+
+histeditdata = {
+    'cmdname': 'rebase',
+    'fname': 'histedit-state',
+    'clearable': False,
+    'allowcommit': True,
+}
+cmdutil.addunfinished(**histeditdata)
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
 # be specifying the version(s) of Mercurial they are tested with, or
@@ -1947,8 +1955,12 @@ 
     entry[1].append(('t', 'tool', '',
                      _("specify merge tool for rebase")))
     cmdutil.summaryhooks.add('rebase', summaryhook)
-    statemod.unfinishedstates.append(
-        statemod.statecheck('rebase', 'rebasestate', clearable=False,
-                            allowcommit=False))
+    rebasedata = {
+        'cmdname': 'rebase',
+        'fname': 'rebasestate',
+        'clearable': False,
+        'allowcommit': False
+    }
+    cmdutil.addunfinished(**rebasedata)
     cmdutil.afterresolvedstates.append(
         ['rebasestate', _('hg rebase --continue')])
diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -2288,8 +2288,12 @@ 
 
 def extsetup(ui):
     cmdutil.summaryhooks.add('histedit', summaryhook)
-    statemod.unfinishedstates.append(
-        statemod.statecheck('histedit','histedit-state',
-        clearable=False, allowcommit=True))
+    histeditdata = {
+        'cmdname': 'histedit',
+        'fname': 'histedit-state',
+        'clearable': False,
+        'allowcommit': True
+    }
+    cmdutil.addunfinished(**histeditdata)
     cmdutil.afterresolvedstates.append(
         ['histedit-state', _('hg histedit --continue')])