Plan 9 from Bell Labs’s /usr/web/sources/contrib/bichued/root/sys/lib/python/mercurial/patch.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�
�c@s�ddklZddklZlZlZddkZddkZddkZddk	Z	ddk
Z
ddkZddkZddk
ZddkZddkZddkZddkZddkZeid�Zdefd��YZdefd��YZd	�Zd
�Zd2Zd3Zd4Zdefd��YZd�Z defd��YZ!eid�Z"eid�Z#defd��YZ$defd��YZ%defd��YZ&de&fd��YZ'de&fd��YZ(d�Z)d �Z*d!�Z+de-d"�Z.dde-dd#�Z/he-d$�Z0dd%�Z1d&�Z2hd'd(�Z3ddhd'd)�Z4d*�Z5d+�Z6dddddd,�Z7d-de-dd.�Z8d/�Z9d0d1�Z:dS(5i�(t_(thextnullidtshortNsdiff --git a/(.*) b/(.*)t
PatchErrorcBseZRS((t__name__t
__module__(((s"/sys/lib/python/mercurial/patch.pyRstNoHunkscBseZRS((RR(((s"/sys/lib/python/mercurial/patch.pyRscCs�g}||gD]}|ti|||�q~\}}tii|�otitd�|��ntii|�}|oXtii|�oDyti	|�Wq�t
j
o titd�|��q�Xnti||�dS(Ns,cannot create %s: destination already existss8cannot create %s: unable to create destination directory(tutilt	canonpathtostpathtexiststAbortRtdirnametisdirtmakedirstIOErrortcopyfile(tsrctdsttbasedirt_[1]txtabssrctabsdsttdstdir((s"/sys/lib/python/mercurial/patch.pyRs<	cCs�tidti�}tidd�\}}ti|d�}y�tii�i	|�}|d}|d}d|i
dd	�j}	d&}
d&}d&}g}
|oo|id
�o8|i
d�}|djo||d
i�}q�n|idd�}|id|�n|o|id|�nd}d'}d	}x�|i�D]�}|i�}|id|�||joqOn|idt�}|i|�}|ot}t}|itd�|id��|d
7}ti�}xy||id� i�D]^}|id�o:|itd��t}|id�|i�d&}n�|o�|id�o|d}|id|�q1|id�o|d}
q1|id�o|d}q1|id�o|d }q1|id!�o|
i|d �q1n|d"jo|	o
t}n|id#�o&|o|i|�|id$�q
q
W|i �}|o2|i|�|i!d$�p|id$�q�q�qO|o&|o|djo|d$|7}qOqOWWn!|i"�ti#|��nX|o%|i|�od%||f}n|i"�|p-ti#|�d&|||
|d&d&d&fSn|
o|
i$d�pd&}|
o|
i$d�pd&}||||
||||fS((s?extract patch from data read from fileobj.

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

    return tuple (filename, message, user, date, node, p1, p2).
    Any item in the returned tuple can be None. If filename is None,
    fileobj did not contain a patch. Caller must unlink filename when done.s^^(?:Index:[ \t]|diff[ \t]|RCS file: |retrieving revision [0-9]+(\.[0-9]+)*$|(---|\*\*\*)[ \t])tprefixs	hg-patch-twtSubjecttFromsgit-send-emailsX-Mailerts[PATCHt]iis
	t sSubject: %s
s	From: %s
s
text/plainstext/x-diffstext/x-patchsContent-Type: %s
tdecodesfound patch at byte %d
s# HG changeset patchspatch generated by hg export
s# User is# Date s	# Branch i	s
# Node ID i
s	# Parent s---s# s
s%s
%sN(s
text/plainstext/x-diffstext/x-patch(%tretcompilet	MULTILINEttempfiletmkstempR
tfdopentemailtParsertparsetgettNonet
startswithtfindtlstriptreplacetdebugtwalktget_content_typetget_payloadtTruetsearchtFalseRtstartt	cStringIOtStringIOt
splitlinestseekttruncatetappendtwritetgetvaluetendswithtclosetunlinktpop(tuitfileobjtdiffretfdttmpnamettmpfptmsgtsubjecttusertgitsendmailtdatetnodeidtbranchtparentstpendt
diffs_seentok_typestmessagetparttcontent_typetpayloadtmthgpatcht
ignoretexttcfptlinetp1tp2((s"/sys/lib/python/mercurial/patch.pytextract,s�	




 











 iiit	patchmetacBs eZdZd�Zd�ZRS(s�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|_t|_dS(NtMODIFYi(RR-toldpathtmodetoptlinenoR8tbinary(tselfR((s"/sys/lib/python/mercurial/patch.pyt__init__�s					cCs'|d@}|d@}||f|_dS(Ni i@(Rf(RjRftislinktisexec((s"/sys/lib/python/mercurial/patch.pytsetmode�s

(RRt__doc__RkRn(((s"/sys/lib/python/mercurial/patch.pyRc�s		c	Cs�d}g}d}d}xP|D]H}|d7}|id�}|id�octi|�}|oI|o|i|�n|idd�\}}t|�}||_qgq|o�|id�oB|i	djo|t
O}n|i|�d}|tO}qn|id	�od|_	|d
|_qg|id�o|d|_
qg|id
�od|_	|d|_qg|id�o|d|_
qg|id�o'd|_	|it|dd��qg|id�o'd|_	|it|dd��qg|id�o|it|dd��qg|id�o|tO}t|_qgqqW|o|i|�n|p
t}n||fS(s9extract git-style metadata about patches from <patchname>iis 
s
diff --gitis--- tCOPYtRENAMEsrename from is
rename to i
s
copy from scopy to isdeleted filetDELETEi�snew file mode tADDs	new mode sGIT binary patchN(RpRq(R-trstripR.tgitretmatchR?tgroupRcRhRgt	GP_FILTERtGP_PATCHReRRntintt	GP_BINARYR6Ri(	tlrtgpt
gitpatchestdopatchRhR_R[RR((s"/sys/lib/python/mercurial/patch.pytreadgitpatch�sd


				

t
linereadercBs/eZed�Zd�Zd�Zd�ZRS(cCs||_g|_||_dS(N(tfptbufttextmode(RjR�R�((s"/sys/lib/python/mercurial/patch.pyRk�s		cCs%|dj	o|ii|�ndS(N(R-R�R?(RjR_((s"/sys/lib/python/mercurial/patch.pytpush�s
cCsh|io|id}|id=|Sn|ii�}|io"|id�o|d d}n|S(Nis
i�s
(R�R�treadlineR�RB(Rjtl((s"/sys/lib/python/mercurial/patch.pyR��s


ccs'x |i�}|pPn|VqdS(N(R�(RjR�((s"/sys/lib/python/mercurial/patch.pyt__iter__�s
(RRR8RkR�R�R�(((s"/sys/lib/python/mercurial/patch.pyR��s		
s&@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@s((---|\*\*\*) (\d+)(,(\d+))? (---|\*\*\*)t	patchfilecBsteZedd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zdd�Zd	�Z
d
�ZRS(cCs�||_||_||_||_g|_t|_||_|p9y|i|�|_t	|_Wq�t
j
oq�Xn|iitd�|i�h|_
d|_d|_g|_t|_|it�d|_dS(Ns!unable to find '%s' for patching
i(tfnameteoltopenerRFtlinesR8Rtmissingt	readlinesR6RtwarnRthashtdirtytoffsettrejtfileprintedt	printfilethunks(RjRFR�R�R�R�((s"/sys/lib/python/mercurial/patch.pyRk	s*							
						
cCsD|i|d�}z tt||idj	��SWd|i�XdS(Ntr(R�tlistR�R�R-RC(RjR�R�((s"/sys/lib/python/mercurial/patch.pyR�"s cCs�|i|d�}zz|io_|idjoOxY|D]@}|o&|ddjo|d |i}n|i|�q6Wn|i|�Wd|i�XdS(NRs
i�(R�R�R@t
writelinesRC(RjR�R�R�R�((s"/sys/lib/python/mercurial/patch.pyR�)scCsti|�dS(N(R
RD(RjR�((s"/sys/lib/python/mercurial/patch.pyRD6scCsu|iodSn|p
|iio
t|_ntd�|i}|o|ii|�n|ii|�dS(Nspatching file %s
(R�RFtverboseR6RR�R�tnote(RjR�ts((s"/sys/lib/python/mercurial/patch.pyR�9s

csSy|i|}WngSnXt|�djo|id�fd��n|S(Nitkeycst|��S((tabs(R(tlinenum(s"/sys/lib/python/mercurial/patch.pyt<lambda>Qs(R�tlentsort(RjR�R�tcand((R�s"/sys/lib/python/mercurial/patch.pyt	findlinesEscCsIh|_x9t|i�D](\}}|ii|g�i|�qWdS(N(R�t	enumerateR�t
setdefaultR?(RjRR�((s"/sys/lib/python/mercurial/patch.pyt	hashlinesTs	cst�ipdSn�id}�iitd�t�i��i|f��fd�}�i||��dS(Ns.rejs7%d out of %d hunks FAILED -- saving rejects to file %s
c3sotii�i�}d||fVxD�iD]9}x0|iD]%}|V|ddjo	dVq>q>Wq.WdS(Ns--- %s
+++ %s
i�s
s
\ No newline at end of file
(R
RtbasenameR�R�thunk(tbaseRR�(Rj(s"/sys/lib/python/mercurial/patch.pytrejlinesgs

(R�R�RFR�RR�R�R�(RjR�R�((Rjs"/sys/lib/python/mercurial/patch.pyt	write_rejYs

			cCs=|ipdSn|p
|i}n|i||i�dS(N(R�R�R�R�(Rjtdest((s"/sys/lib/python/mercurial/patch.pyR@rs


cCs|i�|i�dS(N(R@R�(Rj((s"/sys/lib/python/mercurial/patch.pyRCys
c
Cs|i�pJttd�|i|it|i�|it|i�|i	f��n|i
d7_
|o|i�n|io|i
i|�dSn|ioB|i�o5|iitd�|i�|i
i|�dSnt|t�o]|i�o|i|i�n5|i�|i(|it|i��7_d|_dSn|i�}|idjo
d}n|i|id}|}ti||i|�djoh|i�o|i|i�n@|i�|i|||i+|i|i	|i7_d|_dSn|i �|i!dddjot|i�}n|}x{t"d�D]m}xdt#t$gD]V}|i||�}|i%|dd|�}	x!|	D]}
ti||i|
�djo�i||�}||i|
|
t|�+|it|�t|�7_d|_|o'd|}|ii}
|i&t#�nd	}|ii'}
|
||}|djotd
�}n
td�}|
||i|
d||f�|Sq�q�WqxWqeW|i&t#�|iitd�|i|f�|i
i|�dS(
Nsbad hunk #%d %s (%d %d %d %d)ii�sfile %s already exists
iR!is
with fuzz %d Rs-Hunk #%d succeeded at %d %s(offset %d line).
s.Hunk #%d succeeded at %d %s(offset %d lines).
sHunk #%d FAILED at %d
((tcompleteRRtnumbertdescR�tatlenatbtlenbR�treverseR�R�R?Rt
createfileRFR�R�t
isinstancetgithunktrmfileRDtnewR�R�R�toldtstartatdiffhelpersttesthunkR�R�txrangeR6R8R�R�R�(RjthR�R�R9t
orig_starttsearch_starttfuzzlenttoponlyR�R�tnewlinestfuzzstrtfR�RL((s"/sys/lib/python/mercurial/patch.pytapply}s�
*

	

	


	

!
#N(RRR8R-RkR�R�RDR�R�R�R�R@RCR�(((s"/sys/lib/python/mercurial/patch.pyR�s		
						R�cBs�eZeed�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	ed
�Zd�Z
d	ed�ZRS(
cCss||_||_|g|_g|_g|_|o|i|�n|i|�||_|o||_dS(N(	R�R�R�R�R�tread_context_hunktread_unified_hunktcreatetremove(RjR�tnumR|tcontextR�R�((s"/sys/lib/python/mercurial/patch.pyRk�s				
	cCsoti|i�}|pttd�|i��n|i�\|_}|_|_	}|_
|idjo
d|_nt|i�|_|i
djo
d|_
nt|i
�|_
t|i�|_t|i	�|_	t
i||i|i|i
|i|i�x[t|id�djo@|id=|id=|id=|id8_|i
d8_
qWdS(Nsbad hunk #%dii�i(tunidescRvR�RRR�tgroupsR�R�tstartbR�R-RzR�taddlinesR�R�R�R�(RjR|R[tfootfoo2((s"/sys/lib/python/mercurial/patch.pyR��s&*

+


cCsN|i�|_ti|i�}|pttd�|i��n|i�\}|_}}}t	|i�|_|djo
|i}nt	|�|i|_|io|id7_nx�t|i�D]�}|i�}|i
d�o|i|�Pn|d}	|i
d�p|i
d�od|	}
n>|i
d�od	|	}
n ttd
�|i|f��|ii|
�|ii|
�q�W|i�}|i
d�o;|idd }	|	|id<|	|id<|i�}nti|�}|pttd�|i��n|i�\}|_}}}t	|i�|_|djo
|i}nt	|�|i|_|io|id7_nd}x�t|i�D]�}|i�}|i
d�o6|idd }	|	|id<|	|i|d<q�n|p|i|�Pn|d}	|i
d
�p|i
d�od|	}
nf|i
d�od	|	}
nHt|i�djo|i|�Pn ttd
�|i|f��|ii|	�x�to||t|i�jo
d}
n|i|}
|d7}|
|
joPq�|
i
d�oq�q�|ii|d|
�Pq�Wq�W|ipLxI|iD]:}|i
d�p|i
d	�o|ii|�qyqyWn|ipPxM|iD]>}|i
d�p|i
d	�o|ii|d�q�q�Wnd|i|i|i|if|_|i|id<dS(Nsbad hunk #%dis---is- s! t-s  R!sbad hunk #%d old text line %ds\ i�s+ t+iRs@@ -%d,%d +%d,%d @@
(R�R�tcontextdescRvRRR�R�R�RzR-R�R�R.R�R�R?R�R�R�R�R�R6tinsert(RjR|R[R�R�taendtfoo3RR�R�tutbendthunkiR�((s"/sys/lib/python/mercurial/patch.pyR��s�




 







 








 

  cCs:|i|i|_|_|i}|i}|i|_|i|_||_||_g|_g|_x�tdt	|i
��D]�}|i
|}|id�o&d|d}|ii|d�n]|id�o"d|d}|ii|�n+|}|ii|d�|ii|�||i
|<q�WdS(NiR�R�(
R�R�R�R�R�R�R�R�R�R�R�R.R?(Rjtoriglenat
origstartaRtotn((s"/sys/lib/python/mercurial/patch.pyR�[s,						
cCs ti|i|i|i�dS(N(R�tfix_newlineR�R�R�(Rj((s"/sys/lib/python/mercurial/patch.pyR�tscCs/t|i�|ijot|i�|ijS(N(R�R�R�R�R�(Rj((s"/sys/lib/python/mercurial/patch.pyR�wscCs'|idjo|idjo|iS(Ni(R�R�R�(Rj((s"/sys/lib/python/mercurial/patch.pyR�zscCs'|idjo|idjo|iS(Ni(R�R�R�(Rj((s"/sys/lib/python/mercurial/patch.pyR�}sc		Csst|t|�d�}|oOd}d}t|i�}xCt|d�D]1}|i|dddjo|d7}qLPqLW|pNxKt|d�D]5}|i||dddjo|d7}q�Pq�Wnt||d�}||jotd|||�}nt||�}||jotd|||�}nt||�}||t|�|!Sn|S(NiiR!i(tminR�R�R�tmax(	RjR�tfuzzR�ttoptbotthlenRR�((s"/sys/lib/python/mercurial/patch.pytfuzzit�s2 	

icCs|i|i||�S(N(R�R�(RjR�R�((s"/sys/lib/python/mercurial/patch.pyR��scCsSg}xF|iD];}|d}|djp
|djo|i|�qqW|S(NiR!R�(R�R?(RjtresRtc((s"/sys/lib/python/mercurial/patch.pytnewctrl�s

cCs|i|i||�S(N(R�R�(RjR�R�((s"/sys/lib/python/mercurial/patch.pyR��s(RRR8RkR�R�R�R�R�R�R�R�R�R�R�(((s"/sys/lib/python/mercurial/patch.pyR��s
		a						%	R�cBs;eZdZd�Zd�Zd�Zd�Zd�ZRS(s
A git hunkcCs||_d|_g|_dS(N(tgitpatchR-ttextR�(RjR�((s"/sys/lib/python/mercurial/patch.pyRk�s		cCs|iidjS(NRsRqRp(sADDsRENAMEsCOPY(R�Rg(Rj((s"/sys/lib/python/mercurial/patch.pyR��scCs|iidjS(NRr(R�Rg(Rj((s"/sys/lib/python/mercurial/patch.pyR��scCs
|idj	S(N(R�R-(Rj((s"/sys/lib/python/mercurial/patch.pyR��scCs
|igS(N(R�(Rj((s"/sys/lib/python/mercurial/patch.pyR��s(RRRoRkR�R�R�R�(((s"/sys/lib/python/mercurial/patch.pyR��s				tbinhunkcBs eZdZd�Zd�ZRS(s6A binary patch file. Only understands literals so far.cCs&tt|�i|�dg|_dS(NsGIT binary patch
(tsuperR�RkR�(RjR�((s"/sys/lib/python/mercurial/patch.pyRk�scCs�|i�}|ii|�x9|o1|id�o |i�}|ii|�qW|pttd���nt|di��}g}|i�}|ii|�x�t|�djo�|d}|djo+|djot	|�t	d�d}nt	|�t	d�d	}|it
i|dd
!�| �|i�}|ii|�q�Wti
di|��}t|�|jo#ttd�t|�|��n||_dS(
Nsliteral scould not extract binary patchiiitZtAR�ii�Rs binary patch is %d bytes, not %d(R�R�R?R.RRRzRtR�tordtbase85t	b85decodetzlibt
decompresstjoinR�(RjR|R_tsizetdecR�R�((s"/sys/lib/python/mercurial/patch.pyRb�s0
!(RRRoRkRb(((s"/sys/lib/python/mercurial/patch.pyR��s	tsymlinkhunkcBs)eZdZd�Zd�Zd�ZRS(sA git symlink hunkcCs#tt|�i|�||_dS(N(R�R�RkR�(RjR�R�((s"/sys/lib/python/mercurial/patch.pyRk�scCstS(N(R6(Rj((s"/sys/lib/python/mercurial/patch.pyR��scCsdS(N((Rj((s"/sys/lib/python/mercurial/patch.pyR��s(RRRoRkR�R�(((s"/sys/lib/python/mercurial/patch.pyR��s		cCs_|did�}|id�}|djo(|id�}|djo|SqWn|| S(Nis
s	iR!(RtR/(tstrR�ti((s"/sys/lib/python/mercurial/patch.pyt
parsefilename�s

cCs�dd�}|dj}|dj}|||�\}}	|o
ti|	�}
|||�\}}|	|jo
|
}
n|otii|�}
|i}|o
|i}n|
o|
o|�}|o7|	|jo*t|_|�o
t	}qt	|_n||jo
|i
|	�}d}|p;|
o|
o|o|	p|}qo|
o
|	}qon|pF|p|o|	p|}q�|p
|	}q�tt
d���n||fS(NicSs�t|�}d}|djod|i�fSnx�|djo�|id|�}|djo ttd�||f��n|d7}x1||djo||djo|d7}q�W|d8}q6W|| i�||i�fS(NiRt/i�s$unable to strip away %d dirs from %si(R�RtR/RRR0(RtcounttpathlenR�((s"/sys/lib/python/mercurial/patch.pyt	pathstrip�s


%s	/dev/nulls&undefined source and destination files(RtlexistsR
RRR�R�R6R�R8R.R-RR(t
afile_origt
bfile_origR�tstripR�Rtnullatnullbtabasetafiletgoodatbbasetbfiletgoodbt
createfuncR�tisbackupR�((s"/sys/lib/python/mercurial/patch.pyt
selectfile�s@

	
	



cCs�d}y|ii�}|i}Wn+tj
oti|ii��}nXt||i�}|i|�t	|�\}}|i
|�||fS(s�
    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.
    i(R�ttellRR:R;treadR�R�R�R�R=(R|t	firstlinetposR�tgitlrRR~((s"/sys/lib/python/mercurial/patch.pytscangitpatch<s


c
cs4h}d}d}d}d}d}	t}
t}d}d}
t||�}t}t}xjtobt}|i�}|pPn|o9|id�o|i�nd|fVd}t}n|p
||jo||
o|ddjp|
tj	oV|id�oFy�
djo|id�o
t}
n|i|�}|djp|o
|id	j}|djp|o
|id
j}t	||	d||
||�}|o?|i|d�}|o!|i
dot||�}q�nWn+tj
o}|i
|�d}qZnX|	d7}	|
ot}
d|||ffVq�nT||joh|id
�oXt||�}|	d7}	|
o&t}
dd|d||ffVn|i|�n�|id�o�ti|�}|o�|idd�\}}|pHt}t||�\}}d|fVx|D]}|||i<q6Wn|i|�}|o |idjo|}t}q�nt}n|id�oX|i�}|id�p|i|�qZnt}t}
t|�}t|�}n�|id�o�|i�}|id�p|i|�qZn|i�}|i|�|id�p|i|�qZnt}t}
t|�}t|�}n|ot}
|}d}	qZqZW|o?|i�od|fVq
ttd�||if��n|	djo|o|o
t�ndS(s�Read 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.

    If textmode is True, input line-endings are normalized to LF.
    Riis\ R�t@s***************s	/dev/nullRsRritfilesGIT binary patchsa/sb/s
diff --gittgitRpRqs---s+++s***smalformed patch %s %sN(sCOPYsDELETEsRENAMEsADD(R-R8R�R6R�R.R�R,RgR�RfR�RR2R�RbRuRvRwRRR�R�R�RR�R(RFR�t
sourcefileR�tchangedtcurrent_hunkRRtstatethunknumtemitfileRtBFILER�R|RtgitworkdonetnewfileRtgpatchR�R�terrR[R~R}tl2tl3((s"/sys/lib/python/mercurial/patch.pyt	iterhunksVs�


-
##


 





csVd}d}d
�d
}	titi��}
|d
j	}�fd�}x�||||�D]�\}
}|
djoe�pq^n|}�i||�}|djo.|i�id
�|djo
d}q�q2q^|
djo�||�7}|\}}}y]|ot	|||
d|��n7t
|||||�\�}t	|�|
||��Wq2tj
o9}|it
|�d�d\�}|d7}q^q2Xq^|
djo^|}	ti�}xb|	D]=}|idjot|i|i|�n|||i<q�Wq^titd�|
��q^W||�7}|odSn|S(s�
    Reads a patch from fp and tries to apply it.

    The dict 'changed' is filled in with all of the filenames changed
    by the patch. Returns 0 for a clean patch, -1 if any rejects were
    found and 1 if there was any fuzz.

    If 'eol' is None, the patch content and patched file are read in
    binary mode. Otherwise, line endings are ignored when patching then
    normalized to 'eol' (usually '
' or 
').
    ics&�pdSn�i�t�i�S(Ni(RCR�R�((tcurrent_file(s"/sys/lib/python/mercurial/patch.pyt	closefile�s
R�iRR�s
RRpRqsunsupported parser state: %si�N(NN(sCOPYsRENAME(R-RR�R
tgetcwdR)R�R�R�R�RRR�R�RgRReRR
R(RFR�RRRR�R�trejectsR&R~R�R�R+RtvaluesRtretRRt
first_hunkR�tcwdR}((R*s"/sys/lib/python/mercurial/patch.pyt	applydiff�sZ








cs�d|i��fd�}tid�id�d|d�d|d�d|dd�d|dd�d	|d
d	�d|dd�d
|dd|i��S(Ncs-�i|�p|d|p|dd��S(Ntdifft	untrusted(R,R-(R�tnametgetter(R4topts(s"/sys/lib/python/mercurial/patch.pyR,sR�Rtnodatestshowfunct
show_functiontignorewstignore_all_spacetignorewsamounttignore_space_changetignoreblanklinestignore_blank_linesR�tunifiedR6(R-t
configbooltmdifftdiffoptsR,tconfig(RFR7R4R,((R4R7s"/sys/lib/python/mercurial/patch.pyRDs	c
Cs�|pdSng}t�}|i�}|i�}|o=g}|i�D]}	|ti|i||	�qN~}nx�|D]�}	||	}
|
pq�n|
idjo-|i|
i|
i	f�|i
|
i�q�|
idjo|i|
i|
i	f�q�|
idjo|i
|
i	�q�q�Wx$|D]\}}|i||�q8W|o!|o|it
|�t�nx�|D]�}	||	}
|
o�|
io�|
i\}
}|i|
i	�}|
idjoTti	i|�o@|odpd|
odpd}|i|
i	d|�qY|
idjoti||
|�qYq�q�Wti||d	|�|i�}|ig}|D]}||jo||q�q�~�t
|�S(
s=Update dirstate after patch application according to metadataNRqRpRrRsRRR�t
similarity(tsettkeysR,RtpathtotrootRgR?ReRtaddtcopyR�tsortedR6RftwjoinR
Rtwwritet	set_flagstcmdutilt	addremovetextend(RFtrepotpatchesRFtcopiestremovestcfilesR1RR�R}RRRlRmtflagstfilest_[2]R�((s"/sys/lib/python/mercurial/patch.pyt	updatedir%sP	=

$&9c
Cs�t}|o|idti|��ntid|di|�|ti|�f�}x/|D]'}	|	i�}	|i|	d�|	id�o)ti	|	�}
t}|i
|
d�qc|	id�djo=t
}|p|i|
d�t
}n|i|	d�qc|	id�djo|i|	d�qc|	id	�djo7|p|i|
d�t
}n|i|	d�qcqcW|i�}|o'ttd
�ti|�d��n|S(stuse <patcher> to apply <patchname> to the working directory.
    returns whether patch was applied with fuzz factor.s-d %ss%s %s -p%d < %sR!s
spatching file s	with fuzzissaving rejects to filetFAILEDspatch command failed: %sN(R8R?Rt
shellquotetpopenR�RtR�R.tparse_patch_outputR�R-R/R6R�RCRRtexplain_exit(
tpatchertargst	patchnameRFRR1RZR�R�R_tpftprinted_filetcode((s"/sys/lib/python/mercurial/patch.pyt
externalpatchNs>

tstrictc
Cs6|djo|iddd�}ny/hdd<dd<dd<|i�}Wn,tj
o titd�|��nXyt|d	�}Wntj
o
|}nX|ot	i
�}t	i|�nz"t|||d
|d|�}	Wd|ot	i|�nX|	djo
t
�n|	djS(
swuse builtin patch to apply <patchobj> to the working directory.
    returns whether patch was applied with fuzz factor.tpatchR�Ris
tcrlfs
tlfs!Unsupported line endings type: %strbRNi(R-REtlowertKeyErrorRR
Rtopent	TypeErrorR
R,tchdirR2R(
tpatchobjRFRR1RZteolmodeR�R�tcurdirR/((s"/sys/lib/python/mercurial/patch.pyt
internalpatchrs(
/"

c

CsD|idd�}g}y�|o t|||||||�Sn�yt||||||�SWn�tj
o~tid�ptid�pd}|itd�|�ti�o|i	d�nt|||||||�SnXWnPt
j
oD}t|�}	|	oti|	��q@titd���nXdS(s�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.
    RFRjR%s-no valid hunks found; trying with %r instead
s--binaryspatch failed to applyN(
RERhRvRRtfind_exeR2RtneedbinarypatchR?RR�R
(
RdRFRR1RZRtRbRcR&R�((s"/sys/lib/python/mercurial/patch.pyRj�s*&
c	Cs�d�}d�}dd�}||�}||�}||jodSnd||t|�fg}x0|ti|��D]}|i||��q}W|id�di|�S(s print base85-encoded binary diffcSsI|pddSnt|�}tid|�}|i|�|i�S(Nt0i(sblob %d(R�Rtsha1tupdatet	hexdigest(R�R�R�((s"/sys/lib/python/mercurial/patch.pytgitindex�s
cSsot|�}|djottd�|d�}nt|dtd�d�}d|ti|t�fS(NiR�iR�s%c%s
(R�tchrR�R�t	b85encodeR6(R_R�((s"/sys/lib/python/mercurial/patch.pytfmtline�s

i4cssEt|�}d}x,||jo||||!V||7}qWdS(Ni(R�(R�tcsizeR�R�((s"/sys/lib/python/mercurial/patch.pytchunk�s
Rs)index %s..%s
GIT binary patch
literal %s
s
(R�R�tcompressR?R�(	ttottnR}R�R�ttohashttnhashR/R�((s"/sys/lib/python/mercurial/patch.pytb85diff�s		

cCs7||jo&|id|�|id|�ndS(Nsold mode %s
snew mode %s
(R?(theadertomodetnmode((s"/sys/lib/python/mercurial/patch.pyt_addmodehdr�s
c%cs|djo
ti}n|p|ii�d}nd�}|�}||}||}	|p|i||	d|�}n|d \}
}}|
o|o|odSnti|i��}
|i	�}|i
io
d}nS|i
iot
pt}g}||gD]}|o|||�qq~}|ioYti|||	|t�\}}|i�}x(|i�D]\}}|||<q�Wnt�}hdd<dd	<d
d<}x:t|
||�D]$}d}d}t}g}||jo|||�i�}n||jo|||	�i�}n||}}|io�|jo�|	i|�} ||jo�||}||i|�}!t||!| �||jo$||jod}"|i|�nd
}"|id|"|f�|id|"|f�|||�i�}n|id| �ti|�o
d}q4n�||jo_||jo0|||jo||||jo
t}q4|id||i|��na||i|�}!||	i|�}#t||!|#�ti|�pti|�o
d}nd}|idti||||��n|o�|djot ||�}$n7ti!||
|ti|	i��|||d|�}$|o,|$pt"|�djodi#|�Vn|$o	|$Vqq�q�dS(s�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.ics"h�g���fd�}|S(Ncs�|i|d�i|��}|�jo8t��djo��id�=n|i�|<n�i|��i|�|S(Ntfilelogii(tfilectxR,R�REt_filelogR�R?(R�tctxtfctx(tcachetorder(s"/sys/lib/python/mercurial/patch.pyt
getfilectx�s


((R�((R�R�s"/sys/lib/python/mercurial/patch.pyt
lrugetfilectx�s
RviNt120000R�t100755Rt100644RtrenameRLs%s from %s
s	%s to %s
snew file mode %s
Risdeleted file mode %s
R7i($R-RCtdefaultoptstdirstateRStstatusRtdatestrRPtmanifestRFtquiett	debugflagRRRRVRRLtitemsRGRMR6tdataRYR�RKR?RiR8R�tdifflineR�tunidiffR�R�(%RTtnode1tnode2RvtchangesR7R�R�tctx1tctx2tmodifiedtaddedtremovedtdate1tman1R�thexfuncRtnodeRLtdivergetktvtgonetgitmodeR�R�R�tdodiffR�R�R�RfR�RgR�R�((s"/sys/lib/python/mercurial/patch.pyR3�s�

		



8
"
	!







3
	 
&
!shg-%h.patchc
s�t|��tg}|D]}|tt|��q~��������fd�}x.t|�D] \}	}|||	d|�qjWdS(s export changesets as hg patches.cs�|}|i�}g}|i�D]}|o||i�q'q'~}|i�}�o|i�n|o|dpt}	|p1ti��|d�d|d�dd�}n|tijo+t	|d�o�i
id|i�n|i
d	�|i
d
|i��|i
d|i��|o"|djo|i
d
|�n|i
dt|��|i
dt|	��t|�djo|i
dt|d��n|i
|i�i��|i
d�x-t�|	|d��D]}
|i
|
�q�S(NittotaltseqnotrevwidthRftabR5s%s
s# HG changeset patch
s
# User %s
s
# Date %d %d
tdefaults# Branch %s
s
# Node ID %s
s
# Parent  %s
is

R7(R�RSRRR�RRQt	make_filetsyststdoutthasattrRFR�R5R@RNRPRR�tdescriptionRtR3(trevR�R�R�R�RtpRSRRtprevR�(R�R�t
switch_parentttemplateRTR7(s"/sys/lib/python/mercurial/patch.pytsingleUs6
8
 

iN(R�R�R�R�(
RTtrevsR�R�R�R7RR�R�R�((RTR�R�R�R7R�s"/sys/lib/python/mercurial/patch.pytexportNs3
ccsd\}}}x�D]�}|id�ok|o|||fVnd\}}|id�oti|�id�}q�idd�d}q|id�o|id�o|d7}q|id	�o|id
�o|d7}qqW|o|||fVndS(
NiR3s
diff --gitiii�R�s+++R�s---(Nii(ii(R-R.RuR7Rwtsplit(R�tfilenametaddsRWR_((s"/sys/lib/python/mercurial/patch.pytdiffstatdataws !!iPcsrg}tt|��}d
\�}d\}}xS|D]K\}}}	||7}||	7}t|t|��}t�||	��q7Wtt���}
||
|d��djo
d�n��fd�}x^|D]V\}}}	d||�}d||	�}
|id|||
||	||
f�q�W|o*|itd�t|�||f�nd	i|�S(Niii
cs6��jo|Snt|��tt|���S(N(R�Rztbool(R�(tmaxtotalt
graphwidth(s"/sys/lib/python/mercurial/patch.pytscale�s
R�R�s %-*s |  %*.d %s%s
s5 %d files changed, %d insertions(+), %d deletions(-)
R(ii(ii(R�R�R�R�R�R?RR�(R�twidthtoutputtstatstmaxnamet	totaladdsttotalremovesR�R�RWt
countwidthR�tplusestminuses((R�R�s"/sys/lib/python/mercurial/patch.pytdiffstat�s2



iii(;ti18nRR�RRRR�RQRCRR�RVR:temail.ParserR)R
R#R�R&R�R$Rut	ExceptionRRRRbRyRxR{tobjectRcR�R�R�R�R�R�R�R�R�R�RRR-R8R)R2RDR\RhRvRjR�R�R3R�R�R�(((s"/sys/lib/python/mercurial/patch.pys<module>	sPH0$		f	;��!	
	?	~	B)	$$	&	r	(	

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.