HEX
Server: Apache
System: Linux infong-uk86 4.4.400-icpu-106 #2 SMP Mon Sep 15 08:23:40 UTC 2025 x86_64
User: u44115835 (4976590)
PHP: 8.4.17
Disabled: NONE
Upload Files
File: //kunden/lib/python3/dist-packages/breezy/__pycache__/tree.cpython-39.pyc
a

�*�^���@sVdZddlmZzddlmZWney>ddlmZYn0ddlmZee�d�ddl	m
Z
mZmZddl
mZdd	lmZmZGd
d�de
j�ZGdd
�d
e
j�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Ze�e�d&dd �Zd'd!d"�Z d#d$�Z!d%S)(z7Tree classes, representing directory at point in time.
�)�absolute_import)�deque�)�lazy_importz�

from breezy import (
    conflicts as _mod_conflicts,
    debug,
    delta,
    filters,
    revision as _mod_revision,
    rules,
    trace,
    )
from breezy.i18n import gettext
)�errors�lock�osutils)�InterObject)�	text_type�
viewvaluesc@seZdZdZdZdd�ZdS)�FileTimestampUnavailablez,The filestamp for %(path)s is not available.TcCs
||_dS�N��path��selfr�r�-/usr/lib/python3/dist-packages/breezy/tree.py�__init__<sz!FileTimestampUnavailable.__init__N)�__name__�
__module__�__qualname__�_fmtZinternal_errorrrrrrr6src@seZdZdZdd�ZdS)�MissingNestedTreez1The nested tree for %(path)s can not be resolved.cCs
||_dSr
rrrrrrDszMissingNestedTree.__init__N)rrrrrrrrrr@src@s0eZdZdZgZdd�ZdZdd�Zdd�ZdS)	�	TreeEntryzEAn entry that implements the minimum interface used by commands.
    cCst|t�o|j|jkSr
)�
isinstancer�	__class__�r�otherrrr�__eq__Ns

�zTreeEntry.__eq__NcCsdS)Nz???r�rrrr�kind_characterUszTreeEntry.kind_charactercCsdS)z�Does this entry reference the same entry?

        This is mostly the same as __eq__, but returns False
        for entries without enough information (i.e. revision is None)
        Frrrrr�
is_unmodifiedXszTreeEntry.is_unmodified)	rrr�__doc__�	__slots__r�kindr!r"rrrrrHsrc@s eZdZdZgZdZdd�ZdS)�
TreeDirectoryz5See TreeEntry. This is a directory in a working tree.�	directorycCsdS�N�/rr rrrr!hszTreeDirectory.kind_characterN�rrrr#r$r%r!rrrrr&asr&c@s eZdZdZgZdZdd�ZdS)�TreeFilez8See TreeEntry. This is a regular file in a working tree.�filecCsdS�N�rr rrrr!sszTreeFile.kind_characterNr*rrrrr+lsr+c@s eZdZdZgZdZdd�ZdS)�TreeLinkz3See TreeEntry. This is a symlink in a working tree.�symlinkcCsdSr-rr rrrr!~szTreeLink.kind_characterNr*rrrrr/wsr/c@s eZdZdZgZdZdd�ZdS)�
TreeReferencezFSee TreeEntry. This is a reference to a nested tree in a working tree.�tree-referencecCsdS)N�+rr rrrr!�szTreeReference.kind_characterNr*rrrrr1�sr1c@sbeZdZdZgd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�
TreeChangezCDescribes the changes between the same item in two different trees.�	�file_idr�changed_content�	versioned�	parent_id�namer%�
executable�copiedFc

Cs:||_||_||_||_||_||_||_||_|	|_dSr
r5)
rr6rr7r8r9r:r%r;r<rrrr�szTreeChange.__init__cCsd|jj|��fS)Nz%s%r)rr�	_as_tupler rrr�__repr__�szTreeChange.__repr__cCs
t|j�Sr
)�lenr$r rrr�__len__�szTreeChange.__len__c	Cs(|j|j|j|j|j|j|j|j|jf	Sr
r5r rrrr=�s�zTreeChange._as_tuplecCs4t|t�r|��|��kSt|t�r0|��|kSdS�NF)rr4r=�tuplerrrrr�s


zTreeChange.__eq__cCs|��|��kSr
)r=rrrr�__lt__�szTreeChange.__lt__cCs"|jdkr|jd|jdkSdS)N)TTrrF)r8r;r rrr�
meta_modified�s
zTreeChange.meta_modifiedcCs|jd|jdkS)Nrr)r9r rrr�
is_reparented�szTreeChange.is_reparentedcCs\|j|j|jddf|j|jddf|jddf|jddf|jddf|jddfdd�	S)NrF)r<)	rr6rr7r8r9r:r%r;r rrr�discard_new�s�zTreeChange.discard_newN)F)rrrr#r$rr>r@r=rrCrDrErFrrrrr4�s�
r4c@s�eZdZdZdd�Zdd�Zdd�Zdod
d�Zdpd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdqdd�Zdrd d!�Zd"d#�Zdsd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zdtd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Zdud>d?�Z dvd@dA�Z!dBdC�Z"dDdE�Z#dFdG�Z$dHdI�Z%dJdK�Z&e'j(fdLdM�Z)dNdO�Z*dPdQ�Z+gdfdRdS�Z,dTdU�Z-dVdW�Z.dXdY�Z/dZd[�Z0d\d]�Z1dwd_d`�Z2dadb�Z3dxdcdd�Z4dedf�Z5dydgdh�Z6didj�Z7dzdkdl�Z8e9dmdn��Z:d	S){�Treea+Abstract file tree.

    There are several subclasses:

    * `WorkingTree` exists as files on disk editable by the user.

    * `RevisionTree` is a tree as recorded at some point in the past.

    Trees can be compared, etc, regardless of whether they are working
    trees or versioned trees.
    cCsdS)z�Whether this tree supports rename tracking.

        This defaults to True, but some implementations may want to override
        it.
        Trr rrr�supports_rename_tracking�szTree.supports_rename_trackingcCsdS)z�Whether this tree can contain explicitly versioned directories.

        This defaults to True, but some implementations may want to override
        it.
        Trr rrr�has_versioned_directories�szTree.has_versioned_directoriescCst��S)z/Does this tree support symbolic links?
        )rZhas_symlinksr rrr�supports_symlinks�szTree.supports_symlinksFNcCst�||�j||||||d�S)aReturn a TreeDelta of the changes from other to this tree.

        :param other: A tree to compare with.
        :param specific_files: An optional list of file paths to restrict the
            comparison to. When mapping filenames to ids, all matches in all
            trees (including optional extra_trees) are used, and all children of
            matched directories are included.
        :param want_unchanged: An optional boolean requesting the inclusion of
            unchanged entries in the result.
        :param extra_trees: An optional list of additional trees to use when
            mapping the contents of specific_files (paths) to their identities.
        :param require_versioned: An optional boolean (defaults to False). When
            supplied and True all the 'specific_files' must be versioned, or
            a PathsNotVersionedError will be thrown.
        :param want_unversioned: Scan for unversioned paths.

        The comparison will be performed by an InterTree object looked up on
        self and other.
        )�want_unchanged�specific_files�extra_trees�require_versioned�include_root�want_unversioned)�	InterTree�get�compare)rrrKrLrMrNrOrPrrr�changes_from�s�zTree.changes_fromTc	Cs"t�||�}|j||||||d�S)zSee InterTree.iter_changes)rP)rQrR�iter_changes)	r�	from_tree�include_unchangedrL�pbrMrNrPZ	intertreerrrrUs

�zTree.iter_changescCst��S)zuGet a list of the conflicts in the tree.

        Each conflict is an instance of breezy.conflicts.Conflict.
        )Z_mod_conflictsZConflictListr rrr�	conflictsszTree.conflictscCsgS)zAFor trees that can have unversioned files, return all such paths.rr rrr�extrasszTree.extrascCst|j��dS)z�Get the parent ids for this tree.

        :return: a list of parent ids. [] is returned to indicate
        a tree with no parents.
        :raises: BzrError if the parents are not known.
        N)�NotImplementedError�get_parent_idsr rrrr\szTree.get_parent_idscCst|j��dS)z$True if the tree has given filename.N)r[�has_filename�r�filenamerrrr]%szTree.has_filenamecCsdS)z�Check whether the filename is ignored by this tree.

        :param filename: The relative filename within the tree.
        :return: True if the filename is ignored.
        Frr^rrr�
is_ignored)szTree.is_ignoredcCst|j��dS)z>Iterate through all file ids, including ids for missing files.N)r[�all_file_idsr rrrra1szTree.all_file_idscCst|j��dS)z=Iterate through all paths, including paths for missing files.N)r[�all_versioned_pathsr rrrrb5szTree.all_versioned_paths�downcCst|j��dS)zBReturn the path for a file id.

        :raises NoSuchId:
        N)r[�id2path)rr6�recurserrrrd9szTree.id2pathcCst|j��dS)aJWalk the tree in 'by_dir' order.

        This will yield each entry in the tree as a (path, entry) tuple.
        The order that they are yielded is:

        Directories are walked in a depth-first lexicographical order,
        however, whenever a directory is reached, all of its direct child
        nodes are yielded in  lexicographical order before yielding the
        grandchildren.

        For example, in the tree::

           a/
             b/
               c
             d/
               e
           f/
             g

        The yield order (ignoring root) would be::

          a, f, a/b, a/d, a/b/c, a/d/e, f/g

        If recurse_nested is enabled then nested trees are included as if
        they were a part of the tree. If is disabled then TreeReference
        objects (without any children) are yielded.
        N)r[�iter_entries_by_dir)rrL�recurse_nestedrrrrf@szTree.iter_entries_by_dircCst|j��dS)z�Iterate over the children of a directory or tree reference.

        :param path: Path of the directory
        :raise NoSuchFile: When the path does not exist
        :return: Iterator over entries in the directory
        N)r[�iter_child_entriesrrrrrh_szTree.iter_child_entriescCst|j��dS)a{List all files in this tree.

        :param include_root: Whether to include the entry for the tree root
        :param from_dir: Directory under which to list files
        :param recursive: Whether to list files recursively
        :param recurse_nested: enter nested trees
        :return: iterator over tuples of
            (path, versioned, kind, inventory entry)
        N)r[�
list_files)rrOZfrom_dir�	recursivergrrrrihszTree.list_filesccs.|��r*|��D]\}}|jdkr|VqdS)Nr2)Zsupports_tree_referencerfr%)rr�entryrrr�iter_referencesus
zTree.iter_referencescCsF|��D]8}|d7}|�|�r|�|�}||t|�d�fSqdS)z~Find the nested tree that contains a path.

        :return: tuple with (nested tree and path inside the nested tree)
        r)N�NN)rl�
startswith�get_nested_treer?)rrZnested_pathZnested_treerrr�get_containing_nested_tree{s

zTree.get_containing_nested_treecCst|j��dS)z�Open the nested tree at the specified path.

        :param path: Path from which to resolve tree reference.
        :return: A Tree object for the nested tree
        :raise MissingNestedTree: If the nested tree can not be resolved
        N)r[rorrrrro�szTree.get_nested_treecCstd|jj��dS)Nz$Tree subclass %s must implement kind�r[rrrrrrr%�s�z	Tree.kindcCs
|�|�S)z�File kind stored for this path.

        May not match kind on disk for working trees.  Always available
        for versioned files, even when the file itself is missing.
        )r%rrrr�stored_kind�szTree.stored_kindcCst|j��dS)a�Get a summary of the information about path.

        All the attributes returned are for the canonical form, not the
        convenient form (if content filters are in use.)

        :param path: A relative path within the tree.
        :return: A tuple containing kind, size, exec, sha1-or-link.
            Kind is always present (see tree.kind()).
            size is present if kind is file and the size of the
                canonical form can be cheaply determined, None otherwise.
            exec is None unless kind is file and the platform supports the 'x'
                bit.
            sha1-or-link is the link target if kind is symlink, or the sha1 if
                it can be obtained without reading the file.
        N)r[�path_content_summaryrrrrrs�szTree.path_content_summarycCstd|jj��dS)Nz6Tree subclass %s must implement get_reference_revisionrq)rr�branchrrr�get_reference_revision�s�zTree.get_reference_revisioncCst|j��dS)a@Return a tuple of kind, executable, stat_value for a file.

        entry may be None if there is no inventory entry for the file, but
        path must always be supplied.

        kind is None if there is no file present (even if an inventory id is
        present).  executable is False for non-file entries.
        N)r[�_comparison_data)rrkrrrrrv�s	zTree._comparison_datacCst|j��dS)z<Return a file object for the file path in the tree.
        N)r[�get_filerrrrrw�sz
Tree.get_filecCs|�|�dfS)a�Get a file handle and stat object for path.

        The default implementation returns (self.get_file, None) for backwards
        compatibility.

        :param path: The path of the file.
        :return: A tuple (file_handle, stat_value_or_None). If the tree has
            no stat facility, or need for a stat cache feedback during commit,
            it may return None for the second element of the tuple.
        N)rwrrrr�get_file_with_stat�szTree.get_file_with_statcCs6|�|��}|��Wd�S1s(0YdS)z�Return the byte content of a file.

        :param path: The path of the file.

        :returns: A single byte string for the whole file.
        N)rw�read)rrZmy_filerrr�
get_file_text�szTree.get_file_textcCst�|�|��S)z\Return the content of a file, as lines.

        :param path: The path of the file.
        )rZsplit_linesrzrrrr�get_file_lines�szTree.get_file_linescCsd|j||d�fS)aDReturn a verifier for a file.

        The default implementation returns a sha1.

        :param path: The path that this file can be found at.
            These must point to the same object.
        :param stat_value: Optional stat value for the object
        :return: Tuple with verifier name and verifier data
        �SHA1)�
stat_value)�
get_file_sha1�rrr}rrr�get_file_verifier�s
zTree.get_file_verifiercCst|j��dS)agReturn the SHA1 file for a file.

        :note: callers should use get_file_verifier instead
            where possible, as the underlying repository implementation may
            have quicker access to a non-sha1 verifier.

        :param path: The path that this file can be found at.
        :param stat_value: Optional stat value for the object
        N)r[r~rrrrr~�s
zTree.get_file_sha1cCst|j��dS)zpReturn the modification time for a file.

        :param path: The path that this file can be found at.
        N)r[�get_file_mtimerrrrr��szTree.get_file_mtimecCst|j��dS)z�Return the size of a file in bytes.

        This applies only to regular files.  If invoked on directories or
        symlinks, it will return None.
        N)r[�
get_file_sizerrrrr�szTree.get_file_sizecCst|j��dS)zfCheck if a file is executable.

        :param path: The path that this file can be found at.
        N)r[�
is_executablerrrrr�	szTree.is_executableccs(|D]\}}|�|�f}||fVqdS)aIterate through file contents.

        Files will not necessarily be returned in the order they occur in
        desired_files.  No specific order is guaranteed.

        Yields pairs of identifier, bytes_iterator.  identifier is an opaque
        value supplied by the caller as part of desired_files.  It should
        uniquely identify the file version in the caller's context.  (Examples:
        an index number or a TreeTransform trans_id.)

        bytes_iterator is an iterable of bytestrings for the file.  The
        kind of iterable and length of the bytestrings are unspecified, but for
        this implementation, it is a tuple containing a single bytestring with
        the complete text of the file.

        :param desired_files: a list of (path, identifier) pairs
        N)rz)rZ
desired_filesrZ
identifierZcur_filerrr�iter_files_bytesszTree.iter_files_bytescCst|j��dS)z�Get the target for a given path.

        It is assumed that the caller already knows that path is referencing
        a symlink.
        :param path: The path of the file.
        :return: The path the symlink points to.
        N)r[�get_symlink_targetrrrrr�*szTree.get_symlink_targetcCst|j��dS)a�Return an iterator of revision_id, line tuples.

        For working trees (and mutable trees in general), the special
        revision_id 'current:' will be used for lines that are new in this
        tree, e.g. uncommitted changes.
        :param path: The file to produce an annotated version from
        :param default_revision: For lines that don't match a basis, mark them
            with this revision id. Not all implementations will make use of
            this value.
        N)r[�
annotate_iter)rrZdefault_revisionrrrr�4szTree.annotate_itercCst|j��dS)z$Return the id for path in this tree.N)r[�path2idrrrrr�BszTree.path2idcCs|�|�duS)zfCheck whether path is versioned.

        :param path: Path to check
        :return: boolean
        N)r�rrrr�is_versionedFszTree.is_versionedcCst|j��dS)aHFind related paths in tree corresponding to specified filenames in any
        of `lookup_trees`.

        All matches in all trees will be used, and all children of matched
        directories will be used.

        :param paths: The filenames to find related paths for (if None, returns
            None)
        :param trees: The trees to find file_ids within
        :param require_versioned: if true, all specified filenames must occur in
            at least one tree.
        :return: a set of paths for the specified filenames and their children
            in `tree`
        N)r[�find_related_paths_across_trees)r�paths�treesrNrrrr�Nsz$Tree.find_related_paths_across_treescCst�|j�S)zmLock this tree for multiple read only operations.

        :return: A breezy.lock.LogicalLockResult.
        )rZLogicalLockResult�unlockr rrr�	lock_read`szTree.lock_readcCst�||��dS)aEObtain a revision tree for the revision revision_id.

        The intention of this method is to allow access to possibly cached
        tree data. Implementors of this method should raise NoSuchRevision if
        the tree is not locally available, even if they could obtain the
        tree via a repository or some other means. Callers are responsible
        for finding the ultimate source for a revision tree.

        :param revision_id: The revision_id of the requested tree.
        :return: A Tree.
        :raises: NoSuchRevision if the tree cannot be obtained.
        N)rZNoSuchRevisionInTree)rZrevision_idrrr�
revision_treegs
zTree.revision_treecCstg�S)zoWhat files are present in this tree and unknown.

        :return: an iterator over the unknown files.
        )�iterr rrr�unknownsvsz
Tree.unknownscCsdSr
rr rrrr�}szTree.unlockcst�fdd�|D��S)zMFilter out paths that are versioned.

        :return: set of paths.
        c3s|]}��|�s|VqdSr
)r���.0�pr rr�	<genexpr>��z0Tree.filter_unversioned_files.<locals>.<genexpr>)�set)rr�rr r�filter_unversioned_files�szTree.filter_unversioned_filesr.cCst|j��dS)a�Walk the contents of this tree from path down.

        This yields all the data about the contents of a directory at a time.
        After each directory has been yielded, if the caller has mutated the
        list to exclude some directories, they are then not descended into.

        The data yielded is of the form:
        ((directory-relpath, directory-path-from-root, directory-fileid),
        [(relpath, basename, kind, lstat, path_from_tree_root, file_id,
          versioned_kind), ...]),
         - directory-relpath is the containing dirs relpath from prefix
         - directory-path-from-root is the containing dirs path from /
         - directory-fileid is the id of the directory if it is versioned.
         - relpath is the relative path within the subtree being walked.
         - basename is the basename
         - kind is the kind of the file now. If unknonwn then the file is not
           present within the tree - but it may be recorded as versioned. See
           versioned_kind.
         - lstat is the stat data *if* the file was statted.
         - path_from_tree_root is the path from the root of the tree.
         - file_id is the file_id if the entry is versioned.
         - versioned_kind is the kind of the file as last recorded in the
           versioning system. If 'unknown' the file is not versioned.
        One of 'kind' and 'versioned_kind' must not be 'unknown'.

        :param prefix: Start walking from prefix within the tree rather than
        at the root. This allows one to walk a subtree but get paths that are
        relative to a tree rooted higher up.
        :return: an iterator over the directory data.
        N)r[�walkdirs)r�prefixrrrr��sz
Tree.walkdirscCsdSrArr rrr�supports_content_filtering�szTree.supports_content_filteringcCsZt��}t|�dkrgSt|�|g|��}t�|�}dtjvrVt�	t
d��|||��|S)a�The stack of content filters for a path if filtering is supported.

        Readers will be applied in first-to-last order.
        Writers will be applied in last-to-first order.
        Either the path or the file-id needs to be provided.

        :param path: path relative to the root of the tree
            or None if unknown
        :return: the list of filters - [] if there are none
        r�filtersz$*** {0} content-filter: {1} => {2!r})r�Z_get_registered_namesr?�next�iter_search_rulesZ_get_filter_stack_for�debugZdebug_flagsZtraceZnote�gettext�format)rrZfilter_pref_namesZprefsZstkrrr�_content_filter_stack�s

�zTree._content_filter_stackcCs|��r|jSdSdS)z�A function that returns a stack of ContentFilters.

        The function takes a path (relative to the top of the tree) and a
        file-id as parameters.

        :return: None if content filtering is not supported by this tree.
        N)r�r�r rrr�_content_filter_stack_provider�sz#Tree._content_filter_stack_providerccs\|durtj}|�|�}|durX|durB|D]}|�||�Vq,n|D]}|�|�VqFdS)a�Find the preferences for filenames in a tree.

        :param path_names: an iterable of paths to find attributes for.
          Paths are given relative to the root of the tree.
        :param pref_names: the list of preferences to lookup - None for all
        :param _default_searcher: private parameter to assist testing - don't use
        :return: an iterator of tuple sequences, one per path-name.
          See _RulesSearcher.get_items for details on the tuple sequence.
        N)ZrulesZ_per_user_searcher�_get_rules_searcherZget_selected_itemsZ	get_items)rZ
path_namesZ
pref_namesZ_default_searcher�searcherrrrrr��s
zTree.iter_search_rulescCs|}|S)z:Get the RulesSearcher for this tree given the default one.r)rZdefault_searcherr�rrrr��szTree._get_rules_searcherc	CsLddlm}|���$|||||||d�Wd�S1s>0YdS)aCreate an archive of this tree.

        :param format: Format name (e.g. 'tar')
        :param name: target file name
        :param root: Root directory name (or None)
        :param subdir: Subdirectory to export (or None)
        :return: Iterator over archive chunks
        r)�create_archive)�force_mtimeN)�archiver�r�)rr�r:�rootZsubdirr�r�rrrr��s



�zTree.archivecCs|dvS)z;Check if this tree support versioning a specific file kind.)r,r'r0r2r)�clsr%rrr�versionable_kind�szTree.versionable_kind)FNNFFF)FNNNTF)rc)NF)FNTF)N)N)N)r.)N)NN)r.NN);rrrr#rHrIrJrTrUrYrZr\r]r`rarbrdrfrhrirlrpror%rrrsrurvrwrxrzr{r�r~r�r�r�r�r�Z
_mod_revisionZCURRENT_REVISIONr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��classmethodr�rrrrrG�s��
"�
		

	�


	




�
�


!

�
�
rGc@s�eZdZdZdZdZgZedd��Zdd�Z	ddd	�Z
dddgd
dfdd�Zed
d��Z
ddd�Zddd�Zddd�Zd dd�Zd!dd�Zd"dd�ZdS)#rQa�This class represents operations taking place between two Trees.

    Its instances have methods like 'compare' and contain references to the
    source and target trees these operations are to be carried out on.

    Clients of breezy should not need to use InterTree directly, rather they
    should use the convenience methods on Tree such as 'Tree.compare()' which
    will pass through to InterTree as appropriate.
    NcCsdS)NTr)Zkls�source�targetrrr�
is_compatibleszInterTree.is_compatiblec	Cs�|dur|durdS|j}n|j}|durPd}|j}|j}|j�||�\}	}
}nd}d}d}d}	d}
|dur�d}|j}
|j}|j�||�\}}}nd}d}
d}d}d}||f}|	|f}d}|	|kr�d}np|	dkr�|�||||�s�d}nR|	dk�r|j�|�|j�|�k�r8d}n(|	dk�r8|j�|�|j�|�k�r8d}||f}||
f}|
|f}|du�s�|d|dk�s�|d|dk�s�|d|dk�s�|d|dk�r�d}nd}t	|||f||||||�|fS)	a�Generate a iter_changes tuple between source_entry and target_entry.

        :param source_entry: An inventory entry from self.source, or None.
        :param target_entry: An inventory entry from self.target, or None.
        :param source_path: The path of source_entry.
        :param target_path: The path of target_entry.
        :return: A tuple, item 0 of which is an iter_changes result tuple, and
            item 1 is True if there are any changes in the result tuple.
        NTFr,r0r2rr)
r6r:r9r�rvr��file_content_matchesr�rur4)r�source_entry�target_entry�source_path�target_pathr6Zsource_versionedZsource_nameZ
source_parentZsource_kindZsource_executable�source_statZtarget_versionedZtarget_nameZ
target_parent�target_kind�target_executable�target_statr8r%r7�parentr:r;�changesrrr�_changes_from_entriess��
�
�


�


����

��zInterTree._changes_from_entriesFcCsf|jf}|dur|t|�}|���.tj|j|j||||||d�Wd�S1sX0YdS)a�Return the changes from source to target.

        :return: A TreeDelta.
        :param specific_files: An optional list of file paths to restrict the
            comparison to. When mapping filenames to ids, all matches in all
            trees (including optional extra_trees) are used, and all children of
            matched directories are included.
        :param want_unchanged: An optional boolean requesting the inclusion of
            unchanged entries in the result.
        :param extra_trees: An optional list of additional trees to use when
            mapping the contents of specific_files (paths) to file_ids.
        :param require_versioned: An optional boolean (defaults to False). When
            supplied and True all the 'specific_files' must be versioned, or
            a PathsNotVersionedError will be thrown.
        :param want_unversioned: Scan for unversioned paths.
        N)rMrNrP)r�rBr�ZdeltaZ_compare_treesr�)rrKrLrMrNrOrPr�rrrrSas
�zInterTree.compareTc0#s�|s
g}nt|�}t�}g}�gkr.g}	g}
n4|jj�|jg||d�}	|jj�|jg||d�}
�durvt�}t�}|r�t�fdd�|j��D��}
t|
�}
nt�}
i}t|jj|
d��}t	|�}t|jj|	d��}|�
dd�|D��}t|�t|�}d}t�}|D�]�\}}|
�r�|
dd|�
d�k�r�|
��}|j�||d	�\}}}tdd|d	fd
ddd|dd
fd|fd|f�V�q||}|du�r�|�|�}nd}|j||||d�\}}|jd	||j<|d	7}|jd�r�|d	7}|du�r|�d||�|�s|�r<�du�r6|�|jd	�|�|j�|V�du�r|jd	dk�rb|�|j�|jd�rx|���r|�|jd	��q|
�r�|
��}|j�||d	�\} }!}"tdd|d	fd
ddd|dd
fd| fd|!f�V�q�|D]�\}#}$|$j}%|%|v�r
�q�|�|#�}&|d	7}|du�r4|�d||�d}'|$jdf}(|$jdf})|j�|$|#�\}*}+},|*df}-|+df}.|*du}/|�|%�t|%|#|&f|/|'|(|)|-|.�V�q�t|�}�du�r�|�||�D]}|V�q�dS)a�Generate an iterator of changes between trees.

        A tuple is returned:
        (file_id, (path_in_source, path_in_target),
         changed_content, versioned, parent, name, kind,
         executable)

        Changed_content is True if the file's content has changed.  This
        includes changes to its kind, and to a symlink's target.

        versioned, parent, name, kind, executable are tuples of (from, to).
        If a file is missing in a tree, its kind is None.

        Iteration is done in parent-to-child order, relative to the target
        tree.

        There is no guarantee that all paths are in sorted order: the
        requirement to expand the search due to renames may result in children
        that should be found early being found late in the search, after
        lexically later results have been returned.
        :param require_versioned: Raise errors.PathsNotVersionedError if a
            path in the specific_files list is not versioned in one of
            source, target or extra_trees.
        :param specific_files: An optional list of file paths to restrict the
            comparison to. When mapping filenames to ids, all matches in all
            trees (including optional extra_trees) are used, and all children
            of matched directories are included. The parents in the target tree
            of the specific files up to and including the root of the tree are
            always evaluated for changes too.
        :param want_unversioned: Should unversioned files be returned in the
            output. An unversioned file is defined as one with (False, False)
            for the versioned pair.
        )rNNcs.g|]&}�dust��|�r|�d�|f�qSr()rZ
is_inside_any�splitr��rLrr�
<listcomp>�s�z*InterTree.iter_changes.<locals>.<listcomp>r�cSsg|]\}}|�qSrr)r�r��errrr��r�rr)rT)FFrm���)r�r�zcomparing filesr')TF)�listr�r�r�r��sortedrZrrf�dict�find_source_pathsr?r+r��popleftrvr4rRr�rr6r8�update�addr9�appendr%rE�find_target_pathr:�_handle_precise_ids)0rrWrLrXrMrNrP�precise_file_ids�changed_file_idsZtarget_specific_filesZsource_specific_filesZseen_parentsZ	seen_dirsZall_unversionedZto_pathsZfrom_entries_by_dirZ	from_dataZto_entries_by_dirZpath_equivsZnum_entriesZentry_countZ
fake_entryr�r�Zunversioned_pathr�r�r�r�r��resultr�Zto_kindZ
to_executableZto_statrZ
from_entryr6Zto_pathr8r�r:Z	from_kindZfrom_executabler}r%r;r7rr�rrU}s�$���
������

�



��





�
�

�zInterTree.iter_changescCs6z|j|gd�}t|�dWSty0YdS0dS)aUGet an inventory entry from a tree, with missing entries as None.

        If the tree raises NotImplementedError on accessing .inventory, then
        this is worked around using iter_entries_by_dir on just the file id
        desired.

        :param tree: The tree to lookup the entry in.
        :param path: The path to look up
        r�rN)rfr��
StopIteration)�treer�iteratorrrr�
_get_entrys
zInterTree._get_entryc	cs�|�r�|�d�|�|�|s"�q�g}|D]0}z|�|j�|��Wq*tjyXYq*0q*|D]}|j�|�}|�	|�q`|�d�|}t
�}|D�]D}	|r�|�|	�}
d}nd}
|
du�rLz|j�|	�}Wntjy�d}d}Yn0|�|j|�}z|j�|	�}
Wntj�y&d}
d}Yn0|�|j|
�}|�
||||
�\}
}nd}|
jd}|�	|�|r�|
jddk�r�|
jddk�r�|du�r�|�|j|
jd�}|�dd�|j�|
jd�D��|�	|
j�|
Vq�qdS)a�Fill out a partial iter_changes to be consistent.

        :param precise_file_ids: The file ids of parents that were seen during
            the iter_changes.
        :param changed_file_ids: The file ids of already emitted items.
        :param discarded_changes: An optional dict of precalculated
            iter_changes items which the partial iter_changes had not output
            but had calculated.
        :return: A generator of iter_changes items to output.
        NTrrr'css|]}|jVqdSr
)r6)r��childrrrr��s�z0InterTree._handle_precise_ids.<locals>.<genexpr>)�discard�difference_updater�r�rdr�NoSuchIdr�r�r�r�rRr�r�r9r%rr�rhr6)rr�r�Zdiscarded_changesr�r9rZold_idZcurrent_idsr6r�r�r�r�r�r�Z
new_parent_idrrrr�1st






�
��


�
�
�zInterTree._handle_precise_idscCs�|����|j�||�\}}|j�||�\}}||krL||kWd�S|dkrd|j�||�}	n|}	|dkr�|j�||�}
n|}
|	|
kWd�S1s�0YdS)a$Check if two files are the same in the source and target trees.

        This only checks that the contents of the files are the same,
        it does not touch anything else.

        :param source_path: Path of the file in the source tree
        :param target_path: Path of the file in the target tree
        :param source_stat: Optional stat value of the file in the source tree
        :param target_stat: Optional stat value of the file in the target tree
        :return: Boolean indicating whether the files have the same contents
        Nr|)r�r�r�r�r~)rr�r�r�r�Zsource_verifier_kindZsource_verifier_dataZtarget_verifier_kindZtarget_verifier_dataZsource_sha1Ztarget_sha1rrrr��s(
�����zInterTree.file_content_matches�nonecCsL|j�|�}|durt�|��z|jj||d�WStjyFYdS0dS)z�Find target tree path.

        :param path: Path to search for (exists in source)
        :return: path in target, or None if there is no equivalent path.
        :raise NoSuchFile: If the path doesn't exist in source
        N�re)r�r�r�
NoSuchFiler�rdr��rrrer6rrrr��s
zInterTree.find_target_pathcCsL|j�|�}|durt�|��z|jj||d�WStjyFYdS0dS)z�Find the source tree path.

        :param path: Path to search for (exists in target)
        :return: path in source, or None if there is no equivalent path.
        :raise NoSuchFile: if the path doesn't exist in target
        Nr�)r�r�rr�r�rdr�r�rrr�find_source_path�s
zInterTree.find_source_pathcCs$i}|D]}|j||d�||<q|S)z�Find target tree paths.

        :param paths: Iterable over paths in target to search for
        :return: Dictionary mapping from source paths to paths in target , or
            None if there is no equivalent path.
        r�)r��rr�reZretrrrr�find_target_paths�szInterTree.find_target_pathscCs$i}|D]}|j||d�||<q|S)z�Find source tree paths.

        :param paths: Iterable over paths in target to search for
        :return: Dictionary mapping from target paths to paths in source, or
            None if there is no equivalent path.
        r�)r�r�rrrr��szInterTree.find_source_paths)FNNFFF)N)NN)r�)r�)r�)r�)rrrr#Z_matching_from_tree_formatZ_matching_to_tree_formatZ_optimisersr�r�r�rSrU�staticmethodr�r�r�r�r�r�r�rrrrrQs4

H�
�
#
�
Z�
#


rQr�cCst�||�j||d�S)aFind previous tree paths.

    :param from_tree: From tree
    :param to_tree: To tree
    :param paths: Iterable over paths in from_tree to search for
    :return: Dictionary mapping from from_tree paths to paths in to_tree, or
        None if there is no equivalent path.
    r�)rQrRr�)rV�to_treer�rerrr�find_previous_paths�s	r�cCst�||�j||d�S)aFind previous tree path.

    :param from_tree: From tree
    :param to_tree: To tree
    :param path: Path to search for (exists in from_tree)
    :return: path in to_tree, or None if there is no equivalent path.
    :raise NoSuchFile: If the path doesn't exist in from_tree
    r�)rQrRr�)rVr�rrerrr�find_previous_path�s	�r�c	
Cs�d}t|�d��}|D]�}||�}d}zn|�|�D]^}z@|j|krXt�||j�}Wq�n||j�|krtt�||j�}Wq2tjy�Yq2Yq20q2Wntjy�Yn0|r�|}qtj||gt	|��R�}q�q|S)z�Find the canonical path of an item, ignoring case.

    :param tree: Tree to traverse
    :param path: Case-insensitive path to look up
    :param normalize: Function to normalize a filename for comparison
    :return: The canonical path
    r.r)N)
r�r�rhr:rZpathjoinrr�Z
NotADirectoryr�)	r�rZ	normalizeZcur_pathZbit_iter�eltZlelt�new_pathr�rrr�get_canonical_path�s,	
r�N)r�)r�)"r#Z
__future__r�collections.abcr�ImportError�collectionsr�globalsr.rrrZinterr	Zsixishr
rZBzrErrorrr�objectrr&r+r/r1r4rGrQZregister_optimiserr�r�r�rrrr�<module>s>
7@f