Mercurial > evolve
changeset 2739:7d86594cb829
prev: extract the code computing the destination
This make the handling of the result simpler. The test agree as one return code
is fixed.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 14 Jul 2017 01:49:43 +0200 |
parents | 3f27fe80be26 |
children | 51afc979d88d |
files | hgext3rd/evolve/__init__.py tests/test-evolve-topic.t |
diffstat | 2 files changed, 32 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/evolve/__init__.py Fri Jul 14 01:32:34 2017 +0200 +++ b/hgext3rd/evolve/__init__.py Fri Jul 14 01:49:43 2017 +0200 @@ -2002,7 +2002,30 @@ lockmod.release(tr, lock) displayer.show(target) - return 0 + +def _findprevtarget(repo, displayer, movebookmark=False, topic=True): + target = bookmark = None + wkctx = repo[None] + wparents = wkctx.parents() + parents = wparents[0].parents() + currenttopic = getattr(repo, 'currenttopic', '') + if currenttopic and topic: + parents = [ctx for ctx in parents if ctx.topic() == currenttopic] + if wparents[0].node() == node.nullid: + repo.ui.warn(_('already at repository root\n')) + elif not parents and currenttopic: + repo.ui.warn(_('no parent in topic "%s"\n') % currenttopic) + repo.ui.warn(_('(do you want --no-topic)\n')) + elif len(parents) == 1: + target = parents[0] + bookmark = None + if movebookmark: + bookmark = repo._activebookmark + else: + for p in parents: + displayer.show(p) + repo.ui.warn(_('multiple parents, explicitly update to one\n')) + return target, bookmark @eh.command( '^previous', @@ -2033,27 +2056,15 @@ exc.hint = _('do you want --merge?') raise - parents = wparents[0].parents() - topic = getattr(repo, 'currenttopic', '') - if topic and not opts.get("no_topic", False): - parents = [ctx for ctx in parents if ctx.topic() == topic] displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate}) - if wparents[0].node() == node.nullid: - ui.warn(_('already at repository root\n')) - return 1 - elif not parents and topic: - ui.warn(_('no parent in topic "%s"\n') % topic) - ui.warn(_('(do you want --no-topic)\n')) - elif len(parents) == 1: - target = parents[0] - bookmark = None - if opts.get('move_bookmark'): - bookmark = repo._activebookmark - return _prevupdate(repo, displayer, target, bookmark, dryrunopt) + + target, bookmark = _findprevtarget(repo, displayer, + opts.get('move_bookmark'), + not opts.get("no_topic", False)) + if target is not None: + _prevupdate(repo, displayer, target, bookmark, dryrunopt) + return 0 else: - for p in parents: - displayer.show(p) - ui.warn(_('multiple parents, explicitly update to one\n')) return 1 finally: lockmod.release(wlock)
--- a/tests/test-evolve-topic.t Fri Jul 14 01:32:34 2017 +0200 +++ b/tests/test-evolve-topic.t Fri Jul 14 01:49:43 2017 +0200 @@ -211,6 +211,7 @@ $ hg prev no parent in topic "bar" (do you want --no-topic) + [1] $ hg prev --no-topic switching to topic foo 0 files updated, 0 files merged, 1 files removed, 0 files unresolved