
    	^cdp                     Z   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZmZmZmZmZmZmZmZmZ d dlmZmZ ddlmZ  ej        d	          Z  G d
 dej                  Z! G d de!          Z" G d dej#                  Z$ G d d          Z%d Z& G d dej'        j(                  Z) G d d          Z* G d d          Z+ G d d          Z, G d d          Z-e*e*e+e,e-dZ.d Z/d Z0d%d Z1 G d! d"ej2                  Z3 G d# d$ej4                  Z5dS )&    N)_)getattr)hex)	encodingerrorhttpconnectionpathutilpycompaturlutilvfsworker)
stringutilurlutil   )lfutils   \A[a-f0-9]{64}\Zc                   &     e Zd Z fdZddZ xZS )lfsvfsc                     t                               |          st          j        d|z            t	          t
          |                               |dd         |dd                   S )z9split the path at first two characters, like: XX/XXXXX...s   unexpected lfs path: %sr   r   N)_lfsrematchr   ProgrammingErrorsuperr   join)selfpath	__class__s     5/usr/lib/python3/dist-packages/hgext/lfs/blobstore.pyr   zlfsvfs.join-   s_    ||D!! 	L()Cd)JKKKVT""''QqS	48<<<    Nc              #     K   t           j                            | j                  }t	          t          j        |                    }g }t          j        |                     | j        |pd          |          D ]D\  }}|d         t	                    dk    r!|	                    fd|D                        Edg |fV  dS )zYield (dirpath, [], oids) tuple for blobs under path

        Oids only exist in the root of this vfs, so dirpath is always ''.
        r   )onerrorNr   c                 T    g | ]$}t                               |z             |z   %S  )r   r   ).0fdirpaths     r   
<listcomp>zlfsvfs.walk.<locals>.<listcomp>F   s2    MMMQ6<<!3L3LMWq[MMMr   )
osr   normpathbaselenr	   normasprefixwalkreljoinextend)	r   r   r!   root	prefixlenoidsdirsfilesr&   s	           @r   r-   zlfsvfs.walk3   s      
 w	** -d3344	$&GLLDKC00'%
 %
 %
 		 		 GT5 ijj)G 7||q  MMMM%MMM   Bor   NN)__name__
__module____qualname__r   r-   __classcell__r   s   @r   r   r   ,   sL        = = = = =       r   r   c                   .    e Zd Zd Zd Zd ZddZd ZdS )nullvfsc                     d S Nr#   r   s    r   __init__znullvfs.__init__M       r   c                     dS )NFr#   r   oids     r   existsznullvfs.existsP   s    ur   c                 `    t          t          j        t          j        d|z                      )Ns   %s: No such file or directory)IOErrorerrnoENOENTr
   sysstrrC   s     r   readznullvfs.readS   s.    
 LO<sBCC
 
 	
r   Nc                     dg g fS )Nr   r#   )r   r   r!   s      r   r-   znullvfs.walk]   s    R}r   c                     d S r>   r#   )r   rD   datas      r   writeznullvfs.write`   rA   r   r5   )r6   r7   r8   r@   rE   rK   r-   rO   r#   r   r   r<   r<   L   sd            
 
 
       r   r<   c                   (     e Zd ZdZ fdZd Z xZS )lfsuploadfilez+a file-like object that supports keepalive.c                 ~    t          t          |                               ||d           | j        j        | _        d S Ns   rb)r   rQ   r@   _datarK   )r   uifilenamer   s      r   r@   zlfsuploadfile.__init__g   s4    mT""++B%@@@JO			r   c                     d S r>   r#   r?   s    r   _makeprogresszlfsuploadfile._makeprogressk   s    tr   )r6   r7   r8   __doc__r@   rX   r9   r:   s   @r   rQ   rQ   d   sM        55$ $ $ $ $      r   rQ   c                   V    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
dd
Zd Zd Zd ZdS )localzLocal blobstore for large file contents.

    This blobstore is used both as a cache and as a staging area for large blobs
    to be uploaded to the remote blobstore.
    c                 4   |j                             d          }t          |          | _        |j                            dd          rt                      | _        n.t          j	        |j        d          }t          |          | _        |j        | _        d S )Ns   lfs/objects   experimentals   lfs.disableusercache   lfs)
svfsr   r   r   rU   
configboolr<   cachevfsr   _usercachedir)r   repofullpath	usercaches       r   r@   zlocal.__init__v   s|    9>>.11(##7o/FGG 	.#IIDMM,TWf==I"9--DM'r   c                 H    t          |                     |          d          S )zgOpen a read-only file descriptor to the named blob, in either the
        usercache or the local store.rb)openr   rC   s     r   rh   z
local.open   s     DIIcNND)))r   c                     | j                             |          r| j                             |          S | j                            |          S )a{  Build the path for the given blob ``oid``.

        If the blob exists locally, the path may point to either the usercache
        or the local store.  If it doesn't, it will point to the local store.
        This is meant for situations where existing code that isn't LFS aware
        needs to open a blob.  Generally, prefer the ``open`` method on this
        class.
        )ra   rE   r   r   rC   s     r   r   z
local.path   sF     =$$ 	+=%%c***x}}S!!!r   c                 |   t          j                    }d}|                     |dd          5 }t          j        |d          D ]>}|                    |           |                    |           |t          |          z  }?|Ct          |          |k    r0d}t          t          |          |t          |          fz            t          |                                          }	|	|k    rt          t          d	          |z            	 ddd           n# 1 swxY w Y   |                     |           dS )
znRead the blob from the remote source in chunks, verify the content,
        and write to this local blobstore.r      wbT
atomictemp   sizeNsX   Response length (%d) does not match Content-Length header (%d): likely server-side crashs   corrupt remote lfs object: %s)hashlibsha256r   r   filechunkiterrO   updater+   intLfsRemoteErrorr   r   digestLfsCorruptionError_linktousercache)
r   rD   srccontent_lengthrr   rp   fpchunkmsgrealoids
             r   downloadzlocal.download   s    !!XXc5TX22 	b+Cg>>> # #e$$$E

" )c..A.AT.I.I=  %QsVVtS5H5H.I%IJJJ&--//**G#~~(677#=   '	 	 	 	 	 	 	 	 	 	 	 	 	 	 	0 	c"""""s   C!DD #D c                     |                      |dd          5 }|                    |           ddd           n# 1 swxY w Y   |                     |           dS )zWrite blob to local blobstore.

        This should only be called from the filelog during a commit or similar.
        As such, there is no need to verify the data.  Imports from a remote
        store must use ``download()`` instead.rk   Trl   N)r   rO   ry   )r   rD   rN   r|   s       r   rO   zlocal.write   s     XXc5TX22 	bHHTNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	c"""""s   ;??c                 T   t          | j        t                    s| j                            |          ss| j                            t          d          |z             t          j	        | j        
                    |          | j        
                    |                     dS dS dS )a  Link blobs found in the user cache into this store.

        The server module needs to do this when it lets the client know not to
        upload the blob, to ensure it is always available in this store.
        Normally this is done implicitly when the client reads or writes the
        blob, but that doesn't happen when the server tells the client that it
        already has the blob.
           lfs: found %s in the usercache
N)
isinstancera   r<   r   rE   rU   noter   r   linkr   rC   s     r   linkfromusercachezlocal.linkfromusercache   s     $-11 	E$(//#:N:N 	EGLL>??#EFFFK**3//s1C1CDDDDD	E 	E 	E 	Er   c                 T   | j                             |          st          | j         t                    ss| j                            t          d          |z             t          j        | j	        
                    |          | j         
                    |                     d S d S d S )Ns    lfs: adding %s to the usercache
)ra   rE   r   r<   rU   r   r   r   r   r   r   rC   s     r   ry   zlocal._linktousercache   s     }##C(( 	EM72
 2
 	E GLL?@@3FGGGKc**DM,>,>s,C,CDDDDD		E 	E 	E 	Er   Tc                 P   | j                             |          s|                     | j        ||          }|s7t	          t          j        |                                                    |k    ro| j        	                    t          d          |z             t          j        | j                            |          | j                             |                     nF| j        	                    t          d          |z             |                     | j         ||          }|S )zRead blob from local blobstore.r   s%   lfs: found %s in the local lfs store
)r   rE   _readra   r   rq   rr   rw   rU   r   r   r   r   r   )r   rD   verifyblobs       r   rK   z
local.read   s    xs## 	5::dmS&99D  IW^D1188::;;sBBQBCCcIJJJDM..s33TX]]35G5GHHHGLLDEEKLLL::dhV44Dr   c                 T    |                     |          }|rt          ||           |S )z0Read blob (after verifying) from the given store)rK   _verify)r   r   rD   r   r   s        r   r   zlocal._read   s.    xx}} 	Cr   c                 *   t          j                    }|                     |          5 }t          j        |d          D ]}|                    |           	 ddd           n# 1 swxY w Y   |t          |                                          k    S )zQIndicate whether or not the hash of the underlying file matches its
        name.rn   ro   N)rq   rr   rh   r   rs   rt   r   rw   )r   rD   rr   r|   r}   s        r   r   zlocal.verify   s     !!YYs^^ 	%r+BW=== % %e$$$$%	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% c&--//****s   /A%%A),A)c                 j    | j                             |          p| j                            |          S )zYReturns True if the local blobstore contains the requested blob,
        False otherwise.)ra   rE   r   rC   s     r   hasz	local.has   s-     }##C((@DHOOC,@,@@r   N)T)r6   r7   r8   rY   r@   rh   r   r   rO   r   ry   rK   r   r   r   r#   r   r   r[   r[   o   s         	 	 	* * *
" " "(# # #@	# 	# 	#E E EE E E   $  	+ 	+ 	+A A A A Ar   r[   c                    | }t          | j        t                    r| j        }t          j        |d          r]	 |j        j        d         }n# t          t          f$ r
 |j        }Y nw xY wt          |t                    rt          j
        |          }|S t          |dd          rt          j        |j                  S t          j        |           S )zbCreate a friendly message for the given URLError to be used in an
    LfsRemoteError message.
    s   reason   strerrorN)r   reason	Exceptionr   safehasattrargsAttributeError
IndexErrorstrr   
unitolocalr   
strtolocalr   r   forcebytestr)urlerrorinstr   s      r   _urlerrorreasonr     s     D(/9-- i(( 1	![%a(FF
+ 	! 	! 	![FFF	! fc"" 	1(00F	z4	(	( 1"4=111&x000s   A A('A(c                       e Zd ZdZd ZdS )lfsauthhandleri  c                 F   |                     dd          }|r|                                d         }|                                dk    rVt          d          }t          j                            |                                |t          j	        |          ||          dS )zEnforces that any authentication performed is HTTP Basic
        Authentication.  No authentication is also acceptable.
        zwww-authenticateNr   basics,   the server must support Basic Authentication)
getsplitlowerr   r   urlerr	httperrorget_full_urlr   strfromlocal)r   reqr|   coder~   headersauthreqschemes           r   http_error_401zlfsauthhandler.http_error_401!  s     ++0$77 	]]__Q'F||~~((GHHk++$$&&)#..   tr   N)r6   r7   r8   handler_orderr   r#   r   r   r   r     s(        M    r   r   c                   D    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )_gitlfsremotec                    |j         }|| _         |                                \  }}|                    d          | _        |j                             dd          }|sdt          j                    z  }t          j        |||          | _	        | j	        
                    t                                 |                    dd          | _        d S )N   /r]   s   lfs.user-agents   git-lfs/2.3.4 (Mercurial %s)r^   s   retry)rU   authinforstripbaseurlconfigr   versionurlmodopener	urlopeneradd_handlerr   	configintretry)r   rc   r   rU   r   r   	useragents          r   r@   z_gitlfsremote.__init__6  s    WLLNN~~d++GNN?4EFF	 	I7$,..HIr8Y??"">#3#3444\\&(33


r   c                 N    |                      t          |          |d           dS )z,Batch upload from local to remote blobstore.   uploadN_batch_deduplicater   pointers	fromstores      r   
writebatchz_gitlfsremote.writebatchB  s&    L**IyAAAAAr   c                 N    |                      t          |          |d           dS )z-Batch download from remote to local blostore.   downloadNr   r   r   tostores      r   	readbatchz_gitlfsremote.readbatchF  s&    L**G[AAAAAr   c                 :   d |D             }t          j        t          j        |t          j        |          d                    }d| j        z  }t          j                            t          j        |          |          }|	                    dd           |	                    dd           	 t          j        | j                            |                    5 }|                                }ddd           n# 1 swxY w Y   n	# t          j        j        $ r}	t#          d	          | j        |fz  t#          d
          | j        z  d}
|
                    |	j        t#          d          ||fz            }t)          t#          d          t+          j        |	          z  |          d}	~	wt          j        j        $ rJ}	t#          d
          | j        z  }t)          t#          d          t1          |	          z  |          d}	~	ww xY w	 t          j        |          }n@# t4          $ r3 t)          t#          d          |                    d          z            w xY w| j        j        r| j                            d|j        z             t          j         |!                                          "                                }| j                            dd#                    tI          |%                                                    z             d|v rtI          |d         d           |d<   | j                            dt          j        t          j        |ddd                    z             d }t          j&        ||          S )zGet metadata about objects pointed by pointers for given action

        Return decoded JSON object like {'objects': [{'oid': '', 'size': 1}]}
        See https://github.com/git-lfs/git-lfs/blob/master/docs/api/batch.md
        c                     g | ]=}t          j        |                                          |                                d >S ))rD   rp   )r
   strurlrD   rp   r$   ps     r   r'   z/_gitlfsremote._batchrequest.<locals>.<listcomp>P  sJ     
 
 
 OAEEGG,,affhh??
 
 
r   )objects	operations   %s/objects/batch)rN   Acceptzapplication/vnd.git-lfs+jsonContent-TypeNs=   check that lfs serving is enabled on %s and "%s" is supporteds/   the "lfs.url" config may be used to override %s)i    s   api=%s, action=%ss   LFS HTTP error: %shint   LFS error: %ss#   LFS server returns invalid JSON: %sutf-8   Status: %d
   %s
   
r   c                     | d         S )NrD   r#   )r   s    r   <lambda>z-_gitlfsremote._batchrequest.<locals>.<lambda>  s
    qx r   keyr   ) z: T)indent
separators	sort_keysc                 Z    t          | t                    r|                     d          S | S )Nr   )r   r   encode)xs    r   	encodestrz._gitlfsremote._batchrequest.<locals>.encodestr  s+    !S!! )xx(((Hr   )'r
   bytesurljsondumpsr   r   r   urlreqrequest
add_header
contextlibclosingr   rh   rK   r   r   r   r   r   rv   r   r   r   r   
json_loads
ValueErrorr   rU   	debugflagdebugstatusbytestrinfostripr   sorted
splitlinesrapply)r   r   actionr   requestdatar   batchreqrsprawjsonexhintsr   responser   r   s                  r   _batchrequestz_gitlfsremote._batchrequestJ  s   
 

 
 
 'J&!)!8!8  
 
 "DL0;&&xs';';+&NNH&DEEEN,JKKK	#DN$7$7$A$ABB %c((**% % % % % % % % % % % % % % %{$ 	 	 	!  <(	)
 IJJ, E 99RWa(<&=&=f&MNND '((:+B2+F+FF    {# 	 	 	DEE,  !"##ob&9&99   		*733HH 	 	 	 899..))*  	 7 	GMM/CJ6777&sxxzz2288::GGMM'EJJvg6H6H6J6J/K/K$L$LLMMMH$$&,Y'-?-?' ' '# GMM#J  #-"&	   
 
 
	 	 	
 y(333sV   2,D C?3D ?DD DD H BF11HAHHH+ +=I(c                    |D ]}d|vr"|dk    r||                     dg           vrd}n*(|                     d                               dd          }d |D             }|                     |d         d	          }|rRt          |d
d          }ddddd}	|	                     |d|z            }
t          t          d          ||
fz            t          t          d          |d         z            d	S )zUScans errors from objects

        Raises LfsRemoteError if any objects have an errors   errorr      actionsr   s   code  c                 8    i | ]}|                                 |S r#   )rD   r   s     r   
<dictcomp>z6_gitlfsremote._checkforservererror.<locals>.<dictcomp>  s"    333Qaeeggq333r      oidNrV   s   unknowns   The object does not exists#   The object was removed by the owners   Validation errors   Internal server error)r   i  i  r  s   status code %ds   LFS server error for "%s": %ss1   LFS server error. Unsolicited response for oid %s)r   r   rv   r   )r   r   	responsesr  r	  r   ptrmapr   rV   errorsr~   s              r   _checkforservererrorz"_gitlfsremote._checkforservererror  sQ    " #	 #	H
 x''[((V8<<< < . . DD  ||H--11'3??33(333F

8F+T22A "1j*==5?,1	  jj'84'?@@$6778S/I   %JKKv&'  A#	 #	r   c                 ~    |                     dg           }|                     ||           fd|D             }|S )zextract objects from response of the batch API

        response: parsed JSON object returned by batch API
        return response['objects'] filtered by action
        raise if any object has an error
        s   objectsc                 D    g | ]}|                     d g           v |S )r  r   )r$   or  s     r   r'   z1_gitlfsremote._extractobjects.<locals>.<listcomp>  s8     
 
 
&AEE*b,A,A"A"AA"A"A"Ar   )r   r  )r   r	  r   r  r   filteredobjectss      `  r   _extractobjectsz_gitlfsremote._extractobjects  s`     ,,z2..!!(GV<<<
 
 
 

 
 
 r   c           
      	   |d         }|d         |                              d          }|d         |                              di                                           }t          j                            t          j        |                    }|dk    rH|                    |          s3t          j	        t          d          |z  t          d                    |D ]?\  }}	|                    t          j        |          t          j        |	                     @	 |dk    rkt          | j        |                    |                    |_        d	 |_        |                    d
d           |                    d|j        j                   t%          j        | j                            |                    5 }
|
                                                     d          }| j        }| j        j        r|                    d|
j        z             t          j        |
                                                                          }|                    dd                    t;          |                                                    z             |dk    r|                    ||
|           nbg }	 |
                     d          }|sn|!                    |           .d                    |          }|r|                    d||fz             ddd           n# 1 swxY w Y   n# t          j"        j#        $ rv}| j        j        r1| j                            d||                                 fz             tI          t          d          tK          j&        |          ||fz            d}~wt          j"        j'        $ rt}t          d          t          j(        t          j)        *                    |                    z  }tI          t          d          tW          |          z  |          d}~ww xY w|j        r|j        ,                                 dS dS # |j        r|j        ,                                 w w xY w)aC  Download or upload a single object using basic transfer protocol

        obj: dict, an object description returned by batch API
        action: string, one of ['upload', 'download']
        localstore: blobstore.local

        See https://github.com/git-lfs/git-lfs/blob/master/docs/api/        basic-transfers.md
        r  r  s   hrefs   headerr      detected corrupt lfs object: %s   run hg verifyr   c                      dS )NPUTr#   r#   r   r   r   z._gitlfsremote._basictransfer.<locals>.<lambda>  s    U r   r   zapplication/octet-streamzContent-Lengths   content-lengthr   r   r   r   Trn   r   s   lfs %s response: %sNs   %s: %s
s&   LFS HTTP error: %s (oid=%s, action=%s)s   attempted connection to %sr   )-r   itemsr   r   r   r
   r   r   r   Abortr   r   rQ   rU   r   rN   
get_methodlengthr   r   r   rh   r   r   r   r   r   r   r   r   r   r   rK   appendr   r   rv   r   r   r   r   urllibcompat
getfullurlr   close)r   objr  
localstorerD   hrefr   r   kvrescontentlengthrU   blocksrN   r	  r  r   s                     r   _basictransferz_gitlfsremote._basictransfer  s    &k:v&**733j/&)--i<<BBDD+%%hod&;&;<<Y$$S)) k899C?+,,   
  	G 	GDAqxq118?13E3EFFFF2	%"",TWjooc6J6JKK%2]""">3MNNN""#3W\5HIII#DN$7$7$@$@AA NS #

/@ A AW7$ QHH_sz9::: '.sxxzz::@@BBGHHWuzz&9K9K9M9M2N2N'O'OOPPP[(( ''S-@@@@F,"xx00# "!d+++	,  #xx//H N!768:L!LMMM1N N N N N N N N N N N N N N N2 {$ 	 	 	w  3		"22   !;<<*2..V<=   {# 	 	 	233h6G!,,W557 7 D !"##ob&9&99   		 | %""$$$$$% %w| %""$$$$%s^    BL0 =EL#L0 #L''L0 *L'+L0 .Q' 0Q A1N55Q A/P;;Q  Q' '#R
c           
          dvrt          j        dz                                 |          }                     ||          }t	          d |D                       }i }|D ].}|                    dd          ||                    d          <   /t          d          t          d          d         }	t          |          d	k    rK j        	                    t          d
          t          |          t          j        |          fz              fd}
 j                            dd          r5 fd}t          j         j        d|
dt          |d           |          }n |
t          |d                     } j                            |	t          d          |          5 }|                    d           d}d}|D ]T\  }}|||         z  }|d	z  }|                    |            j        	                    t          d          |z             U	 d d d            n# 1 swxY w Y   |dk    rdk    r@ j                            t          d          |t          j        |          fz             d S dk    rB j                            t          d          |t          j        |          fz             d S d S d S )N)r   r   s   invalid Git-LFS action: %sc              3   B   K   | ]}|                     d d          V  dS )   sizer   Nr  )r$   r   s     r   	<genexpr>z'_gitlfsremote._batch.<locals>.<genexpr>/  s0      77!AEE'1%%777777r   r3  r   r  s   lfs uploadings   lfs downloadingr   s&   lfs: need to transfer %d objects (%s)
c              3   |  K   | D ]4}|                     dd          }j        j        rodk    rt          d          }ndk    rt          d          }j                            ||                     d          t          j        |          fz             j        }	 	                     |           d	|                     d          fV  nf# t          j
        $ rT}|dk    rHj                            t          d
          t          j        |          |fz             |d	z  }Y d }~ d }~ww xY w6d S )Nr3  r   r   s   lfs: downloading %s (%s)
r   s   lfs: uploading %s (%s)
r  Tr   s%   lfs: failed: %r (remaining retry %d)
)r   rU   verboser   r   r   	bytecountr   r0  socketr   r   r   )	r}   r(  objsizer~   r   r  r  r)  r   s	         r   transferz&_gitlfsremote._batch.<locals>.transfer=  sz       '''1--7? ,, =>>9,, ;<<GLLswwvw0G0GHH   
++CDDD0000!<    199 GLL !"K L L#-#:2#>#>"F!G   "QJE$HHHH  s   #0CD7#A	D21D22D7r]   s   lfs.worker-enablec                  Z    j         j        D ]}  t          | dd                        d S )N	close_allc                      d S r>   r#   r#   r   r   r   z7_gitlfsremote._batch.<locals>.prefork.<locals>.<lambda>g  s    D r   )r   handlersr   )hr   s    r   preforkz%_gitlfsremote._batch.<locals>.preforke  s@    0 < <A9GA{LL99;;;;< <r   g?r#   c                 ,    |                      d          S Nr  r  r  s    r   r   z&_gitlfsremote._batch.<locals>.<lambda>n  s    aeeFmm r   r   )r@  c                 ,    |                      d          S rB  r  rC  s    r   r   z&_gitlfsremote._batch.<locals>.<lambda>r  s    !%%-- r   s   bytes)unittotals   lfs: processed: %s
r   s   lfs: uploaded %d files (%s)
r   s   lfs: downloaded %d files (%s)
)r   r   r
  r  sumr   r   r+   rU   r   r   r7  r`   r   r   makeprogressrt   r   )r   r   r)  r  r	  r   rF  sizesr(  topicr:  r@  r2   progress	processedblobs_onerD   s   ` ``              r   r   z_gitlfsremote._batch)  s   111()F)OPPP%%h77&&x6BB77w77777 	9 	9C%(WWWa%8%8E#''&//"")**-..
 
  w<<!GLL<==w<<!6!678  
	 	 	 	 	 	 	< 7o/CDD 	J< < < < < =w$;$;<<<  DD 8F70G0GHHHIIDW!!(5 " 
 
 
	?OOAIE! ? ?	cU3Z'	
	***Q677#=>>>>	?
	? 
	? 
	? 
	? 
	? 
	? 
	? 
	? 
	? 
	? 
	? 
	? 
	? 
	? 
	? 199""677dnY7789     ;&&899dnY7789     9 '&s   7A1H55H9<H9c                     t          | dd           }|r8|j        D ]2}|                                  t          |dd                        1d S d S )Nr   r<  c                      d S r>   r#   r#   r   r   r   z'_gitlfsremote.__del__.<locals>.<lambda>  s     r   )r   r>  r'  )r   r   r?  s      r   __del__z_gitlfsremote.__del__  sm    D+t44	 	8' 8 8			5;557777	8 	88 8r   N)r6   r7   r8   r@   r   r   r
  r  r  r0  r   rQ  r#   r   r   r   r   5  s        
4 
4 
4B B BB B BS4 S4 S4j' ' 'R  &L% L% L%\a a aF8 8 8 8 8r   r   c                   $    e Zd ZdZd Zd Zd ZdS )_dummyremotez,Dummy store storing blobs to temp directory.c                 n    |j                             d|j                  }t          |          | _         d S )Nr^   )r   r   r   r   )r   rc   r   rd   s       r   r@   z_dummyremote.__init__  s,    8==22(##r   c                 *   t          |          D ]}|                    |                                d          }|                     |                                dd          5 }|                    |           d d d            n# 1 swxY w Y   d S )NT)r   rk   rl   )r   rK   rD   r   rO   )r   r   r   r   contentr|   s         r   r   z_dummyremote.writebatch  s    h'' 	" 	"AnnQUUWWTn::G!%%''5T:: "b!!!" " " " " " " " " " " " " " "	" 	"s   %BB	B	c                     t          |          D ]k}|                     |                                d          5 }|                    |                                |d            d d d            n# 1 swxY w Y   ld S rS   )r   r   rD   r   )r   r   r   r   r|   s        r   r   z_dummyremote.readbatch  s    h'' 	4 	4A!%%''5)) 4R  "d3334 4 4 4 4 4 4 4 4 4 4 4 4 4 4	4 	4s   *A00A4	7A4	Nr6   r7   r8   rY   r@   r   r   r#   r   r   rS  rS    sG        66$ $ $" " "4 4 4 4 4r   rS  c                   $    e Zd ZdZd Zd Zd ZdS )_nullremotez&Null store storing blobs to /dev/null.c                     d S r>   r#   r   rc   r   s      r   r@   z_nullremote.__init__  rA   r   c                     d S r>   r#   r   s      r   r   z_nullremote.writebatch  rA   r   c                     d S r>   r#   r   s      r   r   z_nullremote.readbatch  rA   r   NrX  r#   r   r   rZ  rZ    sG        00        r   rZ  c                   .    e Zd ZdZd ZddZddZd ZdS )_promptremotez)Prompt user to set lfs.url when accessed.c                     d S r>   r#   r\  s      r   r@   z_promptremote.__init__  rA   r   Nc                 .    |                                   d S r>   _prompt)r   r   r   rU   s       r   r   z_promptremote.writebatch      r   c                 .    |                                   d S r>   rc  )r   r   r   rU   s       r   r   z_promptremote.readbatch  re  r   c                 D    t          j        t          d                    )Ns   lfs.url needs to be configured)r   r!  r   r?   s    r   rd  z_promptremote._prompt  s    k!=>>???r   r>   )r6   r7   r8   rY   r@   r   r   rd  r#   r   r   r`  r`    se        33        @ @ @ @ @r   r`  )   https   https   files   nullNc                     t          j                    }| D ]}|||                                <   |                                S )z0Remove any duplicate oids that exist in the list)r   sortdictrD   values)r   reducedr   s      r   r   r     sA    mooG  >>r   c                     t          t          j        |                                                    }|| k    r.t	          t          d          | z  t          d                    d S )Nr  r  r   )r   rq   rr   rw   rx   r   )rD   rV  r   s      r   r   r     si    '.))002233G#~~ 011C7#$$
 
 
 	
 ~r   c                    | j                             dd          }t          j        |pd          }||r|}n:t	          j        | d          r| j        }n| j                             dd          pd}t          j        |          }|j        dv r|j        r#|j        dd	         d
k    r|xj        d
z  c_        |j        pddz   |_        t          j        t          |                    }| j         
                    t          d          |z             |j        }|t          vr$t          j        t          d          |z            t          |         | |          S )a  remotestore factory. return a store in _storemap depending on config

    If ``lfs.url`` is specified, use that remote endpoint.  Otherwise, try to
    infer the endpoint, based on the remote repository using the same path
    adjustments as git.  As an extension, 'http' is supported as well so that
    ``hg serve`` works out of the box.

    https://github.com/git-lfs/git-lfs/blob/master/docs/api/server-discovery.md
    r^   s   urlr   Ns   _subtoppaths   pathss   default)ri  rh  r   s   .git/info/lfss   lfs: assuming remote store: %s
s   lfs: unknown url scheme: %s)rU   r   r   r   r   r   _subtoppathr   r   bytesr   r   	_storemapr   r!  )rc   remotelfsurlr   r   
defaulturlr   s          r   rt  rt    s^    W^^FF++F
+fm
$
$C~ 
	?DDdN33 	? #DD 7>>(J77>3D[&&
  333 (:?3B3#74#?#?4')5#9IIJO+eJ//00CGLL>??#EFFFZFYk!:;;fDEEEVT3'''r   c                       e Zd ZdS )rv   N)r6   r7   r8   r#   r   r   rv   rv   
  s        Dr   rv   c                       e Zd ZdZdS )rx   z~Raised when a corrupt blob is detected, aborting an operation

    It exists to allow specialized handling on the server side.N)r6   r7   r8   rY   r#   r   r   rx   rx     s"        C C C Cr   rx   r>   )6r   rH   rq   r   r(   rer8  mercurial.i18nr   mercurial.pycompatr   mercurial.noder   	mercurialr   r   r   httpconnectionmodr	   r
   r   r   r   r   vfsmodr   mercurial.utilsr   r   
largefilesr   compiler   r   r<   httpsendfilerQ   r[   r   r   basehandlerr   r   rS  rZ  r`  rs  r   r   rt  StorageErrorrv   r!  rx   r#   r   r   <module>r     s          				 				        & & & & & &      
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
       
        
(	)	)    VZ   @    f   0    %2   SA SA SA SA SA SA SA SAl1 1 12    T[,   .]8 ]8 ]8 ]8 ]8 ]8 ]8 ]8@4 4 4 4 4 4 4 4&
 
 
 
 
 
 
 
@ @ @ @ @ @ @ @" 
 	  
 
 
(( (( (( ((V	 	 	 	 	U' 	 	 	C C C C C C C C C Cr   