# HG changeset patch # User Pierre-Yves David # Date 1499987540 -7200 # Node ID 3c87d527639437ae939d7d1a1c1d1f7343ec355a # Parent 28087c173534305a65a8bb834aa4501f52f6a087 prev: extract the function performing the update That code is fairly independant so let us isolate it to simplify the rest of the code. diff -r 28087c173534 -r 3c87d5276394 hgext3rd/evolve/__init__.py --- a/hgext3rd/evolve/__init__.py Fri Jul 14 01:01:22 2017 +0200 +++ b/hgext3rd/evolve/__init__.py Fri Jul 14 01:12:20 2017 +0200 @@ -1979,6 +1979,31 @@ shorttemplate = "[{label('evolve.rev', rev)}] {desc|firstline}\n" +def _prevupdate(repo, displayer, target, bookmark, dryrun): + if dryrun: + repo.ui.write(('hg update %s;\n' % target.rev())) + if bookmark is not None: + repo.ui.write(('hg bookmark %s -r %s;\n' + % (bookmark, target.rev()))) + else: + ret = hg.update(repo, target.rev()) + if not ret: + tr = lock = None + try: + lock = repo.lock() + tr = repo.transaction('previous') + if bookmark is not None: + repo._bookmarks[bookmark] = target.node() + repo._bookmarks.recordchange(tr) + else: + bookmarksmod.deactivate(repo) + tr.close() + finally: + lockmod.release(tr, lock) + + displayer.show(target) + return 0 + @eh.command( '^previous', [('B', 'move-bookmark', False, @@ -2021,29 +2046,7 @@ bookmark = None if opts.get('move_bookmark'): bookmark = repo._activebookmark - if dryrunopt: - ui.write(('hg update %s;\n' % target.rev())) - if bookmark is not None: - ui.write(('hg bookmark %s -r %s;\n' - % (bookmark, target.rev()))) - else: - ret = hg.update(repo, target.rev()) - if not ret: - tr = lock = None - try: - lock = repo.lock() - tr = repo.transaction('previous') - if bookmark is not None: - repo._bookmarks[bookmark] = target.node() - repo._bookmarks.recordchange(tr) - else: - bookmarksmod.deactivate(repo) - tr.close() - finally: - lockmod.release(tr, lock) - - displayer.show(target) - return 0 + return _prevupdate(repo, displayer, target, bookmark, dryrunopt) else: for p in parents: displayer.show(p)