hgext3rd/evolve/evolvecmd.py
author Pulkit Goyal <7895pulkit@gmail.com>
Fri, 19 Jan 2018 14:42:46 +0530
changeset 3461 6475d2046f87
child 3462 e147c18ed064
permissions -rw-r--r--
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.

# Copyright 2011 Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
#                Logilab SA        <contact@logilab.fr>
#                Pierre-Yves David <pierre-yves.david@ens-lyon.org>
#                Patrick Mezard <patrick@mezard.eu>
#
# 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)