hgext/evolve.py
changeset 468 6b1b6d338478
parent 466 b98490b689a5
child 469 abeb17a9e313
--- a/hgext/evolve.py	Mon Aug 20 15:43:57 2012 +0200
+++ b/hgext/evolve.py	Mon Aug 20 18:59:07 2012 +0200
@@ -181,7 +181,7 @@
         repo.dirstate.invalidate()
         raise
 
-def stabilizableunstable(repo, pctx):
+def _stabilizableunstable(repo, pctx):
     """Return a changectx for an unstable changeset which can be
     stabilized on top of pctx or one of its descendants. None if none
     can be found.
@@ -250,23 +250,46 @@
         graftcmd = commands.table['graft'][0]
         return graftcmd(ui, repo, old_obsolete=True, **{'continue': True})
 
-    obsolete = extensions.find('obsolete')
-
-    orig = None
-    if not opts['any']:
-        orig = stabilizableunstable(repo, repo['.'])
-    if orig is None:
-        unstables = list(repo.set('unstable()'))
-        if unstables and not opts['any']:
+    troubled = list(repo.revs('troubled()'))
+    tr = _picknexttroubled(ui, repo, anyopt)
+    if tr is None:
+        if troubled:
             ui.write_err(_('nothing to stabilize here\n'))
-            ui.status(_('(%i unstable changesets, do you want --any ?)\n')
-                      % len(unstables))
+            ui.status(_('(%i troubled changesets, do you want --any ?)\n')
+                      % len(troubled))
             return 2
-        elif not unstables:
-            ui.write_err(_('no unstable changeset\n'))
+        else:
+            ui.write_err(_('no troubled changeset\n'))
             return 1
-        orig = unstables[0]
+    troubles = tr.troubles()
+    if 'unstable' in troubles:
+        return _stabunstable(ui, repo, tr, opts['dry_run'])
+    elif 'latecomer' in troubles:
+        ui.write_err(_('latecomer not handled yet\n'))
+        return 4
+    elif 'conflicting' in troubles:
+        ui.write_err(_('conflicting not handled yet\n'))
+        return 4
+    else:
+        assert False  # WHAT? unknown troubles
 
+def _picknexttroubled(ui, repo, any=False):
+    """Pick a the next trouble changeset to solve"""
+    tr = _stabilizableunstable(repo, repo['.'])
+    if tr is None and any:
+        troubled = list(repo.set('unstable()'))
+        if not troubled:
+            troubled = list(repo.set('latecomer()'))
+        if not troubled:
+            troubled = list(repo.set('conflicting()'))
+        if troubled:
+            tr = troubled[0]
+    return tr
+
+
+def _stabunstable(ui, repo, orig, dryrun=False):
+    """Stabilize a unstable changeset"""
+    obsolete = extensions.find('obsolete')
     obs = orig.parents()[0]
     if not obs.obsolete():
         obs = orig.parents()[1]
@@ -295,8 +318,8 @@
     repo.ui.status(_('atop:'))
     if not ui.quiet:
         displayer.show(target)
-    todo= 'hg rebase -Dr %s -d %s\n' % (orig, target)
-    if opts['dry_run']:
+    todo = 'hg rebase -Dr %s -d %s\n' % (orig, target)
+    if dryrun:
         repo.ui.write(todo)
     else:
         repo.ui.note(todo)