Patchwork D6503: statecheck: added support for STATES

login
register
mail settings
Submitter phabricator
Date June 14, 2019, 8:36 a.m.
Message ID <f8a9efdbc6707dec57b8890620487195@localhost.localdomain>
Download mbox | patch
Permalink /patch/40503/
State Not Applicable
Headers show

Comments

phabricator - June 14, 2019, 8:36 a.m.
taapas1128 updated this revision to Diff 15506.

REPOSITORY
  rHG Mercurial

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

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-mq-qnew.t
  tests/test-rebase-conflicts.t
  tests/test-rebase-pull.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
diff --git a/tests/test-strip.t b/tests/test-strip.t
--- a/tests/test-strip.t
+++ b/tests/test-strip.t
@@ -273,23 +273,34 @@ 
   summary:     c
   
   $ hg strip 4
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  saved backup bundle to $TESTTMP/test/.hg/strip-backup/*-backup.hg (glob)
+  abort: merge in progress
+  (To continue:    hg commit
+  To abort:       hg merge --abort)
+  [255]
 
 after strip of merge parent
 
   $ hg parents
-  changeset:   1:ef3a871183d7
-  user:        test
-  date:        Thu Jan 01 00:00:00 1970 +0000
-  summary:     b
+  changeset:   2:65bd5f99a4a3
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     d
+  
+  changeset:   4:264128213d29
+  tag:         tip
+  parent:      1:ef3a871183d7
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     c
   
   $ restore
+  abort: $ENOENT$: '.hg/strip-backup/*'
+  rm: cannot remove '.hg/strip-backup/*': $ENOENT$
+  [1]
 
   $ hg up
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  updated to "264128213d29: c"
-  1 other heads for branch "default"
+  abort: outstanding uncommitted merge
+  [255]
   $ hg log -G
   @  changeset:   4:264128213d29
   |  tag:         tip
@@ -303,7 +314,7 @@ 
   | |  date:        Thu Jan 01 00:00:00 1970 +0000
   | |  summary:     e
   | |
-  | o  changeset:   2:65bd5f99a4a3
+  | @  changeset:   2:65bd5f99a4a3
   |/   user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
   |    summary:     d
@@ -322,42 +333,27 @@ 
 2 is parent of 3, only one strip should happen
 
   $ hg strip "roots(2)" 3
-  saved backup bundle to $TESTTMP/test/.hg/strip-backup/*-backup.hg (glob)
+  abort: merge in progress
+  (To continue:    hg commit
+  To abort:       hg merge --abort)
+  [255]
   $ hg log -G
-  @  changeset:   2:264128213d29
+  @  changeset:   4:264128213d29
   |  tag:         tip
+  |  parent:      1:ef3a871183d7
   |  user:        test
   |  date:        Thu Jan 01 00:00:00 1970 +0000
   |  summary:     c
   |
-  o  changeset:   1:ef3a871183d7
-  |  user:        test
-  |  date:        Thu Jan 01 00:00:00 1970 +0000
-  |  summary:     b
-  |
-  o  changeset:   0:9ab35a2d17cb
-     user:        test
-     date:        Thu Jan 01 00:00:00 1970 +0000
-     summary:     a
-  
-  $ restore
-  $ hg log -G
-  o  changeset:   4:443431ffac4f
-  |  tag:         tip
-  |  user:        test
-  |  date:        Thu Jan 01 00:00:00 1970 +0000
-  |  summary:     e
-  |
-  o  changeset:   3:65bd5f99a4a3
-  |  parent:      1:ef3a871183d7
-  |  user:        test
-  |  date:        Thu Jan 01 00:00:00 1970 +0000
-  |  summary:     d
-  |
-  | @  changeset:   2:264128213d29
+  | o  changeset:   3:443431ffac4f
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     e
+  | |
+  | @  changeset:   2:65bd5f99a4a3
   |/   user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
-  |    summary:     c
+  |    summary:     d
   |
   o  changeset:   1:ef3a871183d7
   |  user:        test
@@ -369,38 +365,29 @@ 
      date:        Thu Jan 01 00:00:00 1970 +0000
      summary:     a
   
-Failed hook while applying "saveheads" bundle.
-
-  $ hg strip 2 --config hooks.pretxnchangegroup.bad=false
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  saved backup bundle to $TESTTMP/test/.hg/strip-backup/*-backup.hg (glob)
-  transaction abort!
-  rollback completed
-  strip failed, backup bundle stored in '$TESTTMP/test/.hg/strip-backup/*-backup.hg' (glob)
-  strip failed, unrecovered changes stored in '$TESTTMP/test/.hg/strip-backup/*-temp.hg' (glob)
-  (fix the problem, then recover the changesets with "hg unbundle '$TESTTMP/test/.hg/strip-backup/*-temp.hg'") (glob)
-  abort: pretxnchangegroup.bad hook exited with status 1
-  [255]
   $ restore
+  abort: $ENOENT$: '.hg/strip-backup/*'
+  rm: cannot remove '.hg/strip-backup/*': $ENOENT$
+  [1]
   $ hg log -G
-  o  changeset:   4:443431ffac4f
+  @  changeset:   4:264128213d29
   |  tag:         tip
-  |  user:        test
-  |  date:        Thu Jan 01 00:00:00 1970 +0000
-  |  summary:     e
-  |
-  o  changeset:   3:65bd5f99a4a3
   |  parent:      1:ef3a871183d7
   |  user:        test
   |  date:        Thu Jan 01 00:00:00 1970 +0000
-  |  summary:     d
-  |
-  | o  changeset:   2:264128213d29
+  |  summary:     c
+  |
+  | o  changeset:   3:443431ffac4f
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     e
+  | |
+  | @  changeset:   2:65bd5f99a4a3
   |/   user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
-  |    summary:     c
-  |
-  @  changeset:   1:ef3a871183d7
+  |    summary:     d
+  |
+  o  changeset:   1:ef3a871183d7
   |  user:        test
   |  date:        Thu Jan 01 00:00:00 1970 +0000
   |  summary:     b
@@ -410,19 +397,72 @@ 
      date:        Thu Jan 01 00:00:00 1970 +0000
      summary:     a
   
+Failed hook while applying "saveheads" bundle.
+
+  $ hg strip 2 --config hooks.pretxnchangegroup.bad=false
+  abort: merge in progress
+  (To continue:    hg commit
+  To abort:       hg merge --abort)
+  [255]
+  $ restore
+  abort: $ENOENT$: '.hg/strip-backup/*'
+  rm: cannot remove '.hg/strip-backup/*': $ENOENT$
+  [1]
+  $ hg log -G
+  @  changeset:   4:264128213d29
+  |  tag:         tip
+  |  parent:      1:ef3a871183d7
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     c
+  |
+  | o  changeset:   3:443431ffac4f
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     e
+  | |
+  | @  changeset:   2:65bd5f99a4a3
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     d
+  |
+  o  changeset:   1:ef3a871183d7
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     b
+  |
+  o  changeset:   0:9ab35a2d17cb
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     a
+  
 
 2 different branches: 2 strips
 
   $ hg strip 2 4
-  saved backup bundle to $TESTTMP/test/.hg/strip-backup/*-backup.hg (glob)
+  abort: merge in progress
+  (To continue:    hg commit
+  To abort:       hg merge --abort)
+  [255]
   $ hg log -G
-  o  changeset:   2:65bd5f99a4a3
+  @  changeset:   4:264128213d29
   |  tag:         tip
-  |  user:        test
-  |  date:        Thu Jan 01 00:00:00 1970 +0000
-  |  summary:     d
-  |
-  @  changeset:   1:ef3a871183d7
+  |  parent:      1:ef3a871183d7
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     c
+  |
+  | o  changeset:   3:443431ffac4f
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     e
+  | |
+  | @  changeset:   2:65bd5f99a4a3
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     d
+  |
+  o  changeset:   1:ef3a871183d7
   |  user:        test
   |  date:        Thu Jan 01 00:00:00 1970 +0000
   |  summary:     b
@@ -433,13 +473,21 @@ 
      summary:     a
   
   $ restore
+  abort: $ENOENT$: '.hg/strip-backup/*'
+  rm: cannot remove '.hg/strip-backup/*': $ENOENT$
+  [1]
 
 2 different branches and a common ancestor: 1 strip
 
   $ hg strip 1 "2|4"
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  saved backup bundle to $TESTTMP/test/.hg/strip-backup/*-backup.hg (glob)
+  abort: merge in progress
+  (To continue:    hg commit
+  To abort:       hg merge --abort)
+  [255]
   $ restore
+  abort: $ENOENT$: '.hg/strip-backup/*'
+  rm: cannot remove '.hg/strip-backup/*': $ENOENT$
+  [1]
 
 verify fncache is kept up-to-date
 
@@ -475,16 +523,17 @@ 
 
   $ echo "mq=" >> $HGRCPATH
   $ hg up -C 3
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ echo fooagain >> bar
   $ hg ci -mf
   $ hg qimport -r tip:2
+  abort: revision 2 is not the parent of 1
+  [255]
 
 applied patches before strip
 
   $ hg qapplied
-  d
-  e
+  c
   f
 
 stripping revision in queue
@@ -496,7 +545,6 @@ 
 applied patches after stripping rev in queue
 
   $ hg qapplied
-  d
 
 stripping ancestor of queue
 
@@ -542,7 +590,7 @@ 
   commit: 1 modified, 1 unknown, 1 unresolved
   update: (current)
   phases: 2 draft
-  mq:     3 unapplied
+  mq:     2 unapplied
 
   $ echo c > b
   $ hg strip tip
@@ -570,7 +618,7 @@ 
   commit: 1 modified, 1 unknown
   update: (current)
   phases: 1 draft
-  mq:     3 unapplied
+  mq:     2 unapplied
 
 Strip adds, removes, modifies with --keep
 
@@ -1014,21 +1062,29 @@ 
   
 
   $ hg strip --force -r 35358f982181
-  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
-  saved backup bundle to $TESTTMP/issue4736/.hg/strip-backup/35358f982181-50d992d4-backup.hg
+  abort: merge in progress
+  (To continue:    hg commit
+  To abort:       hg merge --abort)
+  [255]
   $ hg log -G
-  @  changeset:   3:f62c6c09b707
-  |  branch:      new-branch
+  @  changeset:   4:35358f982181
   |  tag:         tip
-  |  user:        test
-  |  date:        Thu Jan 01 00:00:00 1970 +0000
-  |  summary:     foo
-  |
-  o  changeset:   2:b1d33a8cadd9
-  |  branch:      new-branch
-  |  user:        test
-  |  date:        Thu Jan 01 00:00:00 1970 +0000
-  |  summary:     start new branch
+  |  parent:      1:eca11cf91c71
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     bar
+  |
+  | @  changeset:   3:f62c6c09b707
+  | |  branch:      new-branch
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     foo
+  | |
+  | o  changeset:   2:b1d33a8cadd9
+  |/   branch:      new-branch
+  |    user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     start new branch
   |
   o  changeset:   1:eca11cf91c71
   |  user:        test
@@ -1042,24 +1098,27 @@ 
   
 
   $ hg up default
-  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  abort: outstanding uncommitted merge
+  [255]
   $ echo 'bar' > bar.txt
   $ hg ci -Aqm bar
   $ hg up new-branch
-  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg merge default
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  (branch merge, don't forget to commit)
+  abort: merging with a working directory ancestor has no effect
+  [255]
   $ hg ci -m merge
+  nothing changed
+  [1]
   $ hg log -G
-  @    changeset:   5:4cf5e92caec2
+  @    changeset:   5:83e3b1899f69
   |\   branch:      new-branch
   | |  tag:         tip
   | |  parent:      3:f62c6c09b707
   | |  parent:      4:35358f982181
   | |  user:        test
   | |  date:        Thu Jan 01 00:00:00 1970 +0000
-  | |  summary:     merge
+  | |  summary:     bar
   | |
   | o  changeset:   4:35358f982181
   | |  parent:      1:eca11cf91c71
@@ -1092,7 +1151,7 @@ 
 
   $ hg strip -r 35358f982181
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
-  saved backup bundle to $TESTTMP/issue4736/.hg/strip-backup/35358f982181-a6f020aa-backup.hg
+  saved backup bundle to $TESTTMP/issue4736/.hg/strip-backup/35358f982181-e55d5023-backup.hg
   $ hg log -G
   @  changeset:   3:f62c6c09b707
   |  branch:      new-branch
@@ -1119,15 +1178,12 @@ 
   
 
   $ hg unbundle -u $TESTTMP/issue4736/.hg/strip-backup/35358f982181-a6f020aa-backup.hg
-  adding changesets
-  adding manifests
-  adding file changes
-  added 2 changesets with 1 changes to 1 files
-  new changesets 35358f982181:4cf5e92caec2 (2 drafts)
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  abort: $ENOENT$: '$TESTTMP/issue4736/.hg/strip-backup/35358f982181-a6f020aa-backup.hg'
+  [255]
 
   $ hg strip -k -r 35358f982181
-  saved backup bundle to $TESTTMP/issue4736/.hg/strip-backup/35358f982181-a6f020aa-backup.hg
+  abort: unknown revision '35358f982181'!
+  [255]
   $ hg log -G
   @  changeset:   3:f62c6c09b707
   |  branch:      new-branch
@@ -1153,11 +1209,6 @@ 
      summary:     commitA
   
   $ hg diff
-  diff -r f62c6c09b707 bar.txt
-  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-  +++ b/bar.txt	Thu Jan 01 00:00:00 1970 +0000
-  @@ -0,0 +1,1 @@
-  +bar
 
 Use delayedstrip to strip inside a transaction
 
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-pull.t b/tests/test-rebase-pull.t
--- a/tests/test-rebase-pull.t
+++ b/tests/test-rebase-pull.t
@@ -115,8 +115,9 @@ 
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
   $ hg pull --rebase
-  abort: outstanding uncommitted merge
-  (cannot pull with rebase: please commit or shelve your changes first)
+  abort: merge in progress
+  (To continue:    hg commit
+  To abort:       hg merge --abort)
   [255]
   $ hg update --clean --quiet
 
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-mq-qnew.t b/tests/test-mq-qnew.t
--- a/tests/test-mq-qnew.t
+++ b/tests/test-mq-qnew.t
@@ -164,7 +164,9 @@ 
   0 files updated, 0 files merged, 0 files removed, 1 files unresolved
   use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
   (no more unresolved files)
-  abort: cannot manage merge changesets
+  abort: merge in progress
+  (To continue:    hg commit
+  To abort:       hg merge --abort)
   $ rm -r sandbox
 
 hg headers
@@ -243,7 +245,9 @@ 
   0 files updated, 0 files merged, 0 files removed, 1 files unresolved
   use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
   (no more unresolved files)
-  abort: cannot manage merge changesets
+  abort: merge in progress
+  (To continue:    hg commit
+  To abort:       hg merge --abort)
   $ rm -r sandbox
 
 Test saving last-message.txt
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
@@ -124,7 +124,7 @@ 
         """returns the hint message corresponding to the command"""
         if not self._cmdhint:
                 return (_("use 'hg %s --continue' or 'hg %s --abort'") %
-                        (self._cmdname,self._cmdname))
+                        (self._cmdname, self._cmdname))
         return self._cmdhint
 
     def msg(self):
@@ -134,18 +134,64 @@ 
         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._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")))
+
+def addunfinished(**cmddata):
+    """this accepts a dict having command data, makes a statecheck object and
+    adds it to the unfinishedstate object list
+    """
+    cmdname = cmddata['cmdname']
+    statecheckobj = statecheck(**cmddata)
+    if cmdname=='merge' or cmdname=='bisect':
+        unfinishedstates.append(statecheckobj)
+    else:
+        unfinishedstates.insert(0, statecheckobj)
+
+graftdata = {
+    'cmdname': 'graft',
+    'fname': 'graftstate',
+    'clearable': True,
+    'allowcommit': False,
+    'cmdhint': _("use 'hg graft --continue' or 'hg graft --stop' to stop")
+}
+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')
+}
+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")
+}
+addunfinished(**updatedata)
+mergedata = {
+    'cmdname': 'merge',
+    'fname': None,
+    'clearable': True,
+    'allowcommit': True,
+    'cmdhint': _('To continue:    hg commit\n'
+                 'To abort:       hg merge --abort')
+}
+addunfinished(**mergedata)
 
 def checkunfinished(repo, commit=False):
     '''Look for an unfinished multistep operation, like graft, and abort
@@ -155,7 +201,8 @@ 
     # 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())
@@ -171,70 +218,22 @@ 
     that are clearable.
     '''
     for state in unfinishedstates:
+        if 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':
+            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 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
@@ -620,18 +620,17 @@ 
     return _commentlines(msg)
 
 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")
+    }
+    statemod.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')
+    }
+    statemod.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
@@ -1947,8 +1947,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
+    }
+    statemod.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
+    }
+    statemod.addunfinished(**histeditdata)
     cmdutil.afterresolvedstates.append(
         ['histedit-state', _('hg histedit --continue')])