Mercurial > evolve
changeset 3539:9bd64091e880
next: factor out the logic to update to changeset in another function
This patch moves the logic to update to children changeset during `hg next` in a
separate function because we want to re-use the logic when we will prompt user
to choose a changeset in case of multiple childrens.
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Fri, 16 Mar 2018 11:24:35 +0530 |
parents | b314c64f336b |
children | 0624732c92f7 |
files | hgext3rd/evolve/__init__.py |
diffstat | 1 files changed, 29 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/evolve/__init__.py Wed Mar 14 17:59:53 2018 +0530 +++ b/hgext3rd/evolve/__init__.py Fri Mar 16 11:24:35 2018 +0530 @@ -1107,30 +1107,7 @@ {'template': shorttemplate}) if len(children) == 1: c = children[0] - bm = repo._activebookmark - shouldmove = opts.get('move_bookmark') and bm is not None - if dryrunopt: - ui.write(('hg update %s;\n' % c.rev())) - if shouldmove: - ui.write(('hg bookmark %s -r %s;\n' % (bm, c.rev()))) - else: - ret = hg.update(repo, c.rev()) - if not ret: - lock = tr = None - try: - lock = repo.lock() - tr = repo.transaction('next') - if shouldmove: - bmchanges = [(bm, c.node())] - compat.bookmarkapplychanges(repo, tr, bmchanges) - else: - bookmarksmod.deactivate(repo) - tr.close() - finally: - lockmod.release(tr, lock) - if not ui.quiet: - displayer.show(c) - result = 0 + result = _updatetonext(ui, repo, c, displayer, opts) elif children: ui.warn(_("ambiguous next changeset:\n")) for c in children: @@ -1177,6 +1154,34 @@ finally: lockmod.release(wlock) +def _updatetonext(ui, repo, children, displayer, opts): + """ logic for `hg next` command to update to children and move bookmarks if + required """ + bm = repo._activebookmark + shouldmove = opts.get('move_bookmark') and bm is not None + if opts.get('dry_run'): + ui.write(('hg update %s;\n' % children.rev())) + if shouldmove: + ui.write(('hg bookmark %s -r %s;\n' % (bm, children.rev()))) + else: + ret = hg.update(repo, children.rev()) + if not ret: + lock = tr = None + try: + lock = repo.lock() + tr = repo.transaction('next') + if shouldmove: + bmchanges = [(bm, children.node())] + compat.bookmarkapplychanges(repo, tr, bmchanges) + else: + bookmarksmod.deactivate(repo) + tr.close() + finally: + lockmod.release(tr, lock) + if not ui.quiet: + displayer.show(children) + return 0 + @eh.wrapcommand('commit') def commitwrapper(orig, ui, repo, *arg, **kwargs): tr = None