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/dulwich/__pycache__/diff_tree.cpython-39.pyc
a

�~�_XY�@s\dZddlmZmZddlmZddlmZddlZddl	m
Z
mZdZdZ
d	Zd
ZdZdZeefZeddd�Zd
ZdZdZdZGdd�dedgd���Zdd�Zdd�Zdd�Zd2dd�Zdd�Zd3dd�Zd d!�Zd"d#�Z d4d$d%�Z!d&Z"d'd(�Z#d)d*�Z$d5d+d,�Z%d-d.�Z&Gd/d0�d0e'�Z(eZ)eZ*e#Z+zdd1l,mZmZm#Z#Wne-�yVYn0dS)6z&Utilities for diffing files and trees.�)�defaultdict�
namedtuple)�BytesIO)�chainN)�S_ISGITLINK�	TreeEntry�addZmodify�delete�rename�copyZ	unchanged�d�<��c@s(eZdZdZedd��Zedd��ZdS)�
TreeChangez.Named tuple a single change between two trees.cCs|tt|�S�N)�
CHANGE_ADD�_NULL_ENTRY)�cls�new�r�3/usr/lib/python3/dist-packages/dulwich/diff_tree.pyr;szTreeChange.addcCs|t|t�Sr)�
CHANGE_DELETEr)r�oldrrrr	?szTreeChange.deleteN)�__name__�
__module__�__qualname__�__doc__�classmethodrr	rrrrr8s

r)�typerrcCs2g}|s|S|jdd�D]}|�|�|��q|S)NT)Z
name_order)Z	iteritems�appendZin_path)�pathZtree�result�entryrrr�
_tree_entriesDsr#c
Cst||�}t||�}d}}t|�}t|�}g}	||kr�||kr�||}
||}|
j|jkrt|	�|
tf�|d7}q0|
j|jkr�|	�t|f�|d7}q0|	�|
|f�|d7}|d7}q0t||�D]}|	�||tf�q�t||�D]}|	�t||f�q�|	S)a�Merge the entries of two trees.

    Args:
      path: A path to prepend to all tree entry names.
      tree1: The first Tree object to iterate, or None.
      tree2: The second Tree object to iterate, or None.
    Returns:
      A list of pairs of TreeEntry objects for each pair of entries in
        the trees. If an entry exists in one tree but not the other, the other
        entry will have all attributes set to None. If neither entry's path is
        None, they are guaranteed to match.
    r�)r#�lenr rr�range)
r �tree1�tree2Zentries1Zentries2Zi1Zi2Zlen1Zlen2r!�entry1�entry2�irrr�_merge_entriesMs.




r,cCs|j}|durdSt�|�S�NF)�mode�stat�S_ISDIR)r"r.rrr�_is_treeusr1Fccs�|r
tjpd}|rtjpd}td||�td||�fg}|r�|��\}}t|�}	t|�}
|rl|	rl|
rl||krlq6|	rz||jp|d}|
r�||jp�d}|jp�|j}
|�tt	|
||���||fVq6dS)a�Recursively walk all the entries of two trees.

    Iteration is depth-first pre-order, as in e.g. os.walk.

    Args:
      store: An ObjectStore for looking up objects.
      tree1_id: The SHA of the first Tree object to iterate, or None.
      tree2_id: The SHA of the second Tree object to iterate, or None.
      param prune_identical: If True, identical subtrees will not be walked.
    Returns:
      Iterator over Pairs of TreeEntry objects for each pair of entries
        in the trees and their subtrees recursively. If an entry exists in one
        tree but not the other, the other entry will have all attributes set
        to None. If neither entry's path is None, they are guaranteed to
        match.
    N�)
r/�S_IFDIRr�popr1�shar �extend�reversedr,)�store�tree1_id�tree2_id�prune_identicalZmode1Zmode2Ztodor)r*Zis_tree1Zis_tree2r'r(r rrr�
walk_trees|sr<cCs"|jdus|st�|j�rtS|Sr)r.r/r0r)r"�
include_treesrrr�
_skip_tree�sr>ccs|dur:|dur:|dur:|j||||d�D]
}|Vq*dSt||||d�}|D]�\}	}
|	|
krf|sfqPt|	|�}	t|
|�}
|	tkr�|
tkr�t�|	j�t�|
j�kr�|s�t�|	�Vt}	t	}q�|	|
kr�t
}q�t}n|	tkr�t}n|
tkrPt	}nqPt||	|
�VqPdS)auFind the differences between the contents of two trees.

    Args:
      store: An ObjectStore for looking up objects.
      tree1_id: The SHA of the source tree.
      tree2_id: The SHA of the target tree.
      want_unchanged: If True, include TreeChanges for unmodified entries
        as well.
      include_trees: Whether to include trees
      rename_detector: RenameDetector object for detecting renames.
      change_type_same: Whether to report change types in the same
        entry or as delete+add.
    Returns:
      Iterator over TreeChange instances for each change between the
        source and target tree.
    N��want_unchangedr=)r;)
�changes_with_renamesr<r>rr/�S_IFMTr.rr	r�CHANGE_UNCHANGED�
CHANGE_MODIFYr)r8r9r:r@�rename_detectorr=Zchange_type_same�change�entriesr)r*�change_typerrr�tree_changes�sB��
�

�rIcCs |D]}||�|krdSqdS)NFTr)�seq�key�value�errr�_all_eq�srNcCst|dd�|||d��S)Nr$r)rN)rJrKrrr�	_all_same�srOc#s����fdd�|D�}t|��t�fdd��}t|�D]:\}}|D],}|jtkrZ|jj}	n|jj}	|||	|<qBq6dd�}
dd�}t|�	��D]d\}}
t|
��ks�J�d	d�|
D�}t
||t�r�t||
�s�|
Vq�t||�s�|
Vq�d
|
vr�|
Vq�d
S)aBGet the tree changes for a merge tree relative to all its parents.

    Args:
      store: An ObjectStore for looking up objects.
      parent_tree_ids: An iterable of the SHAs of the parent trees.
      tree_id: The SHA of the merge tree.
      rename_detector: RenameDetector object for detecting renames.

    Returns:
      Iterator over lists of TreeChange objects, one per conflicted path
      in the merge.

      Each list contains one element per parent, with the TreeChange for that
      path relative to that parent. An element may be None if it never
      existed in one parent and was deleted in two others.

      A path is only included in the output if it is a conflict, i.e. its SHA
      in the merge tree is not found in any of the parents, or in the case of
      deletes, if not all of the old SHAs match.
    csg|]}t�|��d��qS))rE)rI)�.0�t)rEr8�tree_idrr�
<listcomp>s��z*tree_changes_for_merge.<locals>.<listcomp>cs
dg�Srrr)�num_parentsrr�<lambda>r2z(tree_changes_for_merge.<locals>.<lambda>cSs|jjSr)rr5��crrr�old_shasz'tree_changes_for_merge.<locals>.old_shacSs|jSr)rrVrrrrHsz+tree_changes_for_merge.<locals>.change_typecSsg|]}|dur|�qSrr)rPrWrrrrSr2N)r%r�	enumeraterrrr r�sorted�itemsrNrO)r8Zparent_tree_idsrRrEZall_parent_changesZchanges_by_pathr+Zparent_changesrFr rXrH�_ZchangesZhaver)rTrEr8rRr�tree_changes_for_merge�s.�



r]�@cCs�tt�}t�}d}|j}|j}|j}|j}t�|�	��D]`}|�
dd�}||�|d7}|dksh|tkr8|�}	|t|	�t
|	�7<|d�|�d}q8|dkr�|�}
|t|
�t
|
�7<|S)z�Count the blocks in an object.

    Splits the data into blocks either on lines or <=64-byte chunks of lines.

    Args:
      obj: The object to count blocks for.
    Returns:
      A dict of block hashcode -> total bytes occurring.
    rr$Zbig�
)r�intr�write�seek�truncate�getvaluer�
from_iterableZ
as_raw_chunks�to_bytes�_BLOCK_SIZE�hashr%)�objZblock_counts�block�nZblock_writeZ
block_seekZblock_truncateZblock_getvaluerWrLZ
last_blockrrr�
_count_blocks)s*
rlcCsPt|�t|�kr||}}d}|��D]$\}}|�|�}|r&|t||�7}q&|S)aWCount the number of common bytes in two block count dicts.

    Args:
      block1: The first dict of block hashcode -> total bytes.
      block2: The second dict of block hashcode -> total bytes.
    Returns:
      The number of bytes in common between blocks1 and blocks2. This is
      only approximate due to possible hash collisions.
    r)r%r[�get�min)Zblocks1Zblocks2�scorerjZcount1Zcount2rrr�
_common_bytesMs

rpcCs�|duri}|j|vr$t|�||j<|j|vr<t|�||j<t||j||j�}t|��|���}|sltStt|�t|�S)a�Compute a similarity score for two objects.

    Args:
      obj1: The first object to score.
      obj2: The second object to score.
      block_cache: An optional dict of SHA to block counts to cache
        results between calls.
    Returns:
      The similarity score between the two objects, defined as the
        number of bytes in common between the two objects divided by the
        maximum size, scaled to the range 0-100.
    N)�idrlrp�maxZ
raw_length�
_MAX_SCOREr`�float)Zobj1Zobj2�block_cacheZcommon_bytesZmax_sizerrr�_similarity_scorebs


rvcCs0|jj}|jj}|dur|}|dur(|}||fSr)rr r)r"Zpath1Zpath2rrr�_tree_change_key}srwc@s�eZdZdZeeedfdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd"dd �Zd!S)#�RenameDetectorz7Object for handling rename detection between two trees.FcCs(||_||_||_||_||_d|_dS)a�Initialize the rename detector.

        Args:
          store: An ObjectStore for looking up objects.
          rename_threshold: The threshold similarity score for considering
            an add/delete pair to be a rename/copy; see _similarity_score.
          max_files: The maximum number of adds and deletes to consider,
            or None for no limit. The detector is guaranteed to compare no more
            than max_files ** 2 add/delete pairs. This limit is provided
            because rename detection can be quadratic in the project size. If
            the limit is exceeded, no content rename detection is attempted.
          rewrite_threshold: The threshold similarity score below which a
            modify should be considered a delete/add, or None to not break
            modifies; see _similarity_score.
          find_copies_harder: If True, consider unmodified files when
            detecting copies.
        FN)�_store�_rename_threshold�_rewrite_threshold�
_max_files�_find_copies_harder�_want_unchanged)�selfr8Zrename_thresholdZ	max_filesZrewrite_thresholdZfind_copies_harderrrr�__init__�szRenameDetector.__init__cCsg|_g|_g|_dSr)�_adds�_deletes�_changes�rrrr�_reset�szRenameDetector._resetcCsT|jdus$|jtks$|jj|jjkr(dS|j|jj}|j|jj}t||�|jkSr-)r{rrDrr5rryrv)rrF�old_obj�new_objrrr�
_should_split�s�zRenameDetector._should_splitcCs�|jtkr|j�|�n�|jtkr0|j�|�nh|�|�rd|j�t�|j	��|j�t�
|j��n4|jrt|jt
ks~|jtkr�|j�|�n|j�|�dSr)rrr�rrr�r�rr	rrrr}rCrDr�)rrFrrr�_add_change�s


�zRenameDetector._add_changecCs6|jp
|j}t|j||||jd�D]}|�|�q"dS)Nr?)r}r~rIry�_include_treesr�)rr9r:r@rFrrr�_collect_changes�s
�
zRenameDetector._collect_changescs0�fdd�|jD�|_�fdd�|jD�|_dS)Ncsg|]}|jj�vr|�qSr�rr �rP�a)�	add_pathsrrrS�r2z)RenameDetector._prune.<locals>.<listcomp>csg|]}|jj�vr|�qSr�rr �rP�d)�delete_pathsrrrS�s�)r�r�)rr�r�r)r�r�r�_prune�szRenameDetector._prunecCs\tt�}|jD]}||jj�|j�qtt�}|jD]&}|jtk}||j	j�|j	|f�q6t
�}t
�}|��D]�\}}	||}
t|	|
�D]b\\}}}t
�|j�t
�|j�kr�q�|r�|�|j�|�|j�|r�tp�t}
|j�t|
||��q�t|
�t|	�}|	dd}|dkrr|
|d�D]&}|�|j�|j�tt||���q"qr|�||�dS)Nr)r�listr�rr5rr�rrr�setr[�zipr/rBr.rr �
CHANGE_RENAME�CHANGE_COPYr�rr%r�)rZadd_mapr�
delete_mapr	Z	is_deleter�r�r5Zsha_deletesZsha_addsrr�new_typeZnum_extra_addsrrr�_find_exact_renames�s4


z"RenameDetector._find_exact_renamescCst|j�t|j�|jdkS)N�)r%r�r�r|r�rrr�_should_find_content_renames�sz+RenameDetector._should_find_content_renamescCs*|r|jj|jjkrtS|jtkr&tStSr)rr rrDrrr�r�)r�check_pathsr	rrrr�_rename_type�s

zRenameDetector._rename_typecCs�g}|_|��sdSi}|jdu}|jD]�}t|jj�r<q*|jj}|j|}t	|�||<|j
D]v}t�|jj�t�|j
j�kr�q`|j|j
j}t|||d�}	|	|jkr`|�|||�}
t|
|j|j
�}|�|	|f�q`q*dS)N)ru)�_candidatesr�rzr�rrr.r5ryrlr�r/rBrrvr�rr)rZ
candidatesrur�r	rXr�rr�ror�r
rrr�_find_content_rename_candidatess,




�
z.RenameDetector._find_content_rename_candidatescCs�|j��t�}t�}|jD]h\}}|jj}||vr6q|jj}|j}||vr\tt|j|j�}|tkrn|�	|�|�	|�|j
�|�q|�||�dSr)
r��sortr�rr rrrr�rr�rr�)rr�r�r\rF�new_pathZold_pathZ	orig_typerrr�_choose_content_renames s 


z&RenameDetector._choose_content_renamescs�|jdurdSi�tdd�|jD��}|jD]N}|jj}|�|�}|dur,t�|j	j
�t�|jj
�kr,tt|j	|j��|<q,�fdd�|jD�|_�fdd�|jD�|_|j
���7_
dS)Ncss|]}|jj|fVqdSrr�r�rrr�	<genexpr>=r2z0RenameDetector._join_modifies.<locals>.<genexpr>csg|]}|jj�vr|�qSrr�r��ZmodifiesrrrSEr2z1RenameDetector._join_modifies.<locals>.<listcomp>csg|]}|jj�vr|�qSrr�r�r�rrrSFs�)r{�dictr�r�rr rmr/rBrr.rrDr��values)rr�rr r	rr�r�_join_modifies8s


�zRenameDetector._join_modifiescCs8g}|�|j�|�|j�|�|j�|jtd�|S)N)rK)r6r�r�r�r�rw)rr!rrr�_sorted_changesJszRenameDetector._sorted_changescCs |jr
dSdd�|jD�|_dS)NcSsg|]}|jtkr|�qSr)rrCr�rrrrSUsz3RenameDetector._prune_unchanged.<locals>.<listcomp>)r~r�r�rrr�_prune_unchangedRs
�zRenameDetector._prune_unchangedcCsP|��||_||_|�||�|��|��|��|��|��|�	�S)zAIterate TreeChanges between two tree SHAs, with rename detection.)
r�r~r�r�r�r�r�r�r�r�)rr9r:r@r=rrrrAXsz#RenameDetector.changes_with_renamesN)FF)rrrr�RENAME_THRESHOLD�	MAX_FILES�REWRITE_THRESHOLDr�r�r�r�r�r�r�r�r�r�r�r�r�r�rArrrrrx�s,�
!�rx)r1r,rl)F)FNFF)N)N).r�collectionsrr�ior�	itertoolsrr/Zdulwich.objectsrrrrDrr�r�rCZRENAME_CHANGE_TYPESrrsr�r�r�rr#r,r1r<r>rIrNrOr]rgrlrprvrw�objectrxZ_is_tree_pyZ_merge_entries_pyZ_count_blocks_pyZdulwich._diff_tree�ImportErrorrrrr�<module>sZ	(
$�
:�
;$
a