00000049
  C   ˆl–äY>”JeJe@†à¸Û*bÑ¿�þBÓÂmfå…dA$�4çÂ„y ¿Ç_ŠI|¥�+Wé3ž¯ÆÅ ?÷     # rebase.py - rebasing feature for mercurial
#
# Copyright 2008 Stefano Tortarolo <stefano.tortarolo at gmail dot com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.

'''command to move sets of revisions to a different ancestor

This extension lets you rebase changesets in an existing Mercurial
repository.

For more information:
https://mercurial-scm.org/wiki/RebaseExtension
'''


import os

from mercurial.i18n import _
from mercurial.node import (
    nullrev,
    short,
    wdirrev,
)
from mercurial.pycompat import open
from mercurial import (
    bookmarks,
    cmdutil,
    commands,
    copies,
    destutil,
    dirstateguard,
    error,
    extensions,
    logcmdutil,
    merge as mergemod,
    mergestate as mergestatemod,
    mergeutil,
    obsolete,
    obsutil,
    patch,
    phases,
    pycompat,
    registrar,
    repair,
    revset,
    revsetlang,
    rewriteutil,
    scmutil,
    smartset,
    state as statemod,
    util,
)

# The following constants are used throughout the rebase module. The ordering of
# their values must be maintained.

# Indicates that a revision needs to be rebased
revtodo = -1
revtodostr = b'-1'

# legacy revstates no longer needed in current code
# -2: nullmerge, -3: revignored, -4: revprecursor, -5: revpruned
legacystates = {b'-2', b'-3', b'-4', b'-5'}

cmdtable = {}
command = registrar.command(cmdtable)

configtable = {}
configitem = registrar.configitem(configtable)
configitem(
    b'devel',
    b'rebase.force-in-memory-merge',
    default=False,
)
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
# be specifying the version(s) of Mercurial they are tested with, or
# leave the attribute unspecified.
testedwith = b'ships-with-hg-core'


def _nothingtorebase():
    return 1


def _savegraft(ctx, extra):
    s = ctx.extra().get(b'source', None)
    if s is not None:
        extra[b'source'] = s
    s = ctx.extra().get(b'intermediate-source', None)
    if s is not None:
        extra[b'intermediate-source'] = s


def _savebranch(ctx, extra):
    extra[b'branch'] = ctx.branch()


def _destrebase(repo, sourceset, destspace=None):
    """small wrapper around destmerge to pass the right extra args

    Please wrap destutil.destmerge instead."""
    return destutil.destmerge(
        repo,
        action=b'rebase',
        sourceset=sourceset,
        onheadcheck=False,
        destspace=destspace,
    )


revsetpredicate = registrar.revsetpredicate()


@revsetpredicate(b'_destrebase')
def _revsetdestrebase(repo, subset, x):
    # ``_rebasedefaultdest()``

    # default destination for rebase.
    # # XXX: Currently private because I expect the signature to change.
    # # XXX: - bailing out in case of ambiguity vs returning all data.
    # i18n: "_rebasedefaultdest" is a keyword
    sourceset = None
    if x is not None:
        sourceset = revset.getset(repo, smartset.fullreposet(repo), x)
    return subset & smartset.baseset([_destrebase(repo, sourceset)])


@revsetpredicate(b'_destautoorphanrebase')
def _revsetdestautoorphanrebase(repo, subset, x):
    # ``_destautoorphanrebase()``

    # automatic rebase destination for a single orphan revision.
    unfi = repo.unfiltered()
    obsoleted = unfi.revs(b'obsolete()')

    src = revset.getset(repo, subset, x).first()

    # Empty src or already obsoleted - Do not return a destination
    if not src or src in obsoleted:
        return smartset.baseset()
    dests = destutil.orphanpossibledestination(repo, src)
    if len(dests) > 1:
        raise error.StateError(
            _(b"ambiguous automatic rebase: %r could end up on any of %r")
            % (src, dests)
        )
    # We have zero or one destination, so we can just return here.
    return smartset.baseset(dests)


def _ctxdesc(ctx):
    """short description for a context"""
    return cmdutil.forma