# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1516353166 -19800 # Node ID 6475d2046f87a234fe970333731993dc30cf1018 # Parent ada7fb45303444ad28bc7f899d193a379f010bc0 evolvecmd: introduce a new module to handle `hg evolve` related code __init__.py is to cluttered with wrapping and all, it's better to move code related to evolve command to new a module which will help us in great refactoring and introducing nice and better flow of data through functions. There is a temporary import cycle is introduced which will be fixed in the series. diff -r ada7fb453034 -r 6475d2046f87 hgext3rd/evolve/__init__.py --- a/hgext3rd/evolve/__init__.py Thu Jan 18 16:57:19 2018 +0530 +++ b/hgext3rd/evolve/__init__.py Fri Jan 19 14:42:46 2018 +0530 @@ -311,6 +311,7 @@ debugcmd, cmdrewrite, state, + evolvecmd, exthelper, metadata, obscache, @@ -1028,34 +1029,6 @@ _deprecatealias('gup', 'next') _deprecatealias('gdown', 'previous') -def _solveone(ui, repo, ctx, dryrun, confirm, progresscb, category): - """Resolve the troubles affecting one revision - - returns a tuple (bool, newnode) where, - bool: a boolean value indicating whether the instability was solved - newnode: if bool is True, then the newnode of the resultant commit - formed. newnode can be node, when resolution led to no new - commit. If bool is False, this is ''. - """ - wlock = lock = tr = None - try: - wlock = repo.wlock() - lock = repo.lock() - tr = repo.transaction("evolve") - if 'orphan' == category: - result = _solveunstable(ui, repo, ctx, dryrun, confirm, progresscb) - elif 'phasedivergent' == category: - result = _solvebumped(ui, repo, ctx, dryrun, confirm, progresscb) - elif 'contentdivergent' == category: - result = _solvedivergent(ui, repo, ctx, dryrun, confirm, - progresscb) - else: - assert False, "unknown trouble category: %s" % (category) - tr.close() - return result - finally: - lockmod.release(tr, lock, wlock) - def _handlenotrouble(ui, repo, allopt, revopt, anyopt, targetcat): """Used by the evolve function to display an error message when no troubles can be resolved""" @@ -1627,8 +1600,8 @@ for rev in revs: curctx = repo[rev] progresscb() - ret = _solveone(ui, repo, curctx, dryrunopt, confirmopt, - progresscb, targetcat) + ret = evolvecmd._solveone(ui, repo, curctx, dryrunopt, confirmopt, + progresscb, targetcat) seen += 1 if ret[0]: replacements[curctx.node()] = [ret[1]] @@ -1796,8 +1769,8 @@ progresscb() todo = 'hg rebase -r %s -d %s\n' % (orig, target) if dryrun: + repo.ui.write(todo) return (False, '') - repo.ui.write(todo) else: repo.ui.note(todo) if progresscb: @@ -2282,8 +2255,9 @@ return 1 else: cmdutil.bailifchanged(repo) - result = _solveone(ui, repo, repo[aspchildren[0]], dryrunopt, - False, lambda: None, category='orphan') + result = evolvecmd._solveone(ui, repo, repo[aspchildren[0]], + dryrunopt, False, lambda: None, + category='orphan') # making sure a next commit is formed if result[0] and result[1]: ui.status(_('working directory now at %s\n') diff -r ada7fb453034 -r 6475d2046f87 hgext3rd/evolve/evolvecmd.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hgext3rd/evolve/evolvecmd.py Fri Jan 19 14:42:46 2018 +0530 @@ -0,0 +1,43 @@ +# Copyright 2011 Peter Arrenbrecht +# Logilab SA +# Pierre-Yves David +# Patrick Mezard +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2 or any later version. + +"""logic related to hg evolve command""" + +from mercurial import ( + lock as lockmod, +) + +from . import _solveunstable, _solvebumped, _solvedivergent + +def _solveone(ui, repo, ctx, dryrun, confirm, progresscb, category): + """Resolve the troubles affecting one revision + + returns a tuple (bool, newnode) where, + bool: a boolean value indicating whether the instability was solved + newnode: if bool is True, then the newnode of the resultant commit + formed. newnode can be node, when resolution led to no new + commit. If bool is False, this is ''. + """ + wlock = lock = tr = None + try: + wlock = repo.wlock() + lock = repo.lock() + tr = repo.transaction("evolve") + if 'orphan' == category: + result = _solveunstable(ui, repo, ctx, dryrun, confirm, progresscb) + elif 'phasedivergent' == category: + result = _solvebumped(ui, repo, ctx, dryrun, confirm, progresscb) + elif 'contentdivergent' == category: + result = _solvedivergent(ui, repo, ctx, dryrun, confirm, + progresscb) + else: + assert False, "unknown trouble category: %s" % (category) + tr.close() + return result + finally: + lockmod.release(tr, lock, wlock)