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__/patch.cpython-39.pyc
a

�~�_�0�@s�dZddlmZddlZddlZddlmZmZm	Z	dZ
d%dd�Zdd	�Zd
d�Z
d&dd�Zdd�Zdd�Zdd�Zd'dd�Zdd�Zdd�Zd(dd �Zd)d!d"�Zd*d#d$�ZdS)+z~Classes for dealing with git am-style patches.

These patches are basically unified diffs with some extra metadata tacked
on.
�)�SequenceMatcherN)�Blob�Commit�S_ISGITLINKi@c
	Csl|pt|dd�}t|t�r$|�|�}|\}}|�d|jdt�|j��|�d�|�d|j	d�|�dt�
d��|�d�|�d	||f�|�|jd�|�d�|�d
�z"ddl}|j
d
g|j|jd�}	Wnttfy�Yn$0|	�|�\}
}|�|
�|�d�|�|�|�d�|du�rTddlm}|�d|�n|�|�|�d�dS)z�Write a individual file patch.

    Args:
      commit: Commit object
      progress: Tuple with current patch number and total.
    Returns:
      tuple with filename and contents
    �encoding�asciisFrom � �
�From: sDate: z%a, %d %b %Y %H:%M:%S %ZzSubject: [PATCH %d/%d] �---
rN�diffstat)�stdout�stdin�-- 
)�__version__sDulwich %d.%d.%d
)�getattr�
isinstance�str�encode�write�id�time�ctimeZcommit_time�author�strftime�message�
subprocess�Popen�PIPE�ImportError�OSErrorZcommunicateZdulwichr)
�f�commit�contentsZprogress�versionrZnum�totalr�pr�_Zdulwich_version�r(�//usr/lib/python3/dist-packages/dulwich/patch.py�write_commit_patch(sL


������

�





r*cCs"|jjdd�}|��d�dd�S)zrDetermine the summary line for use in a filename.

    Args:
      commit: Commit
    Returns: Summary string
    �replace)�errorsr� �-)r�decode�
splitlinesr+)r"Zdecodedr(r(r)�get_summaryRsr1cCs:|d}||}|dkr"d�|�S|s.|d8}d�||�S)z Convert range to the "ed" format�z{}z{},{})�format)�start�stopZ	beginningZlengthr(r(r)�_format_range_unified^s
r6���
�utf-8c
cs�d}
td||��|�D�]r}|
s�d}
|r2d�|�nd}|rDd�|�nd}
d�|�|�||��|	�Vd�|�|�|
|��|	�V|d|d	}}t|d
|d�}t|d|d
�}d�|||��|	�V|D]�\}}}}}|dk�r|||�D]}d|Vq�q�|dv�rH|||�D]*}|d	d�dk�s:|d7}d|V�q|dvr�|||�D]*}|d	d�dk�sz|d7}d|V�q\q�qdS)z�difflib.unified_diff that can detect "No newline at end of file" as
    original "git diff" does.

    Based on the same function in Python2.7 difflib.py
    FNTz	{}r7z
--- {}{}{}z
+++ {}{}{}r���r2�r8�z@@ -{} +{} @@{}Zequalr)r+�deleter	s
\ No newline at end of file
�-)r+�insert�+)rZget_grouped_opcodesr3r/rr6)�a�bZfromfileZtofileZfromfiledateZ
tofiledate�nZlinetermZ
tree_encodingZoutput_encodingZstarted�groupZfromdateZtodate�firstZlastZfile1_rangeZfile2_range�tagZi1Zi2Zj1Zj2�liner(r(r)�unified_diffjsZ������

rIcCsd|dt�vS)z}See if the first few bytes contain any null characters.

    Args:
      content: Bytestring to check for binary content
    �N)�FIRST_FEW_BYTES��contentr(r(r)�	is_binary�srNcCs|durdS|dd�SdS)Ns0000000�r()�hexshar(r(r)�shortid�srQcCs|durdS|d|SdS)Ns	/dev/null�/r()r&�rootr(r(r)�patch_filename�srTFcs�|\}}}|\}}	}
t|d�}t|d�}�fdd�}
dd�}|�t||f||	f||
f��|
||�}|
|	|
�}|s�t|j�s�t|j�r�d|d|d	}|�|�n|�t||�||�||��d
S)a�Write the diff for an object.

    Args:
      f: File-like object to write to
      store: Store to retrieve objects from, if necessary
      old_file: (path, mode, hexsha) tuple
      new_file: (path, mode, hexsha) tuple
      diff_binary: Whether to diff files even if they
        are considered binary files by is_binary().

    Note: the tuple elements should be None for nonexistant files
    �a�bcs8|durt�d�St|�r,t�d|d�S�|SdS)N�sSubproject commit r	)rZfrom_stringr)�moderP��storer(r)rM�s

z"write_object_diff.<locals>.contentcSs|sgS|��SdS�N�r0rLr(r(r)�lines�sz write_object_diff.<locals>.liness
Binary files s and s differ
N)rT�
writelines�gen_diff_headerrN�datarrI)r!rZ�old_file�new_file�diff_binary�old_path�old_modeZold_id�new_path�new_modeZnew_id�patched_old_path�patched_new_pathrMr]Zold_contentZnew_contentZbinary_diffr(rYr)�write_object_diff�s<



�

��������rjc	cs�|\}}|\}}|\}}|dur,|dur,|}|dur@|dur@|}t|d�}t|d�}d|d|dV||kr�|dur�|dur�d|�d�Vd	|�d�Vnd
|�d�Vdt|�dt|�V|dur�|dur�d
|�d�VdVdS)z�Write a blob diff header.

    Args:
      paths: Tuple with old and new path
      modes: Tuple with old and new modes
      shas: Tuple with old and new shas
    NrUrVsdiff --git rr	zold file mode %o
rznew file mode %o
zdeleted file mode %o
sindex s..z %o)rTrrQ)	�pathsZmodesZshasrdrfrergZold_shaZnew_shar(r(r)r_�s(

r_c
Cs�|\}}}|\}}}t|d�}	t|d�}
dd�}|�t||f||ft|dd�t|dd�f��||�}||�}
|�t||
|	|
��dS)aWrite blob diff.

    Args:
      f: File-like object to write to
      old_file: (path, mode, hexsha) tuple (None if nonexisting)
      new_file: (path, mode, hexsha) tuple (None if nonexisting)

    Note: The use of write_object_diff is recommended over this function.
    rUrVcSs|dur|��SgSdSr[r\)Zblobr(r(r)r]szwrite_blob_diff.<locals>.linesrN)rTr^r_rrI)r!rarbrdreZold_blobrfrgZnew_blobrhrir]Zold_contentsZnew_contentsr(r(r)�write_blob_diffs




�
�rlcCsJ|�||�}|D]4\\}}\}}	\}
}t|||||
f||	|f|d�qdS)z�Write tree diff.

    Args:
      f: File-like object to write to.
      old_tree: Old tree id
      new_tree: New tree id
      diff_binary: Whether to diff files even if they
        are considered binary files by is_binary().
    )rcN)Ztree_changesrj)r!rZZold_treeZnew_treercZchangesZoldpath�newpathZoldmodeZnewmodeZoldshaZnewshar(r(r)�write_tree_diff%s


�rncCsl|pt|dd�}|pd}|��}t|t�rNttjdd�rNtj��}|�|�}ntj��}|�	|�}t
||�S)z�Parse a git-am-style patch and split it up into bits.

    Args:
      f: File-like object to parse
      encoding: Encoding to use when creating Git objects
    Returns: Tuple with commit object, diff contents and git version
    rr�BytesParserN)r�readr�bytes�email�parserroZ
parsebytesZParserZparsestr�parse_patch_message)r!rr#rs�msgr(r(r)�git_am_patch_split5s
�


rvc
Csvt�}|d�|�|_|d�|�|_z|d�d�}WntyR|d}Yn&0|d�d|�}|d|dd�}|�dd�d�|�|_d	}|jd	d
�}|�	d	�}t
|�}	|	D]`}
|
dkr��q|�r|
�d�r�|
td�d��
�|_n|jd
|
7_d}q�|j|
7_q�d}|	D]}
|
dk�r4�q@||
7}�q zt|	��
d
�}Wnt�yjd}Yn0|||fS)z�Extract a Commit object and patch from an e-mail message.

    Args:
      msg: An email message (email.message.Message)
      encoding: Encoding to use to encode Git commits
    Returns: Tuple with commit object, diff contents and git version
    �from�subjectz[PATCHz] r<Nr9r7T)r/rr
r	FrWr)rrrZ	committer�index�
ValueErrorr+rZget_payloadr0�iter�
startswith�len�rstrip�next�
StopIteration)
rur�cZpatch_tag_startrx�closerF�bodyr]Z	line_iterrHZdiffr$r(r(r)rtJsB



rt)NN)r7r7r7r7r8r9r:r:)F)F)N)N)�__doc__ZdifflibrZemail.parserrrrZdulwich.objectsrrrrKr*r1r6rIrNrQrTrjr_rlrnrvrtr(r(r(r)�<module>s.�
*�
3	
3!