0000004c
  B   ˆl–Ü4ý( ©”u( 	•íÀà™S�ÿ�þ^!
³rˆ�†A„% ?ŸÇ„eÀ4çÌ_ŠI|¥�+Wé3ž¯ÃÊ ?÷     # Copyright (C) 2005-2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from typing import List, Type, Optional

from breezy import (
    revision,
    workingtree,
    )
from breezy.i18n import gettext

from . import (
    errors,
    lazy_regex,
    registry,
    revision as _mod_revision,
    trace,
    )


class InvalidRevisionSpec(errors.BzrError):

    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
            " %(branch_url)s%(extra)s")

    def __init__(self, spec, branch, extra=None):
        errors.BzrError.__init__(self, branch=branch, spec=spec)
        self.branch_url = getattr(branch, 'user_url', str(branch))
        if extra:
            self.extra = '\n' + str(extra)
        else:
            self.extra = ''


class RevisionInfo:
    """The results of applying a revision specification to a branch."""

    help_txt = """The results of applying a revision specification to a branch.

    An instance has two useful attributes: revno, and rev_id.

    They can also be accessed as spec[0] and spec[1] respectively,
    so that you can write code like:
    revno, rev_id = RevisionSpec(branch, spec)
    although this is probably going to be deprecated later.

    This class exists mostly to be the return value of a RevisionSpec,
    so that you can access the member you're interested in (number or id)
    or treat the result as a tuple.
    """

    def __init__(self, branch, revno=None, rev_id=None):
        self.branch = branch
        self._has_revno = (revno is not None)
        self._revno = revno
        self.rev_id = rev_id
        if self.rev_id is None and self._revno is not None:
            # allow caller to be lazy
            self.rev_id = branch.get_rev_id(self._revno)

    @property
    def revno(self):
        if not self._has_revno and self.rev_id is not None:
            try:
                self._revno = self.branch.revision_id_to_revno(self.rev_id)
            except (errors.NoSuchRevision, errors.RevnoOutOfBounds):
                self._revno = None
            self._has_revno = True
        return self._revno

    def __bool__(self):
        if self.rev_id is None:
            return False
        # TODO: otherwise, it should depend on how I was built -
        # if it's in_history(branch), then check revision_history(),
        # if it's in_store(branch), do the check below
        return self.branch.repository.has_revision(self.rev_id)

    __nonzero__ = __bool__

    def __len__(self):
        return 2

    def __getitem__(self, index):
        if index == 0:
            return self.revno
        if index == 1:
            return self.rev_id
        raise IndexError(index)

    def get(self):
        return self.branch.repository.get_revision(self.rev_id)

    def __eq__(self, other):
        if type(other) not in (tuple, list, type(self)):
            return False
        if isinstance(other, type(self)) and self.branch is not other.branch:
            return False
        return tuple(self) == tuple(other)

    def __repr__(self):
        return '<breezy.revisionspec.RevisionInfo object {}, {} for {!r}>'.format(
            self.revno, self.rev_id, self.branch)

    @staticmethod
    def from_revision_id(branch, revision_id):
        """Construct a RevisionInfo given just the id.

        Use this if you don't know 