Mercurial > public > mercurial-scm > evolve
diff hgext/evolve.py @ 269:6c6bb7a23bb5 0.1.0
stabilize: improve unstable selection heuristic
Without argument, stabilize was picking the first in:
"unstable() and ((suspended() or obsancestors(::.))::)"
which usually returned the "oldest" unstable revision in parent
predecessors descendants. This revision is interesting because it
usually gives "soft" merges but rebasing it left the working directory
on a remote branch, which was very confusing.
The new heuristic picks an unstable changeset which can be rebased on
top of the parent revision, or on top of one of its descendants
(selected in revision order). This has the advantage of selecting a
revision which can be rebased on the current subtree, and leave the
working directory in a more convenient location.
author | Patrick Mezard <patrick@mezard.eu> |
---|---|
date | Wed, 13 Jun 2012 18:28:10 +0200 |
parents | 2da5af3dadeb |
children | 78d01e341438 |
line wrap: on
line diff
--- 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]