# HG changeset patch # User Pierre-Yves David # Date 1529197673 -7200 # Node ID bbfbaf46f7b09cd6c112306f1f3e967dff1ab7fa # Parent 1742254d1190acec43e9a7f5d3cc24008da247a8 rewind: move revision selection into its own function This will help making the logic more advanced. diff -r 1742254d1190 -r bbfbaf46f7b0 hgext3rd/evolve/rewind.py --- a/hgext3rd/evolve/rewind.py Sun Jun 17 02:32:29 2018 +0200 +++ b/hgext3rd/evolve/rewind.py Sun Jun 17 03:07:53 2018 +0200 @@ -56,18 +56,12 @@ """ unfi = repo.unfiltered() - if not opts.get('to'): - raise error.Abort('no revision to rewind to') - successorsmap = collections.defaultdict(set) rewindmap = {} sscache = {} with repo.wlock(), repo.lock(): - rewinded = scmutil.revrange(repo, opts.get('to')) - - if not opts['exact']: - rewinded = repo.revs('obsolete() and ::%ld', rewinded) + rewinded = _select_rewinded(repo, opts) if not opts['as_divergence']: for rev in rewinded: @@ -107,6 +101,19 @@ if update_target is not None: ui.status(_('working directory is now at %s\n') % repo['.']) +def _select_rewinded(repo, opts): + """select the revision we shoudl rewind to + """ + if not opts.get('to'): + raise error.Abort('no revision to rewind to') + + rewinded = scmutil.revrange(repo, opts.get('to')) + + if not opts['exact']: + rewinded = repo.revs('obsolete() and ::%ld', rewinded) + + return rewinded + def _revive_revision(unfi, rev, rewindmap): """rewind a single revision rev. """