Patchwork D6503: statecheck: added support for STATES

login
register
mail settings
Submitter phabricator
Date June 18, 2019, 5:09 p.m.
Message ID <3f9a7848c86e828a1fb7cde31f132b07@localhost.localdomain>
Download mbox | patch
Permalink /patch/40591/
State Not Applicable
Headers show

Comments

phabricator - June 18, 2019, 5:09 p.m.
taapas1128 updated this revision to Diff 15584.

REPOSITORY
  rHG Mercurial

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

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

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

AFFECTED FILES
  hgext/rebase.py
  hgext/strip.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
  tests/test-strip.t
  tests/test-transplant.t

CHANGE DETAILS




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

Patch

diff --git a/tests/test-transplant.t b/tests/test-transplant.t
--- a/tests/test-transplant.t
+++ b/tests/test-transplant.t
@@ -39,7 +39,9 @@ 
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
   $ hg transplant 1
-  abort: outstanding uncommitted merge
+  abort: merge in progress
+  (To continue:    hg commit
+  To abort:       hg merge --abort)
   [255]
   $ hg up -qC tip
   $ echo b0 > b1
@@ -461,7 +463,7 @@ 
   baz
   foo
 
-test multiple revisions and --continue
+test multiple revisions, --continue and hg status --verbose
 
   $ hg up -qC 0
   $ echo bazbaz > baz
@@ -481,6 +483,14 @@ 
   abort: transplant in progress
   (use 'hg transplant --continue' or 'hg update' to abort)
   [255]
+  $ hg status -v
+  A bar
+  ? baz.rej
+  ? foo.rej
+  # The repository is in an unfinished *transplant* state.
+  
+  # use 'hg transplant --continue' or 'hg update' to abort
+  
   $ echo fixed > baz
   $ hg transplant --continue
   9d6d6b5a8275 transplanted as d80c49962290
diff --git a/tests/test-strip.t b/tests/test-strip.t
--- a/tests/test-strip.t
+++ b/tests/test-strip.t
@@ -274,7 +274,9 @@ 
   
 ##strip not allowed with merge in progress
   $ hg strip 4
-  abort: outstanding uncommitted merge
+  abort: merge in progress
+  (To continue:    hg commit
+  To abort:       hg merge --abort)
   [255]
 ##strip allowed --force with merge in progress
   $ hg strip 4 --force
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
@@ -1153,7 +1152,9 @@ 
 -- trying to pull in the shelve bits
 -- unshelve should abort otherwise, it'll eat my second parent.
   $ hg unshelve
-  abort: cannot unshelve while merging
+  abort: merge in progress
+  (To continue:    hg commit
+  To abort:       hg merge --abort)
   [255]
 
   $ cd ..
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
@@ -279,8 +279,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
@@ -134,8 +134,13 @@ 
         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
+        """
+        if self._opname == '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 = []
@@ -144,7 +149,10 @@ 
     """this registers a new command or operation to unfinishedstates
     """
     statecheckobj = _statecheck(opname, **kwargs)
-    _unfinishedstates.append(statecheckobj)
+    if opname == 'merge' or opname == 'bisect':
+        _unfinishedstates.append(statecheckobj)
+    else:
+        _unfinishedstates.insert(0, statecheckobj)
 
 addunfinished(
     'graft', fname='graftstate', clearable=True,
@@ -155,8 +163,19 @@ 
     cmdmsg=_('last update was interrupted'),
     cmdhint=_("use 'hg update' to get a consistent checkout")
 )
-
-def checkunfinished(repo, commit=False):
+addunfinished(
+    'bisect', fname='bisect.state', 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')
+)
+addunfinished(
+    'merge',fname=None, clearable=True, allowcommit=True,
+    cmdhint=_('To continue:    hg commit\n'
+              'To abort:       hg merge --abort')
+)
+
+def checkunfinished(repo, commit=False, mergeskip=False):
     '''Look for an unfinished multistep operation, like graft, and abort
     if found. It's probably good to check this right before
     bailifchanged().
@@ -164,13 +183,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._opname == '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._opname == 'merge' and mergeskip)):
             continue
         if s.isunfinished(repo):
             raise error.Abort(s.msg(), hint=s.hint())
@@ -180,70 +201,22 @@ 
     that are clearable.
     '''
     for state in _unfinishedstates:
+        if state._opname == 'bisect':
+            continue
         if not state._clearable and state.isunfinished(repo):
             raise error.Abort(state.msg(), hint=state.hint())
 
     for s in _unfinishedstates:
+        if s._opname == 'merge':
+            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):
     # 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._opname in skip:
+            continue
+        if state.isunfinished(repo):
+            return (state._opname, state.hint())
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -623,15 +623,14 @@ 
     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/strip.py b/hgext/strip.py
--- a/hgext/strip.py
+++ b/hgext/strip.py
@@ -8,6 +8,7 @@ 
 from mercurial.i18n import _
 from mercurial import (
     bookmarks as bookmarksmod,
+    cmdutil,
     error,
     hg,
     lock as lockmod,
@@ -47,10 +48,12 @@ 
     return inclsubs
 
 def checklocalchanges(repo, force=False, excsuffix=''):
-    statemod.checkunfinished(repo)
     s = repo.status()
     if not force:
+        statemod.checkunfinished(repo)
         cmdutil.bailifchanged(repo)
+    else:
+        statemod.checkunfinished(repo, mergeskip=True)
     return s
 
 def _findupdatetarget(repo, nodes):
diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -1822,7 +1822,7 @@ 
                 ui.debug('--update and --rebase are not compatible, ignoring '
                          'the update flag\n')
 
-            statemod.checkunfinished(repo)
+            statemod.checkunfinished(repo, mergeskip=True)
             cmdutil.bailifchanged(repo, hint=_('cannot pull with rebase: '
                 'please commit or shelve your changes first'))