stabilize: rework stabilize code to allow selection of latecomer and conflicting
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Mon, 20 Aug 2012 18:59:07 +0200
changeset 468 6b1b6d338478
parent 467 869ddfb98c7e
child 469 abeb17a9e313
stabilize: rework stabilize code to allow selection of latecomer and conflicting They are still unhandled but the tool now explicitly state this fact.
hgext/evolve.py
tests/test-evolve.t
tests/test-stabilize-order.t
--- 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)
--- a/tests/test-evolve.t	Mon Aug 20 15:43:57 2012 +0200
+++ b/tests/test-evolve.t	Mon Aug 20 18:59:07 2012 +0200
@@ -287,6 +287,30 @@
   $ hg phase --public 7
   1 new latecomers changesets
 
+all solving latecomer troubled
+
+  $ hg glog
+  @  8	feature-B: another feature that rox - test
+  |
+  | o  7	: another feature - test
+  |/
+  o  6	feature-A: a nifty feature - test
+  |
+  o  0	: base - test
+  
+  $ hg stabilize --any
+  latecomer not handled yet
+  [4]
+  $ hg glog
+  @  8	feature-B: another feature that rox - test
+  |
+  | o  7	: another feature - test
+  |/
+  o  6	feature-A: a nifty feature - test
+  |
+  o  0	: base - test
+  
+
   $ cd ..
 
 enable general delta
--- a/tests/test-stabilize-order.t	Mon Aug 20 15:43:57 2012 +0200
+++ b/tests/test-stabilize-order.t	Mon Aug 20 18:59:07 2012 +0200
@@ -118,7 +118,7 @@
   o  0:c471ef929e6a@default(draft) addroot
   
   $ hg stabilize -v
-  no unstable changeset
+  no troubled changeset
   [1]
 
 Test behaviour with --any
@@ -143,7 +143,7 @@
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg stabilize -v
   nothing to stabilize here
-  (1 unstable changesets, do you want --any ?)
+  (1 troubled changesets, do you want --any ?)
   [2]
   $ hg stabilize --any -v
   move:[9] addc
@@ -165,5 +165,5 @@
   o  0:c471ef929e6a@default(draft) addroot
   
   $ hg stabilize --any -v
-  no unstable changeset
+  no troubled changeset
   [1]