0
  8   Ùˆl–Ü4ý( ©”u( 	•íÀà™S�ÿ�þB'
›”D|2!)üÿè„u¶žçæÂä ?÷     Ù# Copyright (C) 2006-2011 Canonical Ltd
# Copyright (C) 2020 Breezy Developers
#
# 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

import errno
import os
import posixpath
from stat import S_IEXEC, S_ISREG
import tempfile
import time

from .mapping import encode_git_path, mode_kind, mode_is_executable, object_mode
from .tree import GitTree, GitTreeDirectory, GitTreeSymlink, GitTreeFile
from .mapping import decode_git_path

from .. import (
    annotate,
    conflicts,
    errors,
    multiparent,
    osutils,
    revision as _mod_revision,
    trace,
    transport as _mod_transport,
    ui,
    urlutils,
    )
from ..i18n import gettext
from ..mutabletree import MutableTree
from ..tree import InterTree, TreeChange
from ..transform import (
    PreviewTree,
    TreeTransform,
    _TransformResults,
    _FileMover,
    FinalPaths,
    joinpath,
    unique_add,
    TransformRenameFailed,
    ImmortalLimbo,
    ROOT_PARENT,
    ReusingTransform,
    MalformedTransform,
    )

from dulwich.index import commit_tree, blob_from_path_and_stat
from dulwich.objects import Blob


class TreeTransformBase(TreeTransform):
    """The base class for TreeTransform and its kin."""

    def __init__(self, tree, pb=None, case_sensitive=True):
        """Constructor.

        :param tree: The tree that will be transformed, but not necessarily
            the output tree.
        :param pb: ignored
        :param case_sensitive: If True, the target of the transform is
            case sensitive, not just case preserving.
        """
        super().__init__(tree, pb=pb)
        # mapping of trans_id => (sha1 of content, stat_value)
        self._observed_sha1s = {}
        # Set of versioned trans ids
        self._versioned = set()
        # The trans_id that will be used as the tree root
        self.root = self.trans_id_tree_path('')
        # Whether the target is case sensitive
        self._case_sensitive_target = case_sensitive
        self._symlink_target = {}

    @property
    def mapping(self):
        return self._tree.mapping

    def finalize(self):
        """Release the working tree lock, if held.

        This is required if apply has not been invoked, but can be invoked
        even after apply.
        """
        if self._tree is None:
            return
        for hook in MutableTree.hooks['post_transform']:
            hook(self._tree, self)
        self._tree.unlock()
        self._tree = None

    def create_path(self, name, parent):
        """Assign a transaction id to a new path"""
        trans_id = self.assign_id()
        unique_add(self._new_name, trans_id, name)
        unique_add(self._new_parent, trans_id, parent)
        return trans_id

    def adjust_root_path(self, name, parent):
        """Emulate moving the root by moving all children, instead.
        """

    def fixup_new_roots(self):
        """Reinterpret requests to change the root directory

        Instead of creating a root directory, or moving an existing directory,
        all the attributes and children of the new root are applied to the
        existing root directory.

        This means that the old root trans-id becomes obsolete, so it is
        recommended only to invoke this after the root trans-id has become
        irrelevant.

        """
        new_roots = [k for k, v in self._new_parent.items()
                   