--- a/hgext/evolve.py Tue Jun 12 15:33:23 2012 +0200
+++ b/hgext/evolve.py Wed Jun 13 18:28:10 2012 +0200
@@ -195,6 +195,24 @@
raise
+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.
+ """
+ def selfanddescendants(repo, pctx):
+ yield pctx
+ for ctx in pctx.descendants():
+ yield ctx
+
+ # Look for an unstable which can be stabilized as a child of
+ # node. The unstable must be a child of one of node predecessors.
+ for ctx in selfanddescendants(repo, pctx):
+ unstables = list(repo.set('unstable() and children(obsancestors(%d))',
+ ctx.rev()))
+ if unstables:
+ return unstables[0]
+ return None
### new command
#############################
@@ -208,30 +226,34 @@
],
'')
def stabilize(ui, repo, **opts):
- """move changeset out of the unstable state
+ """rebase an unstable changeset to make it stable again
- By default only works on changeset that will be rebase on ancestors of the
- current working directory parent (included)"""
+ By default, take the first unstable changeset which could be
+ rebased as child of the working directory parent revision or one
+ of its descendants and rebase it.
+
+ With --any, stabilize any unstable changeset.
+
+ The working directory is updated to the rebased revision.
+ """
obsolete = extensions.find('obsolete')
- if opts['any']:
- rvstargets = 'unstable()'
- else:
- rvstargets = 'unstable() and ((suspended() and obsancestors(::.))::)'
-
- unstable = list(repo.set(rvstargets))
- if not unstable:
- unstable = opts['any'] and () or list(repo.set('unstable()'))
- if unstable:
+ node = None
+ if not opts['any']:
+ node = stabilizableunstable(repo, repo['.'])
+ if node is None:
+ unstables = list(repo.set('unstable()'))
+ if unstables and not opts['any']:
ui.write_err(_('nothing to stabilize here\n'))
ui.status(_('(%i unstable changesets, do you want --any ?)\n')
- % len(unstable))
+ % len(unstables))
return 2
- else:
+ elif not unstables:
ui.write_err(_('no unstable changeset\n'))
return 1
- node = unstable[0]
+ node = unstables[0]
+
obs = node.parents()[0]
if not obs.obsolete():
obs = node.parents()[1]