512
  B   	ˆl–Ü4ý( ©”u( 	•íÀà™S�ÿ�þ]Œ%Y¹DGÃ Â�ÏÉ„d-…ïÈ_ŠI|¥�+Wé3ž¯ÇÆ ?÷     	# Copyright (C) 2009-2018 Jelmer Vernooij <jelmer@jelmer.uk>
#
# 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

"""InterRepository operations."""

import itertools

from dulwich.errors import (
    NotCommitError,
    )
from dulwich.object_store import (
    ObjectStoreGraphWalker,
    )
from dulwich.pack import PACK_SPOOL_FILE_MAX_SIZE
from dulwich.protocol import (
    CAPABILITY_THIN_PACK,
    ZERO_SHA,
    )
from dulwich.refs import (
    ANNOTATED_TAG_SUFFIX,
    SYMREF,
    )
from dulwich.walk import Walker

from ..errors import (
    DivergedBranches,
    FetchLimitUnsupported,
    InvalidRevisionId,
    LossyPushToSameVCS,
    NoRoundtrippingSupport,
    NoSuchRevision,
    )
from ..repository import (
    FetchResult,
    InterRepository,
    )
from ..revision import (
    NULL_REVISION,
    )
from .. import (
    config,
    trace,
    ui,
    )

from .errors import (
    NoPushSupport,
    )
from .fetch import (
    import_git_objects,
    DetermineWantsRecorder,
    )
from .mapping import (
    needs_roundtripping,
    )
from .object_store import (
    get_object_store,
    )
from .push import (
    MissingObjectsIterator,
    remote_divergence,
    )
from .refs import (
    is_tag,
    ref_to_tag_name,
    )
from .repository import (
    GitRepository,
    LocalGitRepository,
    GitRepositoryFormat,
    )
from .remote import (
    RemoteGitRepository,
    RemoteGitError,
    )
from .unpeel_map import (
    UnpeelMap,
    )


class InterToGitRepository(InterRepository):
    """InterRepository that copies into a Git repository."""

    _matching_repo_format = GitRepositoryFormat()

    def __init__(self, source, target):
        super().__init__(source, target)
        self.mapping = self.target.get_mapping()
        self.source_store = get_object_store(self.source, self.mapping)

    @staticmethod
    def _get_repo_format_to_test():
        return None

    def copy_content(self, revision_id=None):
        """See InterRepository.copy_content."""
        self.fetch(revision_id=revision_id, find_ghosts=False)

    def fetch_refs(self, update_refs, lossy, overwrite=False):
        """Fetch possibly roundtripped revisions into the target repository
        and update refs.

        :param update_refs: Generate refs to fetch. Receives dictionary
            with old refs (git shas), returns dictionary of new names to
            git shas.
        :param lossy: Whether to roundtrip
        :return: old refs, new refs
        """
        raise NotImplementedError(self.fetch_refs)

    def search_missing_revision_ids(self,
                                    find_ghosts=True, revision_ids=None,
                                    if_present_ids=None, limit=None):
        if limit is not None:
            raise FetchLimitUnsupported(self)
        git_shas = []
        todo = []
        if revision_ids:
            todo.extend(revision_ids)
        if if_present_ids:
            todo.extend(revision_ids)
        with self.source_store.lock_read():
            for revid in revision_ids:
                if revid == NULL_REVISION:
                    continue
                try:
                    git_sha = self.source_store._lookup_revision_sha1(revid)
                except KeyError:
                    raise NoSuchRevision(revid, self.source)
                git_shas.append(git_sha)
    