Patchwork D6503: statecheck: added support for STATES

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

Comments

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

REVISION SUMMARY
  This removes `STATES` from `state.py` and adds support to
  `statecheck` class to handle its features.
  `getrepostate()` function is modified accordingly.
  
  Results of tests are shown.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  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
Cc: mercurial-devel
phabricator - June 10, 2019, 1:44 p.m.
pulkit added inline comments.

INLINE COMMENTS

> state.py:147
>  
>      def isunfinished(self, repo, mergecheck=False):
> +        """determines whether a multi-step operation is in progress

This change should be a part of patch where isunfinished was introduced.

> state.py:158
>  unfinishedstates=[]
> -unfinishedstates.append(statecheck('graft','graftstate', clearable=True,
> -                                    allowcommit=False))
> +unfinishedstates.append(statecheck('graft', 'graftstate', clearable=True,
> +                                   allowcommit=False))

This adding of space should also be a part of patch where this line was introduced.

> state.py:167
>                                      allowcommit=False))
> +unfinishedstates.append(statecheck('merge', 'None', clearable=False,
> +                                    allowcommit=False, specialhint=

merge can be cleared using `hg update` and hence clearable should be `True`

REPOSITORY
  rHG Mercurial

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

To: taapas1128, durin42, #hg-reviewers
Cc: pulkit, mercurial-devel
phabricator - June 10, 2019, 2:58 p.m.
taapas1128 marked 3 inline comments as done.
taapas1128 added inline comments.

INLINE COMMENTS

> pulkit wrote in state.py:147
> This change should be a part of patch where isunfinished was introduced.

mergecheck is introduced in this patch now so now this change must be okay I suppose.

REPOSITORY
  rHG Mercurial

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

To: taapas1128, durin42, #hg-reviewers
Cc: pulkit, mercurial-devel
phabricator - June 10, 2019, 11:03 p.m.
pulkit added inline comments.

INLINE COMMENTS

> state.py:186
> -
> -def _helpmessage(continuecmd, abortcmd):
> -    msg = _('To continue:    %s\n'

the previous patch moves all this code, and this patch just removes it mostly. I think we can prevent the code-movement then.

REPOSITORY
  rHG Mercurial

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

To: taapas1128, durin42, #hg-reviewers
Cc: pulkit, mercurial-devel
phabricator - June 11, 2019, 8:21 a.m.
taapas1128 added a subscriber: martinvonz.
taapas1128 added inline comments.

INLINE COMMENTS

> pulkit wrote in state.py:186
> the previous patch moves all this code, and this patch just removes it mostly. I think we can prevent the code-movement then.

Yes but this is according to the splitting @martinvonz suggested. The same thing happens between https://phab.mercurial-scm.org/D6484 and https://phab.mercurial-scm.org/D6501. Actually this is done for the benefit of the reviewer so he/she can see how the code changed (here `_getrepostate()` function.

REPOSITORY
  rHG Mercurial

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

To: taapas1128, durin42, #hg-reviewers
Cc: 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
@@ -115,8 +115,15 @@ 
 
     def hint(self):
         """returns the hint message corresponding to the command"""
-        if self.cmdname == 'graft':
+        if self.cmdname == 'bisect':
+            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')
+        elif self.cmdname == 'graft':
             msg = _("use 'hg graft --continue' or 'hg graft --stop' to stop")
+        elif self.cmdname == 'merge':
+            msg = _('To continue:    hg commit\n'
+                    'To abort:       hg merge --abort')
         elif self.cmdname == 'update':
             msg = _("use 'hg update' to get a consistent checkout")
         elif self.cmdname == 'transplant':
@@ -146,9 +153,13 @@ 
             return repo.vfs.exists(self.fname)
 
 unfinishedstates=[]
-unfinishedstates.append(statecheck('graft','graftstate', clearable=True,
+unfinishedstates.append(statecheck('graft', 'graftstate', clearable=True,
+                                   allowcommit=False))
+unfinishedstates.append(statecheck('bisect', 'bisect.state', clearable=False,
+                                   allowcommit=True))
+unfinishedstates.append(statecheck('update', 'updatestate', clearable=True,
                                     allowcommit=False))
-unfinishedstates.append(statecheck('update', 'updatestate', clearable=True,
+unfinishedstates.append(statecheck('merge', 'None', clearable=False,
                                     allowcommit=False))
 
 def checkunfinished(repo, commit=False):
@@ -159,13 +170,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 == 'merge'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 == 'merge' or s.cmdname == 'bisect'):
             continue
         if s.isunfinished(repo):
             raise error.Abort(s.msg(), hint=s.hint())
@@ -175,70 +188,34 @@ 
     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 (state.cmdname == 'merge' or state.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.isunfinished(repo),
+                    state.hint())
+
+    for s in unfinishedstates:
+        if s.cmdname in skip:
+            continue
+        if s.cmdname == 'update' and s.isunfinished(repo):
+            return (s.cmdname, s.isunfinished(repo),
+                    s.hint())
+        if s.cmdname == 'merge' and s.isunfinished(repo):
+            return (s.cmdname, s.isunfinished(repo),
+                    s.hint())
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -620,7 +620,7 @@ 
     return _commentlines(msg)
 
 def morestatus(repo, fm):
-    statetuple = statemod._getrepostate(repo)
+    statetuple = statemod.getrepostate(repo)
     label = 'status.morestatus'
     if statetuple:
         state, statedetectionpredicate, helpfulmsg = statetuple
@@ -630,8 +630,7 @@ 
         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):
     """