Patchwork D6502: state: moved cmdutil.STATES and utilities to state.py

login
register
mail settings
Submitter phabricator
Date June 8, 2019, 8:58 p.m.
Message ID <differential-rev-PHID-DREV-mrx7vydy32ifbwulz3eq-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/40373/
State New
Headers show

Comments

phabricator - June 8, 2019, 8:58 p.m.
taapas1128 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This commit moves `cmdutil.STATES` and adjoining functions to
  `state.py`. The existing users are updated accordingly.
  
  Tests remain unchanged.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/cmdutil.py
  mercurial/state.py

CHANGE DETAILS




To: taapas1128, #hg-reviewers
Cc: mercurial-devel
phabricator - June 8, 2019, 10:15 p.m.
martinvonz added inline comments.

INLINE COMMENTS

> state.py:126
>              msg = (_("use 'hg %s --continue' or 'hg %s --abort'") %
> -            (self.cmdname,self.cmdname))
> +            (self.cmdname, self.cmdname))
>          return msg

Nit: This should be moved to the patch that introduced the bad formatting.

> state.py:185
> +
> +def _commentlines(raw):
> +    '''Surround lineswith a comment char and a new line'''

This feels a lot like morestatus functionality and should perhaps have been left in cmdutil.py.

REPOSITORY
  rHG Mercurial

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

To: taapas1128, #hg-reviewers
Cc: martinvonz, mercurial-devel
phabricator - June 9, 2019, 12:58 p.m.
taapas1128 added inline comments.

INLINE COMMENTS

> martinvonz wrote in state.py:185
> This feels a lot like morestatus functionality and should perhaps have been left in cmdutil.py.

`morestatus` functionality is left in `cmdutil.py` only the place where it checks for unfinished states that is `_morestatus` has been moved here.

REPOSITORY
  rHG Mercurial

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

To: taapas1128, #hg-reviewers
Cc: martinvonz, mercurial-devel
phabricator - June 9, 2019, 12:59 p.m.
taapas1128 added inline comments.

INLINE COMMENTS

> taapas1128 wrote in state.py:185
> `morestatus` functionality is left in `cmdutil.py` only the place where it checks for unfinished states that is `_morestatus` has been moved here.

`_getrepostate` not more status

REPOSITORY
  rHG Mercurial

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

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

Patch

diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -123,7 +123,7 @@ 
             msg = _("use 'hg transplant --continue' or 'hg update' to abort")
         else:
             msg = (_("use 'hg %s --continue' or 'hg %s --abort'") %
-            (self.cmdname,self.cmdname))
+            (self.cmdname, self.cmdname))
         return msg
 
     def msg(self):
@@ -181,3 +181,64 @@ 
     for s in unfinishedstates:
         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):
+    # 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)
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -619,63 +619,8 @@ 
 
     return _commentlines(msg)
 
-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):
-    # 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)
-
 def morestatus(repo, fm):
-    statetuple = _getrepostate(repo)
+    statetuple = statemod._getrepostate(repo)
     label = 'status.morestatus'
     if statetuple:
         state, statedetectionpredicate, helpfulmsg = statetuple