§
    cÌcŸ  ã                   óà   — d Z ddlZddlZddlmZmZ ddlZddlZddlm	Z	m
Z
 ddlmZ  G d„ de
¦  «        Z G d	„ d
e
¦  «        ZdZej        dk    rdZdd„Zdd„Zd„ Z	 	 dd„Z	 	 dd„Zd„ ZdS )zDiff and patch functionalityé    N)ÚPopenÚPIPEé   )ÚNoDiff3ÚBzrError)Úcheck_text_pathc                   ó   — e Zd ZdZdS )ÚPatchFailedzPatch application failedN)Ú__name__Ú
__module__Ú__qualname__Ú_fmt© ó    ú./usr/lib/python3/dist-packages/breezy/patch.pyr
   r
      s   € € € € € à)€D€D€Dr   r
   c                   ó   — e Zd ZdZdZdd„ZdS )ÚPatchInvokeErrorz*Error invoking patch: %(errstr)s%(stderr)sFÚ c                 ód   — || _         t          j        |j        ¦  «        | _        d|z   | _        d S )Nú
)Ú	exceptionÚosÚstrerrorÚerrnoÚerrstrÚstderr)ÚselfÚer   s      r   Ú__init__zPatchInvokeError.__init__'   s+   € ØˆŒÝ”k !¤'Ñ*Ô*ˆŒØ˜V‘mˆŒˆˆr   N©r   )r   r   r   r   Úinternal_errorr   r   r   r   r   r   "   s2   € € € € € à;€DØ€Nð$ð $ð $ð $ð $ð $r   r   TÚntFr   c                 ó  — t          | t          |¦  «        t          t          t          t          ¬¦  «        }|                     |¦  «        \  }}|                     ¦   «         }|dk     rt          d| d         | fz  ¦  «        ‚|||fS )a  Spawn 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Ústdoutr   Ú	close_fdsr   z%s killed by signal %i)r   Úlenr   Ú_do_close_fdsÚcommunicateÚwaitÚ	Exception)ÚargsÚinputÚprocessr&   r   Ústatuss         r   Úwrite_to_cmdr1   2   s„   € õ �D¥# e¡*¤*µDÅÝ­=ð:ñ :ô :€Gà×(Ò(¨Ñ/Ô/�N€FˆFØ�\Š\‰^Œ^€FØ�‚z€zÝÐ0°D¸´G¸f¸WÐ3EÑEÑFÔFÐFØ�6˜6Ð!Ð!r   c                 óÀ   — g d¢}|r|                      d¦  «         |�|                     d|f¦  «         |                      |¦  «         t          || ¦  «        \  }}}|S )a6  Apply 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Úextendr1   )Úpatch_contentsÚfilenameÚoutput_filenameÚreverser-   r&   r   r0   s           r   r3   r3   D   ss   € ð 8Ð7Ð7€DØð !Ø�Š�KÑ Ô Ð ØÐ"Ø�Š�T˜?Ð+Ñ,Ô,Ð,Ø‡K‚K�ÑÔÐÝ)¨$°Ñ?Ô?Ñ€FˆF�FØ€Mr   c                 ó  — d„ }t          |¦  «         t          |¦  «         t          |¦  «         g d¢} ||d¦  «          ||d¦  «          ||d¦  «         |                     |||f¦  «         	 t          |¦  «        \  }}}n/# t          $ r"}	|	j        t          j        k    rt          ‚‚ d }	~	ww xY w|dvrt          |¦  «        ‚t          | d¦  «        5 }
|
 	                    |¦  «         d d d ¦  «         n# 1 swxY w Y   |S )Nc                 ó4   — |                       d|f¦  «         d S )Nz-L)r:   )r-   Úlabels     r   Ú	add_labelzdiff3.<locals>.add_label^   s   € Ø�Š�T˜5�MÑ"Ô"Ð"Ð"Ð"r   )Údiff3z-Ez--mergeÚTREEÚANCESTORzMERGE-SOURCE)r   r   Úwb)
r   r:   r1   ÚOSErrorr   ÚENOENTr   r,   ÚopenÚwrite)Úout_fileÚ	mine_pathÚ
older_pathÚ
yours_pathrB   r-   Úoutputr   r0   r   Úfs              r   rC   rC   ]   sw  € ð#ð #ð #å�IÑÔÐÝ�JÑÔÐÝ�JÑÔÐØ%Ð%Ð%€DØ€Iˆd�FÑÔÐØ€Iˆd�JÑÔÐØ€Iˆd�NÑ#Ô#Ð#Ø‡K‚K�˜J¨
Ð3Ñ4Ô4Ð4ðÝ!-¨dÑ!3Ô!3Ñˆ�˜˜øÝð ð ð ØŒ7•e”lÒ"Ð"ÝˆMàøøøøð	øøøð
 �VÐÐÝ˜ÑÔÐÝ	ˆh˜Ñ	Ô	ð  Ø	�Š�‰Œˆðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð à€Ms*   Á2B Â
B2ÂB-Â-B2ÃC:Ã:C>ÄC>c           	      ó8   — t          | j        ||||||¬¦  «        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_patchÚbasedir)ÚtreeÚpatchesÚstripr>   Údry_runÚquietrR   s          r   Ú
patch_treerZ   v   s,   € õ �T”\ 7¨E°7¸GØ ð%ñ %ô %ð %r   r3   c	                 ó   — |d| dd|z  dg}	|r|	                      d¦  «         t          j        dk    r|	                      d¦  «         |r|	                      d¦  «         |rRt          j                             d	¦  «        r|	                      d
¦  «         n|	                      d¦  «         t          }
nd }
|�|	                      |¦  «         	 t          |	t          t          |
¬¦  «        }n!# t          $ r}t          |¦  «        ‚d }~ww xY w	 |D ])}|j         	                    t          |¦  «        ¦  «         Œ*|j                             ¦   «          n9# t          $ r,}t          ||j                             ¦   «         ¦  «        ‚d }~ww xY w|                     ¦   «         }|sH|�-| 	                    |j                             ¦   «         ¦  «         n|j                             ¦   «          |dk    rt!          ¦   «         ‚|S )Nz-dr5   z-p%dr4   z--quietÚwin32r7   z-RÚfreebsdz--checkz	--dry-run)r%   r&   r   r   )r9   ÚsysÚplatformÚ
startswithr   r   rG   r   r%   rJ   ÚbytesÚcloser   Úreadr+   r&   r
   )Ú	directoryrV   rW   r>   rX   rY   Ú
_patch_cmdÚtarget_filerR   r-   r   r/   r   r3   Úresults                  r   rS   rS   …   s  € à˜˜i¨¨v¸©~¸tÐD€DØð Ø�Š�IÑÔÐå
„|�wÒÐØ�Š�JÑÔÐàð Ø�Š�DÑÔÐØð ÝŒ<×"Ò" 9Ñ-Ô-ð 	%Ø�KŠK˜	Ñ"Ô"Ð"Ð"à�KŠK˜Ñ$Ô$Ð$ÝˆˆàˆØÐØ�Š�KÑ Ô Ð ð"Ý˜¥Dµ¸fÐEÑEÔEˆˆøÝð "ð "ð "Ý˜qÑ!Ô!Ð!øøøøð"øøøð9Øð 	.ð 	.ˆEØŒM×Ò¥ e¡¤Ñ-Ô-Ð-Ð-ØŒ×ÒÑÔÐÐøåð 9ð 9ð 9Ý˜q '¤.×"5Ò"5Ñ"7Ô"7Ñ8Ô8Ð8øøøøð9øøøð �\Š\‰^Œ^€FØð "Øˆ?Ø�IŠI�g”n×)Ò)Ñ+Ô+Ñ,Ô,Ð,Ð,àŒN×ÒÑ!Ô!Ð!Ø�‚{€{Ý‰mŒmÐà€Ms1   ÃC+ Ã+
D	Ã5DÄD	ÄAE Å
F	Å'FÆF	c                 ób  — t          j        ¦   «         5 }|                     | ¦  «         |                     ¦   «          d                     d„ |D ¦   «         ¦  «        }ddddddd	|j        d
d	g
}t          ||¦  «        \  }}}ddd¦  «         n# 1 swxY w Y   |dk    r|gS t          |¦  «        ‚)a3  Iterate 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.
    r   c                 ó6   — g | ]}|                      ¦   «         ‘ŒS r   )Úas_bytes)Ú.0Úhunks     r   ú
<listcomp>z+iter_patched_from_hunks.<locals>.<listcomp>Â   s    € ÐAÐAÐA°4˜tŸ}š}™œÐAÐAÐAr   r3   r4   r5   r6   r7   r8   ú-z-rNr   )ÚtempfileÚNamedTemporaryFileÚ
writelinesÚflushÚjoinÚnamer1   r
   )Ú
orig_linesÚhunksrP   Ú
serializedr-   r&   r   r0   s           r   Úiter_patched_from_hunksrx   ³   s  € õ 
Ô	$Ñ	&Ô	&ð @¨!Ø	�Š�ZÑ Ô Ð Ø	�Š‰	Œ	ˆ	ð —X’XÐAÐA¸5ÐAÑAÔAÑBÔBˆ
Ø˜˜t Y°
Ø�c˜1œ6 4¨ð.ˆå!-¨d°JÑ!?Ô!?Ñˆ�˜ð@ð @ð @ñ @ô @ð @ð @ð @ð @ð @ð @øøøð @ð @ð @ð @ð �‚{€{ØˆxˆÝ
�fÑ
Ô
Ðs   ”A.BÂBÂBr    )NF)r   FFFN)r   FFFr3   NN)Ú__doc__r   r   Ú
subprocessr   r   r^   ro   Úerrorsr   r   Útextfiler   r
   r   r)   rt   r1   r3   rC   rZ   rS   rx   r   r   r   ú<module>r}      sj  ðð$ #Ð "à €€€Ø 	€	€	€	Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "Ø 
€
€
€
Ø €€€à %Ð %Ð %Ð %Ð %Ð %Ð %Ð %Ø %Ð %Ð %Ð %Ð %Ð %ð*ð *ð *ð *ð *�(ñ *ô *ð *ð
$ð $ð $ð $ð $�xñ $ô $ð $ð €Ø„7ˆd‚?€?Ø€Mð"ð "ð "ð "ð$ð ð ð ð2ð ð ð2 ?DØ $ð%ð %ð %ð %ð CHØEIð+ð +ð +ð +ð\ð ð ð ð r   