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

�*�^��@s�ddlmZddlZddlZddlmZmZddlZddlZddl	m
Z
mZddlm
Z
Gdd�de�ZGd	d
�d
e�ZdZejdkr�d
Zddd�Zddd�Zdd�Zddd�Zddd�Zdd�ZdS)�)�absolute_importN)�Popen�PIPE�)�NoDiff3�BzrError)�check_text_pathc@seZdZdZdS)�PatchFailedzPatch application failedN)�__name__�
__module__�__qualname__�_fmt�rr�./usr/lib/python3/dist-packages/breezy/patch.pyr	sr	c@seZdZdZdZddd�ZdS)�PatchInvokeErrorz*Error invoking patch: %(errstr)s%(stderr)sF�cCs"||_t�|j�|_d||_dS)N�
)Z	exception�os�strerror�errnoZerrstr�stderr)�self�errrr�__init__)szPatchInvokeError.__init__N)r)r
rrr
Zinternal_errorrrrrrr$srT�ntFrcCsVt|t|�ttttd�}|�|�\}}|��}|dkrLtd|d|f��|||fS)aSpawn a process, and wait for the result

    If the process is killed, an exception is raised

    :param args: The command line, the first entry should be the program name
    :param input: [optional] The text to send the process on stdin
    :return: (stdout, stderr, status)
    )�bufsize�stdin�stdoutrZ	close_fdsrz%s killed by signal %i)r�lenr�
_do_close_fdsZcommunicate�wait�	Exception)�args�input�processrr�statusrrr�write_to_cmd4s	�r&cCsJgd�}|r|�d�|dur,|�d|f�|�|�t||�\}}}|S)a6Apply a patch to a file, to produce another output file.  This is should
    be suitable for our limited purposes.

    :param patch_contents: The contents of the patch to apply
    :type patch_contents: str
    :param filename: the name of the file to apply the patch to
    :type filename: str
    :param output_filename: The filename to produce.  If None, file is     modified in-place
    :type output_filename: str or NoneType
    :param reverse: If true, apply the patch in reverse
    :type reverse: bool
    :return: 0 on success, 1 if some hunks failed
    )�patch�-f�-s�--posix�--binaryz	--reverseN�-o)�append�extendr&)Zpatch_contents�filenameZoutput_filename�reverser"rrr%rrrr'Fs

r'c
Cs�dd�}t|�t|�t|�gd�}||d�||d�||d�|�|||f�zt|�\}}}Wn8ty�}	z |	jtjkr�t�n�WYd}	~	n
d}	~	00|dvr�t|��t|d��}
|
�	|�Wd�n1s�0Y|S)	NcSs|�d|f�dS)Nz-L)r.)r"Zlabelrrr�	add_label`szdiff3.<locals>.add_label)�diff3z-Ez--mergeZTREEZANCESTORzMERGE-SOURCE)rr�wb)
rr.r&�OSErrorrZENOENTrr!�open�write)Zout_fileZ	mine_pathZ
older_pathZ
yours_pathr1r"�outputrr%r�frrrr2_s(


(r2c	Cst|j||||||d�S)z�Apply a patch to a tree.

    Args:
      tree: A MutableTree object
      patches: list of patches as bytes
      strip: Strip X segments of paths
      reverse: Apply reversal of patch
      dry_run: Dry run
    )�out)�	run_patchZbasedir)Ztree�patches�stripr0�dry_run�quietr9rrr�
patch_treexs�r?c	
Csp|d|dd|dg}	|r"|	�d�tjdkr6|	�d�|rD|	�d�|rptj�d	�r`|	�d
�n
|	�d�t}
nd}
|dur�|	�|�zt|	tt|
d�}Wn,ty�}zt|��WYd}~n
d}~00z(|D]}
|j�	t
|
��q�|j��Wn6t�y&}zt||j
����WYd}~n
d}~00|��}|�s\|du�rR|�	|j���n
|j��|d
k�rlt��|S)Nz-dr)z-p%dr(z--quietZwin32r+z-RZfreebsdz--checkz	--dry-run)rrrr)r-�sys�platform�
startswithrrr4rrr6�bytes�close�IOErrorr�readr rr	)Z	directoryr;r<r0r=r>Z
_patch_cmdZtarget_filer9r"rr$rr'�resultrrrr:�sB





&


r:cCs�t���`}|�|�|��d�dd�|D��}dddddd	d
|jdd
g
}t||�\}}}Wd�n1sn0Y|d
kr�|gSt|��dS)a3Iterate through a series of lines with a patch applied.
    This handles a single file, and does exact, not fuzzy patching.

    :param orig_lines: The unpatched lines.
    :param hunks: An iterable of Hunk instances.

    This is different from breezy.patches in that it invokes the patch
    command.
    �cSsg|]}|���qSr)Zas_bytes)�.0Zhunkrrr�
<listcomp>�rHz+iter_patched_from_hunks.<locals>.<listcomp>r'r(r)r*r+r,�-z-rNr)�tempfileZNamedTemporaryFile�
writelines�flush�join�namer&r	)Z
orig_linesZhunksr8Z
serializedr"rrr%rrr�iter_patched_from_hunks�s



�.rQ)r)NF)rFFFN)rFFFr'NN)Z
__future__rrr�
subprocessrrr@rL�errorsrrZtextfilerr	rrrPr&r'r2r?r:rQrrrr�<module>s,


�
�
.