��c@sdZddlZddlZddlZddlZddlmZmZmZ m
Z
mZddlm
Z
dZedZdZdd �Zd
�Zd�Zd�Zd
�Zdejfd��YZed�Zd�Zddd�Zd�Zd�Zd�Zed�Z d�Z!d�Z"d�Z#gid�Z$d�Z%d�Z&d�Z'd�Z(d�Z)dd �Z*d!�Z+d"�Z,d#�Z-d$�Z.d%�Z/d&�Z0d'�Z1d(�Z2d)�Z3d*�Z4d+e5fd,��YZ6d-�Z7d.�Z8dS(/sGlargefiles utility code: must not import other modules in this package.i�N(tdirstatethttpconnectiontmatchtutiltscmutil(t_s.hglft/t
largefilesi
cCs�|}|r.|r.|jtdd|�}n|rtyt|�}Wqttk
rptjtd�|��qtXn|dkr�tjtd���n|S(Ntminsizetdefaults)largefiles: size must be number (not %s)
s-minimum size for largefiles must be specified(tconfigtlongnametfloatt
ValueErrorRtAbortRtNone(tuitassumelfilestoptR tlfsize((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyt
getminsizes
cCs�tjtjj|��ytj||�Wnvtk
r�tj|�}x-tjt |d��D]}|j
|�qeW|j�tj|tj
|�j�nXdS(Ntrb(RtmakedirstostpathtdirnametoslinktOSErrortatomictempfilet
filechunkitertopentwritetclosetchmodtstattst_mode(tsrctdesttdsttchunk((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pytlink(s
cCsa|jtdd�}|r3tjj||�}n*tjdkr�tjdtjd��}|r]tjj|t|�}q]n�tj �dkr�tjd�}|r]tjj|ddt|�}q]n�tjd krAtjd
�}|rtjj|t|�}q]tjd�}|r]tjj|dt|�}q]nt
jtd�tj��|S(
Nt usercachetnttLOCALAPPDATAtAPPDATAtDarwintHOMEtLibrarytCachestposixtXDG_CACHE_HOMEs.cachesunknown operating system: %s
(
t
configpathRRRRtjointnametgetenvtplatformtsystemRRR(RthashRtappdatathome((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyt
usercachepath4s*!cCs%t||�}|o$tjj|�S(N(R<RRtexists(RR9R((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pytinusercacheNscCs�t||�r6|jjtd�|�t||�St|j|�r�|jjtd�|�t||�}tt|j|�|�|SdS(Nsfound %s in store
sfound %s in system cache
( tinstoreRtnoteRt storepathR>R(R<R(trepoR9R((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pytfindfileRs
tlargefilesdirstatecBsPeZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z RS(cCstt|�jt|��S(N(tsuperRDt__getitem__tunixpath(tselftkey((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyRF^scCstt|�jt|��S(N(RERDtnormalRG(RHtf((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyRJ`scCstt|�jt|��S(N(RERDtremoveRG(RHRK((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyRLbscCstt|�jt|��S(N(RERDtaddRG(RHRK((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyRMdscCstt|�jt|��S(N(RERDtdropRG(RHRK((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyRNfscCstt|�jt|��S(N(RERDtforgetRG(RHRK((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyROhscCstt|�jt|��S(N(RERDtnormallookupRG(RHRK((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyRPjscCstS(N(tFalse(RH((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyt_ignorels(
t__name__t
__module__RFRJRLRMRNRORPRR(((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyRD]s c Cs�|jt�}tj|�}t|||j|jj�}|r�tj j
tj j|d��r�tj|�t
|�}x?|jj|gtt�D]}t|�}|j|�q�Wn|S(s�
Return a dirstate object that tracks largefiles: i.e. its root is
the repo root, but it is saved in .hg/largefiles/dirstate.
R(R4RRtopenerRDtrootRt _validateRRR=RRtgetstandinmatchertwalkRQtsplitstandinRP( RRBtcreatet
lfstoredirRUt
lfdirstatetmatchertstandintlfile((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pytopenlfdirstateos(
"cCstj|j|j��}|j|gttt�}|\}}}}} }
}}x�|D]�}
y||t|
�}Wntk
r�d}nX|s�|j �j
�t|j|
��kr�|j
|
�q[|j
|
�|j|
�q[W|||| |
||fS(N(tmatch_talwaysRVtgetcwdtstatusRQR_tLookupErrorRtdatatstripthashfiletwjointappendRJ(R]RBtrevRtstunsuretmodifiedtaddedtremovedtmissingtunknowntignoredtcleanR`tfctx((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pytlfdirstatestatus�s
.
cCsd|dkrt|�}ng||j|�D]1}|dk sT|j|dkr/t|�^q/S(sNreturn a list of largefiles in the working copy or the
specified changesett?N(RRXRYRRZ(RBRlR^RK((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyt
listlfiles�s
cCstjjt||��S(N(RRR=RA(RBR9((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyR?�scCs|jtjjt|��S(N(R4RRR(RBR9((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyRA�scCs^t||�}|dkrtStjtjj|j|���t j
||j|��tS(s.Copy the specified largefile from the repo or system cache to
filename in the repository. Return true on success or false if the
file was not found in either cache (which should not happened:
this is meant to be called only after ensuring that the needed
largefile exists in the cache).N(RCRRQRRRRRRjtshutiltcopytTrue(RBR9tfilenameR((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyt
copyfromcache�s"cCsBt|||�}t||�r%dSt||j|�|�dS(N(treadstandinR?tcopytostoreabsoluteRj(RBRltfiletuploadedR9((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pytcopytostore�scCsh||}xW|j�D]I}t|�r||j�krt|�}t||j�|�qqWdS(s4Copy all largefiles in a given revision to the storeN(tfilest isstandintmanifestRZR�tnode(RBR�tctxR}trealfile((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pytcopyalltostore�s
cCs�t|j|�r7tt|j|�t||��n�t|dt�s�tjt j
jt||���tjt||�d|j
j�}x-tjt|d��D]}|j|�q�W|j�t||�ndS(Nt
_isconvertingt
createmodeR(R>RR(R<RAtgetattrRQRRRRRRtstoreR�RRRR tlinktousercache(RBR�R9R&R'((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyR��s%"
cCs5t|j|�}|r1tt||�|�ndS(N(R<RR(RA(RBR9R((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyR��scCsr|jt�}|r@g|D]}tjj||�^q}n |g}tj|d||�}d�|_|S(s@Return a match object that applies pats to the standin directorycSsdS(N(R(RKtmsg((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyt<lambda>�sN( Rjt shortnameRRR4RRRtbad(RBtpatstoptst
standindirtpatR((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyRX�s+ cs=t|�j��}|j���fd�}||_|S(s�Return a matcher that accepts standins corresponding to the
files accepted by rmatcher. Pass the list of files in the matcher
as the paths specified by the user.cs�|�o�jt|��S(N(tmatchfnRZ(RK(R�trmatcher(s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pytcomposedmatchfn�s(RXR�R�(RBR�tsmatcherR�((R�R�s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pytcomposestandinmatcher�s
cCsttj|�S(sLReturn the repo-relative path to the standin for the specified big
file.(tshortnameslashRtpconvert(R}((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyR_�s
cCs
|jt�S(ssReturn true if filename is a big file standin. filename must be
in Mercurial's internal form (slash-separated).(t
startswithR�(R}((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyR��scCsMtj|�jdd�}t|�dkrE|dtkrE|dSdSdS(NRiii(RR�tsplittlenR�R(R}tbits((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyRZs"cCsY|jt|��}tjj|�rUt|�}t|�}t||||�ndS(N(RjRZRRR=Rit
getexecutabletwritestandin(RBR_R�R9t
executable((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyt
updatestandin
s
cCs||t|�j�j�S(scread hex hash from standin for filename at given node, or working
directory if no node is given(R_RgRh(RBR}R�((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyRscCs'|j||d|rdpd�dS(s#write hash to <repo.root>/<standin>s
txtN(twwrite(RBR_R9R�((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyR�scCsDtjd�}x(|D] }|j|�|j|�qW|j�S(s�Read bytes from instream (iterable) and write them to outfile,
computing the SHA-1 hash of the data along the way. Return the hash.R�(Rtsha1tupdateRt hexdigest(tinstreamtoutfilethasherRg((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pytcopyandhashs
cCst|j|��S(N(RiRj(RBR�((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pythashrepofile#scCsrtjj|�sdStjd�}t|d�}x'tj|d�D]}|j|�qGW|j�|j �S(NR�Ri�ii(
RRR=RR�RRR�R R�(R�R�tfdRg((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyRi&s
cCs7tj|�j}|tj@o6|tj@o6|tj@S(N(RR"R#tS_IXUSRtS_IXGRPtS_IXOTH(R}tmode((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyR�0s
cGs<d�}|||�}x|D]}|||�}qW|S(NcSs@|jd�s|d7}n|jd�r8|d}n||S(NRi(tendswithR�(tlefttright((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyR47s
((tfirsttsecondtargR4turlta((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyturljoin6s
cCs=tj�}x$tj|�D]}|j|�qW|j�S(sUhexsha1 returns the hex-encoded sha1 sum of the data in the file-like
object data(RR�RR�R�(RgthR'((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pythexsha1CscCstj||d�S(NR(Rthttpsendfile(RR}((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyR�KscCstjtjj|��S(s@Return a version of path normalized for use with the lfdirstate.(RR�RRtnormpath(R((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyRGNscCsQd|jkr5tjd�|jj�D��r5tStjt|j|t��S(NRcss|]}t|dkVqdS(iN(R�(t.0RK((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pys <genexpr>Ts( trequirementsRtanyR�t datafilesR|RaRRQ(RB((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pytislfilesrepoRs"tstoreprotonotcapablecBseZd�ZRS(cCs
||_dS(N(t
storetypes(RHR�((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyt__init__Zs(RSRTR�(((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyR�YscCs�g}t|�}xo|jj|gtt�D]R}t|�}yt||�}Wntk
rld}nX|j||f�q.W|S(N( RXRRYRQRZRtIOErrorRRk(RBtstandinsR^R_R`R9((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pytgetstandinsstate]s"
cCsZt|�jt|��}g}x2|D]*}|d|kr(|j|d�q(q(W|S(Ni(tsettsymmetric_differenceRk(toldstandinstnewstandinstchangedstandinstfilelistRK((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pytgetlfilestoupdateis
(9t__doc__RR7RzR"t mercurialRRRRbRRtmercurial.i18nRR�R�RRR(R<R>RCRDR|RaRwRRyR?RAR~RQR�R�R�R�RXR�R_R�RZR�RR�R�R�RiR�R�R�R�RGR�t ExceptionR�R�R�(((s;/sys/lib/python2.7/site-packages/hgext/largefiles/lfutil.pyt<module> sZ(
|