https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/mercurial/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/mercurial/__pycache__/patch.cpython-310.pyc
o

�]Lb���@s�ddlmZmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZmZmZddlmZddlmZmZmZmZmZmZmZmZmZmZmZmZmZ ddl!m"Z"m#Z#m$Z$m%Z%ej&Z&e�'d	�Z(e�'d
�Z)e�'d�Z*ej+Z+ej,Z,ej-Z-dd
�Z.gd�Z/ej0dd��Z1dd�Z2Gdd�de3�Z4dd�Z5Gdd�de3�Z6Gdd�de3�Z7Gdd�de7�Z8Gdd�de8�Z9Gdd �d e3�Z:Gd!d"�d"e7�Z;e�'d#�Z<e�'d$�Z=gd%�Z>Gd&d'�d'e3�Z?Gd(d)�d)e3�Z@Gd*d+�d+e3�ZAd,d-�ZBd}d.d/�ZCGd0d1�d1e3�ZDGd2d3�d3e3�ZEd4d5�ZFd6d7�ZGd}d8d9�ZHd:d;�ZId<d=�ZJd>d?�ZKd@dA�ZLdBdC�ZMdDdE�ZNd~dHdI�ZOdJdK�ZP	Gd~dLdM�ZQdNdO�ZR	GddPdQ�ZS	F		G	d�dRdS�ZT	GddTdU�ZU		F		G	d�dVdW�ZVd�dXdY�ZWGdZd[�d[eX�ZYejZZ[ejZZZej\Z\										d�d\d]�Z]							d�d^d_�Z^d`da�Z_dbdc�Z`ddde�Zadfdg�Zbdhdi�Zcdjdk�Zddldmdndo�Zedpdq�Zfdrds�Zgdtdu�Zhdvdw�Zid�dydz�Zjd{d|�ZkdS)��)�absolute_import�print_functionN���_)�hex�sha1nodeconstants�short)�open)
�copies�
diffhelper�diffutil�encoding�error�mail�mdiff�pathutil�pycompat�scmutil�similar�util�vfs)�dateutil�hashutil�procutil�
stringutilsdiff --git a/(.*) b/(.*)s(\t+|[^\t]+)s9(\t+| +|[a-zA-Z0-9_\x80-\xff]+|[^ \ta-zA-Z0-9_\x80-\xff])csdd��dd���fdd�}�fdd�}�fd	d
�}��fdd�}�fd
d�}Gdd�dt�}d}g}dg}	t�|d�s@||�}|D]H}
|�|
�|
�d�rU|||�S|
�d�ra|||�S�|
|�r|d}|
�dd�d��|	vr{|||�SqB|
�d�r�|r�|||�SqB||�S)z6return an iterator of individual patches from a streamcSsD|r	|�d�r	dS|�d�rdS|�dd�}t|�dko!d|d	vS)
N)� �	T)r�-�+F�: r�rr)�
startswith�split�len)�line�inheader�l�r(�1/usr/lib/python3/dist-packages/mercurial/patch.py�isheaderCs
zsplit.<locals>.isheadercSstd�|��S�N�)�stringio�join)�linesr(r(r)�chunkMszsplit.<locals>.chunkc3s\�d}|D]}|��s
d}|s|�d�r�|�Vg}d}|�|�q|r,�|�VdSdS)NTF�# HG changeset patch)�stripr"�append��stream�curr&r%�r0r(r)�hgsplitPs�
�zsplit.<locals>.hgsplitc3sp�|D]}|�d�rt�|dd���D]}|Vqg}|�|�q|r4t�|dd���D]}|Vq.dSdS)N�From r)r"r#r3)r5r6r%�cr7r(r)�	mboxsplit`s�
�zsplit.<locals>.mboxsplitc	3sx�dd�}|D]}|�|�q�|�}t�|�}|��s#||�VdSd}|��D]}|��}||vr4q)||�Vq)dS)NcSs,t�}tj|dd�}|�|�|�d�|S)NF)�mangle_from_r)r-r�	Generator�flatten�seek)�m�fp�gr(r(r)�msgfpns


z'split.<locals>.mimesplit.<locals>.msgfp��
text/plainstext/x-diffstext/x-patch)r3r�parse�is_multipart�walk�get_content_type)	r5r6rCr%r:r@�ok_types�part�ctr7r(r)�	mimesplitms�	
�zsplit.<locals>.mimesplitc3sb�d}|D] }|s�||�r�|�Vg}d}|r �||�s d}|�|�q|r/�|�VdSdS�NFT�r3r4�r0r*r(r)�headersplit�s�
�zsplit.<locals>.headersplitc3s��|�VdS�Nr()r6r7r(r)�	remainder�s�zsplit.<locals>.remainderc@s(eZdZdd�Zdd�Zdd�ZeZdS)zsplit.<locals>.fitercS�
||_dSrR)rA��selfrAr(r(r)�__init__��
zsplit.<locals>.fiter.__init__cS�|SrRr(�rVr(r(r)�__iter__��zsplit.<locals>.fiter.__iter__cSs|j��}|s	t�|SrR)rA�readline�
StopIteration�rVr'r(r(r)�next�s
zsplit.<locals>.fiter.nextN)�__name__�
__module__�__qualname__rWr[r`�__next__r(r(r(r)�fiter�s
reFscontent-typesnextr1r9T�:rr�--- )�objectr�safehasattrr3r"r#�lower)r5r8r;rMrQrSrer&r6�mimeheadersr%r(rPr)r#@s8





��r#))sDatesdate)sBranchsbranch)sNode ID�nodeidc	cs\�tjdd�\}}t�|d�}zt||||�VW|��t�|�dS|��t�|�w)a�extract patch from data read from fileobj.

    patch can be a normal patch or contained in an email message.

    return a dictionary. Standard keys are:
      - filename,
      - message,
      - user,
      - date,
      - branch,
      - node,
      - p1,
      - p2.
    Any item can be missing from the dictionary. If filename is missing,
    fileobj did not contain a patch. Caller must unlink filename when done.�	hg-patch-��prefix�wbN)r�mkstemp�os�fdopen�_extract�close�unlink)�ui�fileobj�fd�tmpname�tmpfpr(r(r)�extract�s��r|c	Cs�t�dtjtjB�}i}t�|�}|dot�|d�}|do&t�|d�|d<|s=|ds=d�dd�|��D��d}g}|d}	|	rUt�|	�|d	<}	|�	d
|	�|r}|�
d�ro|�d�}
|
d
kro||
dd���}t�
dd|�}|�	d|�|dr�|�	d|d�d
}d}d}
|��D�]}t�|���}|�	d|�||vr�q�|jdd�}|�|�}|�r�d}d}d}|�	d|�d
��|d7}t�}|d|�d
����D]�}|�
d�r�|s�|�	d�d}d}|�d
�|��d}ne|�rV|�
d��r|dd�|d<|�	d|d�nJ|�
d��r%|�|dd����n8|�
d ��rStD]$\}}d!|}|�
|��rP|t|�d�||<|�	d"|||f��q-n
d}n|d#k�r]d}|�sm|�sm|�|�|�d�q�|��}
|�r�|�|�|�d��s�|�d�q�|�s�|
�r�|d$k�r�|
d|7}
q�|�r�|
�
|��s�d%||
f}
|
|d&<|��|�r�|� d
�|d'<|�r�|� d
�|d(<|�r�||d)<|S)*Ns}^(?:Index:[ \t]|diff[ \t]-|RCS file: |retrieving revision [0-9]+(\.[0-9]+)*$|---[ \t].*?^\+\+\+[ \t]|\*\*\*[ \t].*?^---[ \t])�Subject�Fromsuser�
css"�|]}d�ttj|��VqdS)r N)r.�mapr�
strtolocal��.0�hr(r(r)�	<genexpr>�s�
�z_extract.<locals>.<genexpr>zX-Mercurial-NoderlsNode ID: %s
s[PATCH�]rrs\n[ \t]+rsSubject: %s
s	From: %s
rDr,sContent-Type: %s
T)�decodeFsfound patch at byte %d
r1spatch generated by hg export
s# User �s	# Parent �	�# s# %s s%s: %s
�---rEs%s
%ssmessagesp1sp2sfilename)!�re�compile�	MULTILINE�DOTALLrrF�
headdecoder.�items�debugr"�find�lstrip�subrHr�bytestrrI�get_payload�search�startr-�
splitlinesr?�truncater3�patchheadermapr$�write�getvalue�endswithru�pop)rwrxrzr{�diffre�data�msg�subject�parents�nodeid�pend�
diffs_seenrJ�messagerK�content_type�payloadr@�hgpatch�
hgpatchheader�
ignoretext�cfpr%�header�keyror(r(r)rt�s�
�

���




��


�

��rtc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�	patchmetaa�Patched file metadata

    'op' is the performed operation within ADD, DELETE, RENAME, MODIFY
    or COPY.  'path' is patched file path. 'oldpath' is set to the
    origin file when 'op' is either COPY or RENAME, None otherwise. If
    file mode is changed, 'mode' is a tuple (islink, isexec) where
    'islink' is True if the file is a symlink and 'isexec' is True if
    the file is executable. Otherwise, 'mode' is None.
    cCs"||_d|_d|_d|_d|_dS)NsMODIFYF)�path�oldpath�mode�op�binary)rVr�r(r(r)rWes

zpatchmeta.__init__cCs|d@}|d@}||f|_dS)Ni �@)r�)rVr��islink�isexecr(r(r)�setmodelszpatchmeta.setmodecCs.t|j�}|j|_|j|_|j|_|j|_|SrR)r�r�r�r�r�r�)rV�otherr(r(r)�copyqs
zpatchmeta.copycCs&|dkr	|jdkS|d|jp|jkS)N�	/dev/null�ADD�a/)r�r�r�)rV�afiler(r(r)�_ispatchingays
zpatchmeta._ispatchingacCs |dkr	|jdkS|d|jkS)Nr��DELETE�b/�r�r�)rV�bfiler(r(r)�_ispatchingb~s
zpatchmeta._ispatchingbcCs|�|�o	|�|�SrR)r�r�)rVr�r�r(r(r)�
ispatching��zpatchmeta.ispatchingcCsd|j|jfS)Nz<patchmeta %s %r>r�rZr(r(r)�__repr__�szpatchmeta.__repr__N)rarbrc�__doc__rWr�r�r�r�r�r�r(r(r(r)r�Zs
r�cCsjd}g}|D]�}|�d�}|�d�r*t�|�}|r)|r |�|�|�d�}t|�}q|r�|�d�r9|�|�d}q|�d�rId|_|dd�|_q|�d	�rV|d
d�|_	q|�d�rfd|_|d
d�|_q|�d
�rs|dd�|_	q|�d�r|d|_q|�d�r�d|_|�
t|dd�d��q|�d�r�|�
t|dd�d��q|�d�r�d|_q|r�|�|�|S)z9extract git-style metadata about patches from <patchname>N�
�
diff --git a/r!rgsrename from �RENAME�s
rename to �
s
copy from �COPYscopy to �sdeleted filer�snew file mode r�i����s	new mode �GIT binary patchT)
�rstripr"�gitre�matchr3�groupr�r�r�r�r��intr�)�lr�gp�
gitpatchesr%r@�dstr(r(r)�readgitpatch�sP




�









�
r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
linereadercC�||_g|_dSrR)rA�bufrUr(r(r)rW��
zlinereader.__init__cCs|dur|j�|�dSdSrR)r�r3�rVr%r(r(r)�push�s�zlinereader.pushcCs&|jr|jd}|jd=|S|j��S�Nr)r�rAr]r_r(r(r)r]�s


zlinereader.readlinecCst|jd�Sr+)�iterr]rZr(r(r)r[��zlinereader.__iter__N)rarbrcrWr�r]r[r(r(r(r)r��s
r�c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�abstractbackendcCrTrR)rw)rVrwr(r(r)rW�rXzabstractbackend.__init__cC�t�)z�Return target file data and flags as a (data, (islink,
        isexec)) tuple. Data is None if file is missing/deleted.
        ��NotImplementedError�rV�fnamer(r(r)�getfile�szabstractbackend.getfilecCr�)a	Write data to target file fname and set its mode. mode is a
        (islink, isexec) tuple. If data is None, the file content should
        be left unchanged. If the file is modified after being copied,
        copysource is set to the original file name.
        r��rVr�r�r��
copysourcer(r(r)�setfile�szabstractbackend.setfilecCr�)zUnlink target file.r�r�r(r(r)rv�szabstractbackend.unlinkcCsdS)z�Write rejected lines for fname. total is the number of hunks
        which failed to apply and total the total number of hunks for this
        files.
        Nr()rVr��failed�totalr/r(r(r)�writerej��zabstractbackend.writerejcCr�rRr�r�r(r(r)�exists�r\zabstractbackend.existscCr�rRr�rZr(r(r)ru�r\zabstractbackend.closeN)
rarbrcrWr�r�rvr�r�rur(r(r(r)r��sr�csDeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Z�Z	S)
�	fsbackendcs tt|��|�t�|�|_dSrR)�superr�rW�vfsmodr�opener)rVrw�basedir��	__class__r(r)rW�szfsbackend.__init__c
Cs�|j�|�r|j�|�dfSd}z
|j�|�jd@dk}Wnty6}z
|jtjkr,�WYd}~nd}~wwz|j�|�d|ffWSt	y\}z|jtjkrQ�WYd}~dSd}~ww)N�TFFr�r�NN)
r�r��readlink�lstat�st_mode�OSError�errno�ENOENT�read�IOError)rVr�r��er(r(r)r��s&�����zfsbackend.getfilecCsd|\}}|dur|j�|||�dS|r|j�||�dS|j�||�|r0|j�|dd�dSdSrN)r��setflags�symlinkr�)rVr�r�r�r�r�r�r(r(r)r�s�zfsbackend.setfilecCs$|j�dd�}|jj|d|d�dS)NsexperimentalsremoveemptydirsT)�
ignoremissing�rmdir)rw�
configboolr��
unlinkpath)rVr�rr(r(r)rvszfsbackend.unlinkcCsD|d}|j�td�|||f�|�|d�}|�|�|��dS)Ns.rejs7%d out of %d hunks FAILED -- saving rejects to file %s
�w)rw�warnrr��
writelinesru)rVr�r�r�r/rAr(r(r)r�s��
zfsbackend.writerejcCs|j�|�SrR)r��lexistsr�r(r(r)r�r�zfsbackend.exists)
rarbrcrWr�r�rvr�r��
__classcell__r(r(r�r)r��s
r�csDeZdZ�fdd�Zdd�Z�fdd�Z�fdd�Zd	d
�Z�ZS)�workingbackendcs:tt|��||j�||_||_t�|_t�|_g|_	dSrR)
r�rrW�root�repo�
similarity�set�removed�changed�copied)rVrwrrr�r(r)rW$s
zworkingbackend.__init__cCs2|jj�|�js|�|�rttd�|��dSdS�Ns$cannot patch %s: file is not tracked)r�dirstate�	get_entry�any_trackedr��PatchApplicationErrorrr�r(r(r)�_checkknown,s�
��zworkingbackend._checkknowncsH|�|�tt|��||||�|dur|j�||f�|j�|�dSrR)r r�rr�rr3r�addr�r�r(r)r�4s

zworkingbackend.setfilecs6|�|�tt|��|�|j�|�|j�|�dSrR)r r�rrvrr!rr�r�r(r)rv;s
zworkingbackend.unlinkcCs�|jd}t|j�}|jD]\}}t�|j|j|||�q
|jr9|�t	|j��|jD]
}||jj
vr8|�|�q+|rDt�|j||j
�t	|j�SrR)rrrrr�dirstatecopyrwr�forget�sortedr�discard�marktouchedr)rV�wctxr�srcr��fr(r(r)ruAs



�
zworkingbackend.close)	rarbrcrWr r�rvrurr(r(r�r)r#src@s0eZdZd
dd�Zd
dd�Zdd�Zdd	�ZdS)�	filestoreNcCs8d|_i|_d|_||_|jdurd|_d|_i|_dS)Nri@)r��files�created�maxsize�sizer�)rVr-r(r(r)rWUs

zfilestore.__init__cCs�|jdkst|�|j|jkr"|||f|j|<|jt|�7_dS|jdur3tjdd�}t�|�|_d|j	}|j�
||�|j	d7_	|||f|j|<dS)Nrrmrn�%dr)r-r$r.r�r�r�mkdtempr�rr,r�r+)rVr�r�r�rr�fnr(r(r)r�_s

zfilestore.setfilecCsJ||jvr
|j|S|jr||jvrdS|j|\}}}|j�|�||fS)N)NNN)r�r�r+r)rVr�r1r�rr(r(r)r�ms

zfilestore.getfilecCs|jrt�|jj�dSdSrR)r��shutil�rmtree�baserZr(r(r)ruus�zfilestore.closerR)rarbrcrWr�r�rur(r(r(r)r*Ts



r*csLeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	�Z
S)�repobackendcs<tt|��|�||_||_||_t�|_t�|_i|_	dSrR)
r�r5rWr�ctx�storerrrr)rVrwrr6r7r�r(r)rW{s
zrepobackend.__init__cCs||jvr
ttd�|��dSr)r6rrr�r(r(r)r �s


��zrepobackend._checkknowncCsFz|j|}WntjyYdSw|��}|��d|vd|vffS)Nr��l�x)r6r�LookupError�flagsr�)rVr��fctxr;r(r(r)r��s�zrepobackend.getfilecCsX|r|�|�|dur|j|��}|j�||||�|j�|�|r*||j|<dSdSrR)r r6r�r7r�rr!rr�r(r(r)r��s
�zrepobackend.setfilecCs|�|�|j�|�dSrR)r rr!r�r(r(r)rv�s
zrepobackend.unlinkcCs
||jvSrR)r6r�r(r(r)r��rXzrepobackend.existscCs|j|jBSrR)rrrZr(r(r)ru�r�zrepobackend.close)rarbrcrWr r�r�rvr�rurr(r(r�r)r5zs	
r5s*@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@s.(?:---|\*\*\*) (\d+)(?:,(\d+))? (?:---|\*\*\*))�strict�crlf�lf�autoc@sFeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)�	patchfiler=c
Cs�|j|_||_d|_||_||_g|_d|_d|_|j	|_	|j
|_|jdv|_
|jdk|_|jdur;|�|j�\}}n|�|j�dd�\}}|dur�|jdupU|�|j�|_d|_|rbt�|�|_|j	durj||_	|jr�|jd�d�ryd|_n|jd�d�r�d|_|d	kr�g}|jD]}	|	�d�r�|	dd
�d}	|�|	�q�||_n|j
r�d|_|j	dur�d|_	|jr�|j�td�|j�|j�td
��i|_d|_d|_d|_g|_d|_|�d�d|_dS)NFT)r�r�r�r�r!rr�rr=���)FFs!unable to find '%s' for patching
sB(use '--prefix' to apply patch relative to the current directory)
)r�r��eolmode�eol�backendrwr/r��missingr�r�r�r��create�remover�r�
splitnewlinesr�r3rr�hash�dirty�offset�skew�rej�fileprinted�	printfile�hunks)
rVrwr�rEr7rCr�r��nlinesr'r(r(r)rW�sl



�
��

zpatchfile.__init__cCs�|jdkr	|j}n
|jdkrd}nd}|jdkr;|r;|dkr;g}|D]}|r3|�d�r3|dd�|}|�|�q"|}|j�|d�|�||j�dS)Nr@r>r�rr=���r,)rCrDr�r3rEr�r.r�)rVr�r/r�rD�rawlinesr'r(r(r)r�s

zpatchfile.writelinescCsN|jrdS|s|jjrd|_td�|j}|r|j�|�dS|j�|�dS)NTspatching file %s
)rOrw�verboserr�r�note)rVr�sr(r(r)rP�szpatchfile.printfilecs2|j�|g�}t|�dkr|j�fdd�d�|S)Nrcst|��SrR)�abs)�x��linenumr(r)�<lambda>sz%patchfile.findlines.<locals>.<lambda>)r�)rJ�getr$�sort)rVr'r[�candr(rZr)�	findlinesszpatchfile.findlinescCs�|jsdStj�|j�}d||fg}|jD]}|jD]}|�|�|dd�dkr2|�dtj�qq|j	�
|jt|j�|j|�dS)Ns--- %s
+++ %s
rSr)
rNrrr��basenamer��hunkr3r�MISSING_NEWLINE_MARKERrEr�r$rQ)rVr4r/rYr'r(r(r)�	write_rejs


�� zpatchfile.write_rejc
Csz|��sttd�|j|jt|j�|jt|j�|j	f��|j
d7_
|jr.|j�
|�dS|jrV|jrV|jrC|j�td�|j�n|j�td�|j�|j�
|�dSt|t�r�|jrg|j�|j�dS|�|j�}||jdd�<|jt|�7_d|_dS|}|jdvs�|jd	kr�|jr�|��}|� dd
�\}}}}||j7}|}|j!dkr�t"�#||j|�r�|jr�|j�|j�dS||j||t|��<|jt|�t|�7_d|_dSi|_$t%|j�D]\}	}
|j$�&|
g��
|	�q�t'�(|j�)dd�d�D]�}d
D]�}|� ||�\}}}}||j|j!}t*|t|j��}|�r/|�+|ddd�|�}
n|g}
|
D]k}|�rBt"�#||j|��r�||j||t|��<|jt|�t|�7_|||_!d|_|||}|�r�td�}|�,d�|j�||j|d||f�ntd�}|j�-||j|d|f�|S�q4�qq�|�,d�|j�td�|j|f�|j�
|�dS)Nsbad hunk #%d %s (%d %d %d %d)rrSs-cannot create %s: destination already exists
sfile %s already exists
Tr)r>r?r@F�patchsfuzzr�s9Hunk #%d succeeded at %d with fuzz %d (offset %d lines).
s,Hunk #%d succeeded at %d (offset %d lines).
sHunk #%d FAILED at %d
).�complete�PatchParseErrorr�number�descr$�a�lena�b�lenbrQrFrNr3r�rGr�rwrr��
isinstance�binhunkrHrErv�newr/rLrKrCrD�
getnormalized�fuzzitrMr�testhunkrJ�	enumerate�
setdefaultr�xrange�	configint�minr`rPrV)rVr�r'�horig�old�oldstartrp�newstart�
orig_startrYrW�fuzzlen�toponlyr_rLr�r(r(r)�apply"s�"����
�

�
��
�
�����
#zpatchfile.applycCs,|jr
|�|j|j|j�|��t|j�SrR)rKrr�r/r�rdr$rNrZr(r(r)ru�s
zpatchfile.closeN)r=)
rarbrcrWrrPr`rdr�rur(r(r(r)rA�s
<mrAc@s�eZdZdZe�d�Ze�d�Ze�d�Ze�d�Z	e�d�Z
e�d�Zdd	�Zd
d�Z
dd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)r�zpatch headersdiff --git a/(.*) b/(.*)$sdiff -r .* (.*)$s(?:index|deleted file) s(?:new file|deleted file) s'(?:index|deleted|copy|rename|new mode) s(?:new file|copy to|rename to)cCr�rR)r�rQ)rVr�r(r(r)rW�r�zheader.__init__cCstdd�|jD��S)Ncss�|]}|�d�VqdS)�index N�r"r�r(r(r)r����z header.binary.<locals>.<genexpr>��anyr�rZr(r(r)r��r�z
header.binarycCs�|jD]M}|�d�r|�td��dS|j�|�r-|�|�|��r*|�td��dS|�d�rK|�td�t|j�t	dd�|jD��f�dS|�|�qdS)Nr�s-this modifies a binary file (all or nothing)
sthis is a binary file
r�s%d hunks, %d lines changed
cSsg|]	}t|j|j��qSr()�max�addedrr�r(r(r)�
<listcomp>��z!header.pretty.<locals>.<listcomp>)
r�r"r�r�	pretty_rer�r�r$rQ�sum)rVrAr�r(r(r)�pretty�s(



����z
header.prettycCs|�d�|j��dSr+)r�r.r�rUr(r(r)r��szheader.writec�t�fdd��jD��S)Nc3��|]	}�j�|�VqdSrR)�allhunks_rer�r�rZr(r)r����z"header.allhunks.<locals>.<genexpr>r�rZr(rZr)�allhunks��zheader.allhunkscCsN|j�|jd�}|r|��\}}||kr|gS||gS|j�|jd���Sr�)�
diffgit_rer�r��groups�diff_re)rVr��fromfile�tofiler(r(r)r+�szheader.filescCs|��dS)NrS)r+rZr(r(r)�filename�r�zheader.filenamecCsdd�t�tj|����S)Nz<header %s>� )r.r�rapply�fsdecoder+rZr(r(r)r��s�zheader.__repr__cr�)Nc3r�rR)�
newfile_rer�r�rZr(r)r��r�z#header.isnewfile.<locals>.<genexpr>r�rZr(rZr)�	isnewfile�r�zheader.isnewfilecs6t�j�dk}���o|}|pt�fdd��jD��S)Nr!c3r�rR)�
special_rer�r�rZr(r)r��s�
�z!header.special.<locals>.<genexpr>)r$r�r�r�)rV�	nocontent�emptynewfiler(rZr)�special�s
�zheader.specialN)rarbrcr�r�r�r�r�r�r�r�r�rWr�r�r�r�r+r�r�r�r�r(r(r(r)r��s$






r�c@s^eZdZdZ	ddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e	Z
dd�Zej
dd��ZdS)�
recordhunkzKpatch hunk

    XXX shouldn't we merge this with the other hunk class?
    Nc	sld�fdd�	}	||_|	|d�\}
|_||
|_||
|_|	|d�\}|_||_||_|�|j�\|_|_	dS)NFcsH�dur t|��}|dkr |r|||d�fS||d��fSd|fSr��r$)r/�reverse�delta��
maxcontextr(r)�trimcontext�sz(recordhunk.__init__.<locals>.trimcontextT)F)
r��before�fromline�toline�after�procrb�countchangesr�r)rVr�r�r�r�r�rbr�r�r��trimedbefore�_trimedafterr(r�r)rW�s


zrecordhunk.__init__cCsFt|t�sdS|j|jko"|j|jko"|j|jko"|j��|j��kS)NF)rnr�rbr�r�r�r+)rV�vr(r(r)�__eq__
s

�
��zrecordhunk.__eq__cCs$tt|j�t|j���|j|jf�SrR)rJ�tuplerbr�r+r�r�rZr(r(r)�__hash__s��zrecordhunk.__hash__cCs,tdd�|D��}tdd�|D��}||fS)zhunk -> (n+,n-)cS�g|]	}|�d�r|�qS)rr�r�r(r(r)r�!r�z+recordhunk.countchanges.<locals>.<listcomp>cSr�)rr�r�r(r(r)r�"r�r�)rVrbr!�remr(r(r)r�szrecordhunk.countchangescs@dddd���fdd�|jD�}t|j|j|j|j|j||j�S)z�return another recordhunk which is the reverse of the hunk

        If this hunk is diff(A, B), the returned hunk is diff(B, A). To do
        that, swap fromline/toline and +/- signs while keep other things
        unchanged.
        rr�\)rrr�cs,g|]}d�|dd�|dd�f�qS)s%s%srrNr()r�r'�r@r(r)r�-s,z*recordhunk.reversehunk.<locals>.<listcomp>)rbr�r�r�r�r�r�r��rVrbr(r�r)�reversehunk%s�zrecordhunk.reversehunkc	Cs�t|j�t|j�}|jr|jdtjkr|d8}||j}||j}|�d|j||j	||j
o3d|j
f�|�d�|j|j|j��dS)NrSrs@@ -%d,%d +%d,%d @@%s
rr,)
r$r�r�rrcrr�r�r�r�r�r.rb)rVrAr��fromlen�tolenr(r(r)r�8s 

���"
zrecordhunk.writecCs
|j��SrR)r�r�rZr(r(r)r�LrXzrecordhunk.filenamecCsd|��|jfS)Ns<hunk %r@%d>)r�r�rZr(r(r)r�Oszrecordhunk.__repr__rR)rarbrcr�rWr�r�r�r�r�r�r�r�	strmethodr�r(r(r(r)r��s
�
r�cCsZtd�td�td�td�d�td�td�td�td	�d�td
�td�td�td
�d�d�S)Nsapply change %d/%d to '%s'?sdiscard change %d/%d to '%s'?skeep change %d/%d to '%s'?srecord change %d/%d to '%s'?)sapplysdiscardskeep�recordsapply this change to '%s'?sdiscard this change to '%s'?skeep this change to '%s'?srecord this change to '%s'?s0[Ynesfdaq?]$$ &Yes, apply this change$$ &No, skip this change$$ &Edit this change manually$$ &Skip remaining changes to this file$$ Apply remaining changes to this &file$$ &Done, skip remaining changes and files$$ Apply &all changes to all remaining files$$ &Quit, applying no changes$$ &? (display help)s8[Ynesfdaq?]$$ &Yes, discard this change$$ &No, skip this change$$ &Edit this change manually$$ &Skip remaining changes to this file$$ Discard remaining changes to this &file$$ &Done, skip remaining changes and files$$ Discard &all changes to all remaining files$$ &Quit, discarding no changes$$ &? (display help)s-[Ynesfdaq?]$$ &Yes, keep this change$$ &No, skip this change$$ &Edit this change manually$$ &Skip remaining changes to this file$$ Keep remaining changes to this &file$$ &Done, skip remaining changes and files$$ Keep &all changes to all remaining files$$ &Quit, keeping all changes$$ &? (display help)s4[Ynesfdaq?]$$ &Yes, record this change$$ &No, skip this change$$ &Edit this change manually$$ &Skip remaining changes to this file$$ Record remaining changes to this &file$$ &Done, skip remaining changes and files$$ Record &all changes to all remaining files$$ &Quit, recording no changes$$ &? (display help))�multiple�single�helprr(r(r(r)�getmessagesTs0��������r�cslt���dur	d����fdd�}t�}i}d\}}dtdd�|D��}	}
|D]�}|	t|j�7}	d}d	}d
�|j�}
|
|vr@q(|�|
�|durN|���|�	�}t
d�t
d��d
d�|D��}t�fdd�|D��rsd\}}}n||||d�\}}}}|s�q(|g||��<|�
�r�||��|j7<q(t|j�D]�\}}|dur�|dur�|���|
dkr��d�|��}n|	t|j�|}�d�||
|��f}|||||�\}}}}|r�|r�t�|�}|j|7_||���|�q�|du�r|D]}|jD]}|�r|j|7_||���|��qq�q�||j|j7}q�q(tdd�t�|�D�g�ifS)z:Interactively filter patch chunks into applied-only chunksNr�c	s�d}|dur||||fS|dur||||fS	�d�}��d||f�}��d�|dkrH��|�dD]\}}��d|t�|�f�q6q|d	krPd}	�n|dkrWd
}	n�|dk�r|durm��td����d�q|j��r��td
����d�qdtd�}
tj	ddd�\}}d}
z�t
�t�
|d��}|j�|�|�|�|�d�dd�|
��D���|�����}�jd||fd���idd�}	|	d	kr��td�|	�Wt�|�~
qt|d�}t�}
t
�|�D]}t
�|�}|�d�s�|
�|�q�|��|
�d	�t|
�}Wt�|�~
nt�|�~
wd
}	n4|dk�r)d
}	}n*|dk�r3d}	}n |d k�r=d
}	}n|d!k�rGd}	}n|d"k�rSt�td#���|	|||fS)$z�prompt query, and process base inputs

        - y/n for the rest of file
        - y/n for the rest
        - ? (help)
        - q (quit)

        Return True/False and possibly updated skipfile and skipall.
        NTr�s%s
(enter ? for help) %srr�rs%s - %s
rFr!s cannot edit patch for whole files!cannot edit patch for binary filer�s�
To remove '-' lines, make them ' ' lines (context).
To remove '+' lines, delete them.
Lines starting with # will be removed from the patch.

If the patch applies cleanly, the edited hunk will immediately be
added to the record list. If it does not apply cleanly, a rejects
file will be generated: you can use that when you try again. If
all lines of the hunk are removed, then the edit is aborted and
the hunk is left unchanged.
s
hg-editor-s.diff)ro�suffixrpr,cSsg|]}d|d�qS)r�rr()r��ir(r(r)r���z/filterpatch.<locals>.prompt.<locals>.<listcomp>s%s "%s"sHGUSERsfilterpatch)�environ�
blockedtags editor exited with exit code %d
�rb�#����r�s	user quit)�promptchoicer��extractchoicesrrjrr�r�rrqr�nativeeolwriterrrrsr.r�ru�	geteditor�system�usernamerrvr
r-�iterfile�
fromnativeeolr"r?�
parsepatchr�
CanceledError)�skipfile�skipall�queryr0�
newpatches�resps�rr:�t�ret�phelp�patchfd�patchfn�	ncpatchfpr)�editor�patchfpr%)�messages�	operationrwr(r)�prompt�s�





�

�
��

�

�


�



�








zfilterpatch.<locals>.promptr�rcss�|]}t|j�VqdSrR)r$rQr�r(r(r)r�r�zfilterpatch.<locals>.<genexpr>rr,sexamine changes to %s?s and css�|]}d|VqdS)s'%s'Nr(�r�r)r(r(r)r�s�
�c3s�|]}��|�VqdSrR)�exactr��r�r(r)r�r�)TNNr�r�cSs(g|]}|d��st|�dkr|�qS)rr)r�r$r�r(r(r)r�Bs
��zfilterpatch.<locals>.<listcomp>)r�rr�r$rQr.r�r!r�r+r�allr�r�rtr�r�r3rr�r�
itervalues)rw�headersr�r�r��seen�appliedr�r��posr�r��	fixoffset�hdrr+r�r��npr�r0�idxr��newpatch�newhunkr()r�r�r�rwr)�filterpatch�s�j


�

��


������r�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)rbcCsd||_||_|g|_g|_g|_d|_|_d|_|_|dur0|r)|�	|�dS|�
|�dSdSrR)rhrirbrjrl�startark�startbrm�read_context_hunk�read_unified_hunk)rVri�numr��contextr(r(r)rWNs�z
hunk.__init__cCsndd�}t|j|jdd�}|j|_|j|_|j|_||j�|_||j�|_|j|_|j|_|j|_|j|_|S)z1Return a copy with line endings normalized to LF.cSs6g}|D]}|�d�r|dd�d}|�|�q|S)Nr�rBr)r�r3)r/rRr%r(r(r)�	normalize_s
z%hunk.getnormalized.<locals>.normalizeN)	rbrirhrjrlr�r�rkrm)rVr��nhr(r(r)rq\s	zhunk.getnormalizedc
CsHt�|j�}|sttd�|j��|��\|_|_|_	|_
|jdur&d|_nt|j�|_|j
dur5d|_
nt|j
�|_
t|j�|_t|j	�|_	zt�
||j|j|j
|j|j�Wntjyp}zttd�|j|f��d}~wwt|jd�dkr�|jd=|jd=|jd=|jd8_|j
d8_
t|jd�dksz|�|�dS)N�bad hunk #%drsbad hunk #%d: %srSr)�unidescr�rirgrrhr�r�rkr�rmr�r�addlinesrbrjrlr�
ParseErrorr$�_fixnewline)rVr�r@rr(r(r)r�ts8

����zhunk.read_unified_hunkcCs�|��|_t�|j�}|sttd�|j��|��\|_}t	|j�|_|dur*|j}t	|�|j|_
|jr<|j
d7_
t�|j
�D]H}|��}|�
d�rT|�|�n7|dd�}|�
d�sd|�
d�rid|}n|�
d�rsd	|}nttd
�|j|f��|j�|�|j�|�qB|��}|�
d�r�|jddd�}||jd<||jd<|��}t�|�}|s�ttd�|j��|��\|_}t	|j�|_|dur�|j}t	|�|j|_|jr�|jd7_d}	t�|j�D]�}|��}|�
d��r|jddd�}||jd<||j|	d<q�|�s|�|�np|dd�}|�
d
��s'|�
d��r,d|}n%|�
d��r7d	|}nt|j�dk�rF|�|�n?ttd
�|j|f��|j�|�	|	t|j�k�rcd}
n|j|	}
|	d7}	|
|k�rrn|
�
d��rz�qW|j�|	d|�	q�|j�s�|jD]}|�
d��s�|�
d	��r�|j�|��q�|j�s�|jD]}|�
d��s�|�
d	��r�|j�|dd���q�d|j|j
|j|jf|_|j|jd<|�|�dS)Nrrr�r!s- s! rs  rsbad hunk #%d old text line %d�\ rSs+ rrTr,s@@ -%d,%d +%d,%d @@
)r]ri�contextdescr�rgrrhr�r�r�rkrrvr"r�rjr3rbr�rmrlr$�insertr)rVr�r@�aendrYr'rW�u�bend�hunkir�r(r(r)r��s�





�








�

�
�
��zhunk.read_context_hunkcCs8|��}|�d�rt�|j|j|j�dS|�|�dS)Nr)r]r"r�
fixnewlinerbrjrlr�)rVr�r'r(r(r)rs
zhunk._fixnewlinecCs t|j�|jkot|j�|jkSrR)r$rjrkrlrmrZr(r(r)rfs z
hunk.completec	Cs�t|t|��}|rgd}d}t|j�}t�|d�D]}|j|d�d�r*|d7}q|sHt�|d�D]}|j||d�d�rG|d7}q4t||�}t||�}||t|�|�||t|�|�|fS||dfS)Nrrr)rxr$rbrrvr")	rVrzrp�fuzzr�top�bot�hlenrYr(r(r)�_fuzzit
s$




*
zhunk._fuzzitcCsf|�|j|j||�\}}}|j|}|j|}|jr"|dkr"|d8}|jr-|dkr-|d8}||||fS)Nrr)rrjrlr�r�rkrm)rVrrrzrprr{r|r(r(r)rr%s

zhunk.fuzzitN)rarbrcrWrqr�r�rrfrrrr(r(r(r)rbMsmrbc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)rozA binary patch file.cCs(d|_d|_dg|_||_|�|�dS)NFsGIT binary patch
)�textr�rb�_fname�_read)rVr�r�r(r(r)rW4s
zbinhunk.__init__cCs
|jduSrR)rrZr(r(r)rf;rXzbinhunk.completecCs"|jr
t|jd�|��gS|jgSr+)r��
applybindeltarr.)rVr/r(r(r)rp>szbinhunk.newc	
Cs�dd�}	|||j�}|sttd�|j��|�d�r&t|dd����}n|�d�r9t|dd����}d|_nqg}|||j�}t|�d	kr�|d
d	�}|dkra|dkrat	|�t	d�d	}n
t	|�t	d
�d}z|�
t�|d	d��d|��Wnt
y�}zttd�|jt�|�f��d}~ww|||j�}t|�d	ksHt�d�|��}t|�|kr�ttd�|jt|�|f��||_dS)NcSs|��}|�|�|�d�S)Nr�)r]r3r�)r�rbr'r(r(r)�getlineDs

zbinhunk._read.<locals>.getlineTs"could not extract "%s" binary datasliteral r�sdelta r�rr�Z�A�a�s&could not decode "%s" binary patch: %sr,s%"%s" length is %d bytes, should be %d)rbrgrrr"r�r�r�r$�ordr3r�	b85decode�
ValueErrorr�forcebytestr�zlib�
decompressr.r)	rVr�rr%r.�decr'rrr(r(r)rCsT�

�
$�������
z
binhunk._readN)rarbrcr�rWrfrprr(r(r(r)ro1srocCsF|dd��d�}|�d�}|dkr|�d�}|dkr|S|d|�S)Nr�r�rrr)r�r�)�strrWr�r(r(r)�
parsefilenameos

r$cCs0g}|D]}t�|d�r|��}|�|�q|S)a�reverse the signs in the hunks given as argument

    This function operates on hunks coming out of patch.filterpatch, that is
    a list of the form: [header1, hunk1, hunk2, header2...]. Example usage:

    >>> rawpatch = b"""diff --git a/folder1/g b/folder1/g
    ... --- a/folder1/g
    ... +++ b/folder1/g
    ... @@ -1,7 +1,7 @@
    ... +firstline
    ...  c
    ...  1
    ...  2
    ... + 3
    ... -4
    ...  5
    ...  d
    ... +lastline"""
    >>> hunks = parsepatch([rawpatch])
    >>> hunkscomingfromfilterpatch = []
    >>> for h in hunks:
    ...     hunkscomingfromfilterpatch.append(h)
    ...     hunkscomingfromfilterpatch.extend(h.hunks)

    >>> reversedhunks = reversehunks(hunkscomingfromfilterpatch)
    >>> from . import util
    >>> fp = util.stringio()
    >>> for c in reversedhunks:
    ...      c.write(fp)
    >>> fp.seek(0) or None
    >>> reversedpatch = fp.read()
    >>> print(pycompat.sysstr(reversedpatch))
    diff --git a/folder1/g b/folder1/g
    --- a/folder1/g
    +++ b/folder1/g
    @@ -1,4 +1,3 @@
    -firstline
     c
     1
     2
    @@ -2,6 +1,6 @@
     c
     1
     2
    - 3
    +4
     5
     d
    @@ -6,3 +5,2 @@
     5
     d
    -lastline

    sreversehunk)rrir�r3)rQ�newhunksr:r(r(r)�reversehunkszs8r&c	s�G�fdd�dt�}|�}t�}|�d�|��|�d�d}t|�D]"\}}z|j||||�WntyBtd||f��w|}q#~|�	�S)aDpatch -> [] of headers -> [] of hunks

    If maxcontext is not None, trim context lines if necessary.

    >>> rawpatch = b'''diff --git a/folder1/g b/folder1/g
    ... --- a/folder1/g
    ... +++ b/folder1/g
    ... @@ -1,8 +1,10 @@
    ...  1
    ...  2
    ... -3
    ...  4
    ...  5
    ...  6
    ... +6.1
    ... +6.2
    ...  7
    ...  8
    ... +9'''
    >>> out = util.stringio()
    >>> headers = parsepatch([rawpatch], maxcontext=1)
    >>> for header in headers:
    ...     header.write(out)
    ...     for hunk in header.hunks:
    ...         hunk.write(out)
    >>> print(pycompat.sysstr(out.getvalue()))
    diff --git a/folder1/g b/folder1/g
    --- a/folder1/g
    +++ b/folder1/g
    @@ -2,3 +2,2 @@
     2
    -3
     4
    @@ -6,2 +5,4 @@
     6
    +6.1
    +6.2
     7
    @@ -8,1 +9,2 @@
     8
    +9
    cs�eZdZdZdd�Zdd�Z�fdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
eeeed�eeee	d�eeed�eed�de	id�ZdS)zparsepatch.<locals>.parserzpatch parsing state machinecSs4d|_d|_d|_d|_g|_g|_g|_g|_dS)Nrr,)r�r�r�r�r�r�rbr�rZr(r(r)rW�s
z#parsepatch.<locals>.parser.__init__cSs6|�g�|\}}}}}t|�|_t|�|_||_dSrR)�
addcontextr�r�r�r�)rV�limits�	fromstart�fromend�tostart�toendr�r(r(r)�addrange�s




z#parsepatch.<locals>.parser.addrangec	s�|jr;t|j|j|j|j|j|j|��}|jj�|�|jt	|j�|j
7_|jt	|j�|j7_g|_g|_||_dSrR)
rbr�r�r�r�r�r�rQr3r$rr�r�)rVr�r�r�r(r)r'�s"�

z%parsepatch.<locals>.parser.addcontextcSs.|jr
|j|_g|_|jr|�g�||_dSrR)r�r�rbr'r�r(r(r)�addhunk
s

z"parsepatch.<locals>.parser.addhunkcSs(|�g�t|�}|j�|�||_dSrR)r'r�r�r3)rVr�r�r(r(r)�newfiles

z"parsepatch.<locals>.parser.newfilecSsdSrRr(r�r(r(r)�addotherr\z#parsepatch.<locals>.parser.addothercSs|�g�|jSrR)r'r�rZr(r(r)�finisheds
z#parsepatch.<locals>.parser.finished)�context�file�hunk�range)r3r4r5�other)r2r3r5)r2r4r6)r3r2r4r5r6N)rarbrcr�rWr-r'r.r/r0r1�transitionsr(r�r(r)�parser�s4
���
�r8r,rr2sunhandled transition: %s -> %s)
rhr-r�r.r?�	scanpatchr7�KeyErrorrgr1)�originalchunksr�r8�prA�state�newstater�r(r�r)r��s",R

��r�cCs�t|�}d}|dkrd||��fS|}|dkr]|�d|�}|dkr-ttd�|||f��|d7}||dkrU|||d�dkrU|d7}||dkrU|||d�dksA|d8}|dks|d|���|||d���fS)a�turn a path from a patch into a path suitable for the repository

    prefix, if not empty, is expected to be normalized with a / at the end.

    Returns (stripped components, path in repository).

    >>> pathtransform(b'a/b/c', 0, b'')
    ('', 'a/b/c')
    >>> pathtransform(b'   a/b/c   ', 0, b'')
    ('', '   a/b/c')
    >>> pathtransform(b'   a/b/c   ', 2, b'')
    ('a/b/', 'c')
    >>> pathtransform(b'a/b/c', 0, b'd/e/')
    ('', 'd/e/a/b/c')
    >>> pathtransform(b'   a//b/c   ', 2, b'd/e/')
    ('a//b/', 'd/e/c')
    >>> pathtransform(b'a/b/c', 3, b'')
    Traceback (most recent call last):
    PatchApplicationError: unable to strip away 1 of 3 dirs from a/b/c
    rr,�/rSs*unable to strip away %d of %d dirs from %srN)r$r�r�rrr�)r�r2ro�pathlenr��countr(r(r)�
pathtransformJs(��  ��$rBcCs�|dk}|dk}|o|jdko|jdk}|o|jdko|jdk}	t|||�\}
}|o/|�|�}t|||�\}
}||kr?|}n|oF|�|�}|oO|oO|}|d|�d�d�}|d|�d�d�}|r||kr|�|�r|jdkr|jdkrd}d}|
|
ko�|�|�}d}|s�|r�|r�|r�|}n|}n|r�|}|s�|s�|r�|}n|}n|s�|}ntt	d���t
|�}|r�d|_|S|	r�d	|_|S)
Nr�rr?rTFs&undefined source and destination filesr�r�)r�rkr�rmrBr��rfindr"rgrr�r�)rE�
afile_orig�
bfile_origrbr2ro�nulla�nullbrGrH�abaser��gooda�bbaser��goodbrF�abasedir�bbasedir�isbackupr�r�r(r(r)�
makepatchmetass\��

�rOc	#s�t�d�}t|���fdd�}t�jd�D]p}|�d�s"|�d�rJdd�}|||�}���}|�d	�r?���}|||g7}n��|�d
|fVq|�d�r^d�d
||�fdd��fVq|�d�rrd�d||�fdd��fVq|�|�}|r�d|��fVqd|fVqdS)z�like patch.iterhunks, but yield different events

    - ('file',    [header_lines + fromfile + tofile])
    - ('context', [context_lines])
    - ('hunk',    [hunk_lines])
    - ('range',   (-start,len, +start,len, proc))
    s'@@ -(\d+),(\d+) \+(\d+),(\d+) @@\s*(.*)cs>|g}t�jd�D]}||�r|�|�q	��|�|S|S)zscan lr while predicate holdsr,)r�r]r3r�)�firstr<r/r%)r�r(r)�	scanwhile�s
zscanpatch.<locals>.scanwhiler,r�sdiff -r cSs|�dd�}|p|ddvS)Nrr)r��diff)r#)r%rWr(r(r)�	notheader�szscanpatch.<locals>.notheaderr�r3r)rr�r2c�
|���SrRr��r'��csr(r)r\��
zscanpatch.<locals>.<lambda>)rr)rrr�r4crTrRr�rUrVr(r)r\�rXr5r6N)	r�r�r�r�r]r"r�r�r�)	rA�lines_rerQr%rSr�r�r�r@r()rWr�r)r9�s2�






�r9cCsbd}z
|j��}|j}Wntyt|j���}Ynwt|�}|�|�t|�}|�|�|S)a�
    Git patches can emit:
    - rename a to b
    - change b
    - copy a to c
    - change c

    We cannot apply this sequence as-is, the renamed 'a' could not be
    found for it would have been renamed already. And we cannot copy
    from 'b' instead because 'b' would have been changed already. So
    we scan the git patch for copy and rename commands so we can
    perform the copies ahead of time.
    r)	rA�tellrr-rr�r�r�r?)r��	firstliner�rA�gitlrr�r(r(r)�scangitpatch�s

�

r]ccs��d}d}d}d}d}}d}d}d}	t|�}
t|
jd�D�]<}||kr�|	s+|�d�s9|	dur4|�d�s9|�d�r�d}|rI|d	�||�rI|��}|�d�rUt|
|j�}
n|	dur`|�d�r`d
}	t||d|
|	�}
|d7}|r�d}d|||
|r{|�	�p|dffVd|
fVn�|�d
�r�t
�|�d��}|s�q|dur�t
|
|�}ddd�|D�fV|��d|�d�}d|�d�}|r�|d	�||�s�|��}dd|jd|jd|�	�ffV|r�|d	�||�r�|s�ttd�|dd���d
}nZ|�d��r|
��}|�d��s|
�|�qd
}d}	t|�}t|�}n7|�d��rO|
��}|�d��s.|
�|�q|
��}|
�|�|�d��sC|
�|�qd
}d
}	t|�}t|�}|�rZd}d
}|}d}q|�rx|��}dd|jd|jd|�	�ffV|�s^dSdS)aDRead a patch and yield the following events:
    - ("file", afile, bfile, firsthunk): select a new target file.
    - ("hunk", hunk): a new hunk is ready to be applied, follows a
    "file" event.
    - ("git", gitchanges): current diff is in git format, gitchanges
    maps filenames to gitpatch records. Unique event.
    r,NrFr�@s***************r�rSTr3r4r�r��gitcSsg|]}|jdvr|���qS))r�r�)r�r�)r�rBr(r(r)r�-sziterhunks.<locals>.<listcomp>r�r�r!s'failed to synchronize metadata for "%s"r��+++s***)r�r�r]r"r�r�ror�rbr�r�r�r�r]r�r�rgrr�r$)rAr�r�r=�hunknum�emitfiler/r��BFILEr�r�rYr�r�r@�l2�l3r(r(r)�	iterhunks�s�����



����




�"�rfc
Csdd�}d}||�}||d�}||�}||d�}d}|t|�kr�t|||d��}|d7}|d@r�d}d}|d@rJt|||d��}|d7}|d@r`|t|||d��d	>O}|d7}|d
@rv|t|||d��d>O}|d7}|d	@r�|t|||d��d>O}|d7}|d@r�t|||d��}|d7}|d
@r�|t|||d��d	>O}|d7}|d@r�|t|||d��d>O}|d7}|dkr�d}||}	||||	�7}n|dkr�||}	||||	�7}||7}nttd���|t|�ks"|S)z_Apply a binary delta hunk
    The algorithm used is the algorithm from git's patch-delta.c
    cSs4d}t�|�D]}|d7}t|�d@s|Sq|S)Nrr�)rr�r)�binchunkr�r:r(r(r)�	deltaheadjs�z applybindelta.<locals>.deltaheadr,Nrrrgr!r�r���� r�isunexpected delta opcode 0)r$rrr)
rhr�ri�outrWr��cmdrLr.�
offset_endr(r(r)resZ
�%rr,r=c
Cst||t|||||d�S)aNReads a patch from fp and tries to apply it.

    Returns 0 for a clean patch, -1 if any rejects were found and 1 if
    there was any fuzz.

    If 'eolmode' is 'strict', the patch content and patched file are
    read in binary mode. Otherwise, line endings are ignored when
    patching then normalized according to 'eolmode'.
    �r2rorC)�
_applydiffrA)rwrArEr7r2rorCr(r(r)�	applydiff�s
�rrcCs,|rt�|j|��|�}|dkr|d7}|S)Nr,r?)r�	canonpathr�getcwd)rror(r(r)�_canonprefix�s
rucsht|j�����fdd�}d}	d}
d}t|�D�]\}}
|dkr/|s#q|�|
�}|dkr.d}
q|dkr�|r=|	|��7}	d}|
\}}}}|rU||j�|_|jrT||j�|_n	t||||���}|jdkri|�	|j�|s�|jdkrw|�	|j�qd	\}}|jd
vr�|�
|j�dd�\}}|dur�ttd�|j��|j
r�|j
}|jd
kr�d}|s�|r�|jdvr�|�|j�r�ttd�|j��|�|j|||j�qz||||||d�}Wqty�}z|�t�|�d�d}|	d7}	WYd}~qd}~ww|dk�r|
D]}||j�}|�
|�\}}|du�rq�|�|||�q�qt�td�|��|�r-|	|��7}	|	�r2dS|
S)Ncst|�d��dS)Nr)rB)r<�ror2r(r)�pstrip�r�z_applydiff.<locals>.pstriprr4rr3r�r�r�)r�r�r!ssource file '%s' does not existr�r,)r�r�r�s,cannot create %s: destination already exists)rCrr_�unsupported parser state: %srS)rurrfr�rur�r�rOr�rvr�rrr�r�r��
PatchErrorrrrr�Abort)rwrA�patcherrEr7r2rorCrw�rejects�err�current_filer=�valuesr�r�r��
first_hunkr�r�r��instr�r(rvr)rq�s�
���


�
������


�rqcCs�d}g}|j}	|	r|�dt�|	��d|d�|�|t�|�f}
|�d|
�t�|
d�}ztt�|�D]c}|�	�}|�
|d�|�d�rSt�|�}
d}|�
|
�q4|�d	�d
krod}|sg|�|
d�d}|�|d�q4|�d�d
kr~|�|d�q4|�d
�d
kr�|s�|�|
d�d}|�|d�q4W|r�t�|||�n|r�t�|||�ww|��}|r�ttd�t�|���|S)ztuse <patcher> to apply <patchname> to the working directory.
    returns whether patch was applied with fuzz factor.Fs-d %ss%s %s -p%d < %srsUsing external patch tool: %s
�rbrspatching file s	with fuzzrTssaving rejects to filesFAILEDspatch command failed: %s)rr3r�
shellquoter.r��popenrr�r�rVr"�parsepatchoutputr!r�rrr&rurr�explainexit)rwrr{�	patchnamer2r+rr�args�cwdrnrAr%�pf�printed_file�coder(r(r)�_externalpatch	s`�

������r�c

Cs�|durt�}|dur|�dd�}|��tvr t�td�|��|��}t�}zt|d�}Wnt	y9|}Ynwz t
|||||||d�}	W||krO|��|�|���|��n||krc|��|�|���|��w|	dkryt
td���|	dkS)Nreseols!unsupported line endings type: %sr�rprspatch failed to apply)r�configrj�eolmodesrrzrr*r
�	TypeErrorrrru�updater)
rwrE�patchobjr2ror+rCr7rAr�r(r(r)�patchbackendN	s8��
�
r�c	Cs t|||�}t|||||||�S)zwuse builtin patch to apply <patchobj> to the working directory.
    returns whether patch was applied with fuzz factor.)rr�)	rwrr�r2ror+rCrrEr(r(r)�
internalpatchl	sr�c	
Cs"t||||�}	t||	|||||�SrR)r5r�)
rwrr6r7r�r2ror+rCrEr(r(r)�	patchrepo|	sr�c		CsH|�dd�}|dur
t�}|rt|||||||�St||||||||�S)a�Apply <patchname> to the working directory.

    'eolmode' specifies how end of lines should be handled. It can be:
    - 'strict': inputs are read in binary mode, EOLs are preserved
    - 'crlf': EOLs are ignored when patching and reset to CRLF
    - 'lf': EOLs are ignored when patching and reset to LF
    - None: get it from user settings, default to 'strict'
    'eolmode' is ignored when using an external patcher program.

    Returns whether patch was applied with fuzz factor.
    suireN)r�rr�r�)	rwrr�r2ror+rCrr{r(r(r)�patch�	s��r�c	Cst||j�}t||�}t|d��f}t�}t|�D]T\}}	|dkr_|	\}
}}}
|
rDt|
j|d|�d|
_|
jrCt|
j|d|�d|
_n	t	||
||||�}
|�
|
j�|
jdkr^|�
|
j�q|dvrlt�
td�|��q|Wd�S1sywYdS)Nr�r3rr�)r4r_rx)r�rrur
rrfrBr�r�rOr!r�rrzr)rwr�	patchpathr2rorErArr=rr�r�r�r�r(r(r)�changedfiles�	s8
����
��$�r�c@seZdZdS)�GitDiffRequiredN)rarbrcr(r(r(r)r��	sr�ccs��|s
|s
|j��}||}||}t||||||||||	d�
D]8\}
}}}|
dur7|dus2Jd��|
||�}d�dd�|D��}|rS|sKt|�dkrSd�|�dV|rX|Vq dS)	a�yields diff of changes to files between two nodes, or node and
    working directory.

    if node1 is None, use first dirstate parent instead.
    if node2 is None, compare node1 with working directory.

    losedatafn(**kwarg) is a callable run when opts.upgrade=True and
    every time some change cannot be represented with the current
    patch format. Return False to upgrade to git patch format, True to
    accept the loss or raise an exception to abort the diff. It is
    called with the name of current file being diffed as 'fn'. If set
    to None, patches will always be upgraded to git format when
    necessary.

    prefix is a filename prefix that is prepended to all filenames on
    display (used for subrepos).

    relroot, if not empty, must be normalized with a trailing /. Any match
    patterns that fall outside it will be ignored.

    copy, if not empty, should contain mappings {dst@y: src@x} of copy
    information.

    if copysourcematch is not None, then copy sources will be filtered by this
    matcher

    hunksfilterfn, if not None, should be a function taking a filectx and
    hunks generator that may yield filtered hunks.
    )	�ctx1�ctx2r��changes�opts�
losedatafn�pathfnr��copysourcematchNs-fctx2 unexpectly None in diff hunks filteringr,css�|]
\}}d�|�VqdS)r,N�r.)r��hrange�hlinesr(r(r)r�
s�zdiff.<locals>.<genexpr>rr)r�p1�	diffhunksr.r$)r�node1�node2r�r�r�r�r�r�r��
hunksfilterfnr�r��fctx1�fctx2r�rQrr(r(r)�diff�	s:�*
�
�
��r�c

s<|durtj}dd�}
|
��|s�j�|d�}t|t�r&|dd�\���
n|j|j|j���
�s9�s9�
s9gS�jj	r@t
�nt��fdd�������fD���durei�|j
s]|jretj��|d���rs�fdd	�t���D��t��}t��}t�
�}
�D]}|�vr�|�|�|�|�q��
D]}|�vr�|
�|�q�t|��t|��t|
��
t����D]\}}|�vr��|=q�t��t||B|
B��}���|f���|fg}t��|��������	�
��f
d
d�}|j�r|j
�sz�fdd
�}t||jdd�|��WSt�y||jdd�d�YSw||d�S)z�Yield diff of changes to files in the form of (`header`, `hunks`) tuples
    where `header` is a list of diff headers and `hunks` is an iterable of
    (`hunkrange`, `hunklines`) tuples.

    See diff() for the meaning of parameters.
    Ncsi�t�����fdd�}|S)NcsX|j|��|�d�}|�vr t��dkr����=|���|<n��|���|�|S)N)�filelog�)�filectxr]r$�popleftr�rHr3)r)r6r<��cache�orderr(r)�
getfilectx,
s


z4diffhunks.<locals>.lrugetfilectx.<locals>.getfilectx)�collections�deque)r�r(r�r)�
lrugetfilectx(
sz diffhunks.<locals>.lrugetfilectxr�r�csg|]}|r�|��qSr(r()r��node)�hexfuncr(r)r�M
r�zdiffhunks.<locals>.<listcomp>csi|]\}}�|�r||�qSr(r()r�r�r()r�r(r)�
<dictcomp>W
s��zdiffhunks.<locals>.<dictcomp>c
st��	�������||��SrR)�trydiff)r��losedata)
r�r�r�r�r��modifiedr�rr�revsr(r)�difffn}
s�zdiffhunks.<locals>.difffncs�r�|d�s	t�dS)N�r1)r�r�)r�r(r)r��
s�zdiffhunks.<locals>.losedataF)�gitT)r�defaultopts�statusrn�listr�r�rrw�	debugflagrr	r�r��upgrader�
pathcopiesr�	iteritemsrrHr!r$r�r�
matchfiles�rev�
prefetchfilesr�r�)rr�r�r�r�r�r�r�r�r�r��modifiedset�addedset�
removedsetr)r�r(�
prefetchmatch�
revmatchesr�r�r()
r�r�r�r�r�r�r�r�r�r�rrr�r)r�
sz

�
�

�
���

��
r�ccs��|D]X}|�d�}|��}|�d�rd}n|�d�rd}nt�d|��t�|�D]}|�d�r7|dfVq*||fVq*||krL|t|�d	�d
fV||kr[|t|�d	�dfVqd	S)z1yield tokens for a list of lines in a single hunkr�r�diff.deletedr�
diff.inserted�unexpected hunk line: %sr�diff.tabN�diff.trailingwhitespacer,)r�r"r�ProgrammingError�tabsplitter�findallr$)�	hunklinesr%�	chompline�	stripline�label�tokenr(r(r)�diffsinglehunk�
s&�



��r�ccst�t�}t�}|D]*}|dd�dkr||dd�7}q	|dd�dkr-||dd�7}q	t�d|��|r8|sDt|�D]}|Vq<dSt�t|��}t�t|��}dd�|D�}d	d�|D�}d
�|�}	d
�|�}
g}g}tj	|	|
||d�}
|
D]8\\}}}}}|dk}t�
d
�|||���D]	}|�||f�q�t�
d
�|||���D]	}|�||f�q�qydd
|fdd|ffD]{\}}}d}|D]q\}}|r�||fVd}|�d�}|r�|dd�}|�d�r�|dd�}|t
|�d�}|��}|t
|�d�}t�|�D] }d|dd�k�rd}n|�r|d}n|d}||fV�q|�r6|�r/|dfV|d
fVd}q�q�dS)zEyield tokens for a list of lines in a single hunk, with inline colorsrrrNrr�cS� g|]}|dkr
|n|d�qS�rr(�r�rWr(r(r)r��
� z(diffsinglehunkinline.<locals>.<listcomp>cSr�r�r(r�r(r(r)r��
r�r,)�lines1�lines2�!r�r�TFrrS�
rr�s.changeds
.unchangedr�)�	bytearrayrr�r��wordsplitterr��bytesr.r�	allblocksrIr3r�r$r�r�)r�rjrlr%r��al�bl�aln�bln�an�bn�atokens�btokens�blocks�a1�a2�b1�b2�btyperr�ror��tokens�
nextisnewline�isendofline�chomp�	endofline�	endspaces�maybetab�currentlabelr(r(r)�diffsinglehunkinline�
sx�

��





���rc/s��|�d�r|djrt�nt�gd�}dg}d}g���fdd�}||i|��D]�}|�d�}t|�}	t|�D]{\}
}|rF|�d�rEd}n	|rO|�d	�sOd
}d}|s\|r\|�d�r\d
}|}
|rb|}
|rv|}|
d|	krp|d7}��|�q8|�D]}|Vqy|�	�}|
D]\}}|�|�r�||fV||kr�|t|�d
�dfVnq�|dfV|
d|	kr�dVq8|�D]}|Vq�q)d
S)z@yields 2-tuples of (output, label) based on the output of func()r�)
)rRs
diff.diffline)�copy�
diff.extended)�renamer)soldr)snewr)sdeletedr)sindexr)s
similarityr)r�sdiff.file_a)r`sdiff.file_b)r^s	diff.hunkFc3s.��r���D]}|Vqg�dd�<dSdSrRr()r���
dodiffhunk�
hunkbufferr(r)�consumehunkbuffers��z$difflabel.<locals>.consumehunkbufferrr^)rrrr^r�T)rrrNr�r,�rr,)
r]�worddiffrr�r#r$rtr"r3r�)�funcr��kw�headprefixes�textprefixes�headrr0r/�	linecountr�r%�diffline�prefixes�bufferedliner�r�ror�r(rr)�	difflabel�
sj�
�

��


��
	�
��rcOsttg|�Ri|��S)zBlike diff(), but yields 2-tuples of (output, label) for ui.write())rr�)r�rr(r(r)�diffuiMsrc
cs��t�}dd�|��D�}t|�t|�}}t|||�D]O}	d}
|	|	}}|	|vrKd}|	|vrJ|jrJ||	}||vrH||vrHd}
|�|�nd}
n|	|vrgd}|jrg|	|vrg||	|vrg|||	|	krgq|||
fVqdS)agenerates tuples (f1, f2, copyop), where f1 is the name of the file
    before and f2 is the the name after. For added files, f1 will be None,
    and for removed files, f2 will be None. copyop may be set to None, 'copy'
    or 'rename' (the latter two only if opts.git is set).cSsi|]\}}||�qSr(r()r��kr�r(r(r)r�Ysz_filepairs.<locals>.<dictcomp>Nrr)rr�r$r�r!)
r�r�rr�r��gone�copytor�r�r)�copyop�f1�f2r(r(r)�
_filepairsRs4�
��rcCs4|sd}t|�}t�d|�}|�|�t|���S)Nr,sblob %d)r$r�sha1r�r�digest)rr'rWr(r(r)�	_gitindexws
rs120000s100755s100644)r8r9r,c$cs�|	jr	d}}
nd}d}
dd�}dd�}t�|���}t�|���}|s)dd	�}t|||||	�D�]R\}}}d
}d
}d
}d
}d
}d
}|rT|||�}|	jsO|
rT|�|�}|re|||�}|	js`|
re|�|�}|	jrkd}ntdd
�||fD��}|
r�|	js�|s�||vs�|s�||�s�||�r�|r�|s�|s�|r�|r�||kr�|
|p�|�||p�|�}||p�|�}g}|	j�r|�	d|||
|f�|s�|�	dt
|�na|s�|�	dt
|�nUt
|t
|}} || kr�|�	d|�|�	d| �|d
u�r|	j�rt�
||||�d}!|�	d|!�|�	d||f�|�	d||f�n|�r)|�	|||��|�rY|	j�r<|	j�rY|	j�rY|	j�sY|d
u�rCd}|d
u�rX|d
u�rV|�|��sVd}nd}n|d
u�rb|��}|d
u�rk|��}||||||f}"||||||f}#t|"|#|||	�Vq1d
S)z�given input data, generate a diff and yield it in blocks

    If generating a diff would lose data like flags or binary data and
    losedatafn is not None, it will be called.

    pathfn is applied to every path in the diff output.
    r,r�r�cSs d�dd�|D��}d||fS)NrcSsg|]}d|�qS)s-r %sr()r�r�r(r(r)r��sz-trydiff.<locals>.diffline.<locals>.<listcomp>s
diff %s %sr�)r)r��revinfor(r(r)r�sztrydiff.<locals>.difflinecSs|dup	|��dkSr�)r.)r<r(r(r)�isempty�r�ztrydiff.<locals>.isemptycSrYrRr()r)r(r(r)r\�r�ztrydiff.<locals>.<lambda>NFcss �|]}|dur|��VqdSrR)�isbinaryr�r(r(r)r��s�ztrydiff.<locals>.<genexpr>sdiff --git %s%s %s%ssnew file mode %ssdeleted file mode %ssold mode %ssnew mode %s�dssimilarity index %d%%s
%s from %ss%s to %s�s)�noprefixr�datestr�daterr�r;rr�r3�_gitmode�showsimilarityr�score�nobinary�index�cmpr��diffcontent)$rr�r�r�r�r�rr�r�r�r�r��aprefix�bprefixrr �date1�date2rrr�content1�content2r�r��flag1�flag2r��path1�path2r��mode1�mode2�sim�data1�data2r(r(r)r��s��







�����	�	����
�
����

�

�r�c
Cs|\}}}}}	}
|\}}}
}}}||vrt|	�ntj}|
|vr#t|�ntj}|rF|jrF|jsFt�|	|�}|r?|�d||f�d|gff}n:|jrl|jdkrl|}|durV|}|�d|d|j�|d|j�t	|f�tj
|	|
||||
||d�\}}|�|�||||fS)aOdiffs two versions of a file.

    data1 and data2 are tuples containg:

        * ctx: changeset for the file
        * fctx: file context for that file
        * path1: name of the file
        * flag: flags of the file
        * content: full content of the file (can be null in case of binary)
        * date: date of the changeset

    header: the patch header
    binary: whether the any of the version of file is binary or not
    opts:   user passed options

    It exists as a separate function so that extensions like extdiff can wrap
    it and use the file content directly.
    sindex %s..%sNrsindex %s..%s %s)r�r�)rr�nullhexr�r*r�b85diffr3r+r'�unidiff�extend)r;r<r�r�r�r�r�r6r4r2r0r�r�r7r5r3r1�index1�index2rrQ�flag�uheadersr(r(r)r-sB���	
�

r-c
Csdd\}}}}}|D]!\}}}}	t|t�|��}t|||�}||7}||7}|p)|	}q	|||||fS)N)rrrrF)r�r�colwidth)
�stats�maxfile�maxtotal�addtotal�removetotalr�r)rjr�rlr(r(r)�diffstatsumLs
rKcs,t�d�}g�d\���������fdd�}d}|D]u}|�d�rH|�d}d\���|�d	�r:t�|��d
��q|�d�rG|�|��d��q|�d
�rPd}q|�d�r\|s\�d7�q|�d�rh|sh�d7�q|�d�sr|�d�rud�q|�d�r�|dd��q|�d�r��d|dd�7�q|��S)Ns^diff .*-r [a-z0-9]+\s(.*)$)NrrFcs�r
������f�dSdSrRrOr(��addsr�r!�removes�resultsr(r)�	addresult^s�zdiffstatdata.<locals>.addresultFrRT)rrFr�r!sdiff -rrs@@rrr�sBinary filesrename fromr�s	rename tos => %sr�)r�r�r"r�r�r�)r/r�rPr&r%r(rLr)�diffstatdataXs@




�


�

�rQ�Pc
s�g}t|�}t|�\}�}}}tt���}|r|dkrd}|||d��dkr+d���fdd�}	|D]1\}
}}}
|
r?d}nd||}d|	|�}d	|	|�}|�d
|
d|t�|
�||||f�q4|rv|�td�t|�||f�d
�|�S)Nr�r�r�cs&��kr|St|��tt|���SrR)r�r��bool)r���
graphwidthrHr(r)�scale�szdiffstat.<locals>.scalesBinr/rrs %s%s |  %*s %s%s
rs5 %d files changed, %d insertions(+), %d deletions(-)
r,)	rQrKr$r#r3rrErr.)r/�width�outputrF�maxname�	totaladds�totalremoves�	hasbinary�
countwidthrVr�rMrNr!rA�pluses�minusesr(rTr)�diffstat�sD�����
r`cos��t|i|����D]B}|rD|ddvrD|�dd�\}}|ddfVt�d|�}|r3|�d�dfVt�d	|�}|rC|�d�d
fVn|dfVdVq
dS)
zOlike diffstat(), but yields 2-tuples of (output, label) for
    ui.write()
    rSs+-rrr,s\++rsdiffstat.inserteds-+sdiffstat.deletedrN)r`r��rsplitr�r�r�)r�rr%�name�graphr@r(r(r)�
diffstatui�s��
�rdrR)rr,r=)Nr=)r,Nr=r)rr,Nr=r)rr,)
NNNNNNNNNN)NNNNNNN)rR)l�
__future__rrr��
contextlibr�rrrr�r2r �i18nrr�rrr	rr
�rrr
rrrrrrrrrr��utilsrrrrr-r�r�r�r�ryrgrr#r��contextmanagerr|rtrhr�r�r�r�r�rr*r5rrr�rAr�r�r�r�rbror$r&r�rBrOr9r]rfrrrrurqr�r�r�r�r�r��	Exceptionr��diffallopts�diffopts�difffeatureoptsr�r�r�rrrrrr'r�r-rKrQr`rdr(r(r(r)�<module>s�<

�
q0-#41&
.
jPn
C7e>
@)=3g
;	
�_2
�#
�
�
�
!
�O
�HP%	9
-0

https://t.me/RX1948 - 2025