
    q&f.                         d dl Z d dlmZ d dlmZmZ d dlmZmZm	Z	m
Z
mZmZ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mZ d Zd	 Zd
 Zd Zd Zd Z y)    N)_)hexnullrev)encodingerror	localrepomatchscmutilsparseutil)procutil   )
connectionpool	constantscontentstoredatapackfileserverclienthistorypackmetadatastoreremotefilectxremotefilelogshallowutilc                 z   t         j                  j                  | j                  j                  j
                  d      }t         j                  j                  |      st        j                  |       t        j                  | || j                  d      }t        j                  | || j                  d      }||fS )z:In-repo stores, like .hg/store/data; can not be discarded.s   dataFshared)ospathjoinsvfsvfsbaseexistsmakedirsr   remotefilelogcontentstorenamer   remotefilelogmetadatastore)repo	localpathlocalcontentlocalmetadatas       A/usr/lib/python3/dist-packages/hgext/remotefilelog/shallowrepo.pymakelocalstoresr,   %   s    TYY]]//9I77>>)$
I  99i5L "<<i5M &&    c                 N   t        j                  | j                        }t        j                  | || j
                  d      }t        j                  | || j
                  d      }|| _        | j                  j                  |       | j                  j                  |       ||fS )z?Typically machine-wide, cache of remote data; can be discarded.Tr   )r   getcachepathuir   r$   r%   r   r&   sharedstoreshareddatastoresappendsharedhistorystores)r'   	cachepathcachecontentcachemetadatas       r+   makecachestoresr8   5   s     ((1I99i4L "<<i4M $D  .##M2&&r-   c                     t        j                   |       | _        t        j                  | j                  | j                  |      }t        j                  | j                  | j                  |      }||fS )z-These stores fetch data from a remote server.)r   fileservicer   remotecontentstorer0   r   remotemetadatastore)r'   r6   r7   remotecontentremotemetadatas        r+   makeremotestoresr?   G   sh     (88>D 33!!<M #66!!=N .((r-   c                    t        j                  | t        j                        }t	        j
                  | j                  |      }t        j                  | j                  |      }| j                  j                  |       | j                  j                  |       t        j                  | j                  d||       ||fS )z5Packs are more efficient (to read from) cache stores.	   filestore)r   getcachepackpathr   FILEPACK_CATEGORYr   datapackstorer0   r   historypackstorer2   r3   r4   reportpackmetrics)r'   packpathpackcontentstorepackmetadatastores       r+   makepackstoresrJ   T   s     ++D)2M2MNH--dggx@#44TWWhG  !12##$56!!/1B ...r-   c                    g | _         g | _        t        |       \  }}t        |       \  }}t	        |       \  }}t        | ||      \  }}t        j                  |||||      | _        t        j                  |||||      | _        |}	|}
| j                  j                  | j                  | j                  |	|
       t        j                  | j                  d||       y)zBUnion stores iterate the other stores and return the first result.)
writestorerA   N)r2   r4   rJ   r8   r,   r?   r   unioncontentstorer   unionmetadatastorer:   setstorer   rF   r0   )r'   rH   rI   r6   r7   r)   r*   r=   r>   fileservicedatawritefileservicehistorywrites              r+   makeunionstoresrR   c   s    D!D*8*>''"1$"7L-"1$"7L-$4lM%!M>
 %66D '99 D (+	 !!/1Br-   c                      G  fdd j                          _         t        j                          _        t	                 j
                  j                  ddd        _         j
                  j                  ddd        _        t         d      st        j                          _
         j                  s j                  r=t        j                   j                  dd  j                   j                         _        y y )Nc                        e Zd Zej                  d        Zej                  fd       ZfdZ fdZ fdZ	e
j                  d fd	       Z	 dfd	Zdfd	Zdfd		Z fd
Z xZS )#wraprepo.<locals>.shallowrepositoryc                 :    | j                   j                  dd      S )N   remotefilelogs   reponame)r0   config)selfs    r+   r%   z(wraprepo.<locals>.shallowrepository.name   s    77>>"2K@@r-   c                     j                   j                  ddj                   j                  dd            }|st        j                  d      |S )NrW   s   fallbackpaths   pathss   defaults>   no remotefilelog server configured - is your .hg/hgrc trusted?)r0   rX   r   Abort)rY   r   r'   s     r+   fallbackpathz0wraprepo.<locals>.shallowrepository.fallbackpath   sO    77>> x4D
 kk> 
 Kr-   c                     |rt        j                  |      }nt        j                        }|j                         ry|S )z
            A wrapper that allows the remotefilelog to invoke sparsematch() if
            this is a sparse repository, or returns None if this is not a
            sparse repository.
            )revsN)r   matcheralways)rY   r^   kwargsretr'   s       r+   maybesparsematchz4wraprepo.<locals>.shallowrepository.maybesparsematch   s7     nnT5nnT*zz|Jr-   c                     |d   dk(  r|dd  }| j                  |      r!t        j                  | j                  ||       S t        |   |      S )Nr      /r   )shallowmatchr   r   superfile)rY   f	__class__shallowrepositorys     r+   rh   z(wraprepo.<locals>.shallowrepository.file   sS    tt|abE  #$22499aFF.:1==r-   c                     | j                  |      rt        j                  | |g|i |S t        |   |g|i |S N)rf   r   rg   filectx)rY   r   argsra   rj   rk   s       r+   rn   z+wraprepo.<locals>.shallowrepository.filectx   sV      &$224OOOO.=#) r-   c                    |j                         s|j                         j                         }g }|j                         |j	                         z   D ]J  }|j                  || j                        }|| j                  k7  s/|j                  |t        |      f       L | j                  j                  |       t        	| 3  |||      S )z{Add a new revision to current repository.
            Revision information is passed via the context argument.
            )r   origctx)manifestnodep1manifestmodifiedaddedgetnullidr3   r   r:   prefetchrg   	commitctx)
rY   ctxr   rq   m1filesri   fparent1rj   rk   s
           r+   rz   z-wraprepo.<locals>.shallowrepository.commitctx   s     ##%VVX&&(#))+5 9A!vva5H4;;.aX%789   ))%0*D;5' <  r-   c                 >   t        j                         dj                  dg}|r|j                  d       |r|d|gz  }i }j                  j                  dd      rj                  j                  |d<   t        j                  |t        j                  fdd	i| y
)z0Runs prefetch in background with optional repacks   -Rs   prefetchs   --repacks   -rs   devels   remotefilelog.bg-waitrecord_waitensurestartFN)
r   hgexecutableorigrootr3   r0   
configboolatexitrunbgcommandr   environ)	rY   r^   r!   repackpatsoptscmdra   r'   s	           r+   backgroundprefetchz6wraprepo.<locals>.shallowrepository.backgroundprefetch   s     ((*E4==+NC

;'t}$ Fww!!(,DE(,}%!!X%%38<Br-   c           
          j                  j                  ddddt        d      j                  z        5  | j	                  ||||       ddd       y# 1 sw Y   yxY w)z|Prefetches all the necessary file revisions for the given revs
            Optionally runs repack in background
            s   prefetchlockTNs   prefetching in %s)_lockr   r   r   	_prefetch)rY   r^   r!   r   r   r'   s        r+   ry   z,wraprepo.<locals>.shallowrepository.prefetch   s_     		&'$--7 7 tT467 7 7s   AAc                    | j                   }|rAj                  d|      }|/|t        k7  r&t        j                  d||            }|r|d   }n}j                  }|j                  d      }	|>||   j                            j                         }
t        |
j                               }n
t               }|j                         }|j                         }t               }|j                  t               t        |      }| j                  j                  t        d      |      }|j!                  d       t#        |      D ]  }|   }|rt%        j&                  |||      j)                  |      |j                         }|	j+                  |      }|	j-                  |      \  }}||v r||v r||   j/                         }
n||   j                         }
|
j                         }|rfd|D        }rfd|D        }||vr|j!                  |       n|j!                  |       |j                  |       |j1                           |j3                  |       |j3                  |       |j5                          |r<|D cg c]  \  }}|t7        |      f }}}j8                  j;                  |d	
       |r;|D cg c]  \  }}|t7        |      f }}}j8                  j;                  |       y y c c}}w c c}}w )Ns   outgoing(%s)s   first(reverse(::%s) - %ld)r   r-   s   prefetching)totalc              3   :   K   | ]  } |d          s|  ywr   N ).0pfms     r+   	<genexpr>z@wraprepo.<locals>.shallowrepository._prefetch.<locals>.<genexpr>.  s     :22a5B:   c              3   :   K   | ]  } |d          s|  ywr   r   )r   r   sparsematchs     r+   r   z@wraprepo.<locals>.shallowrepository._prefetch.<locals>.<genexpr>0  s     D2RU1CBDr   T)force)r\   r^   r   listmanifestlog
getstoragerr   readsetitemscopyaddlenr0   makeprogressr   updatesortedr
   r	   rc   rev
parentrevsreadfast	incrementdifference_updatecompleter   r:   ry   )rY   r^   r!   r   r   r\   	localrevs
serverbasemflmfrevlogmfdictskipr}   serverfilesvisitedrevcountprogressr   r{   mfnodemfrevrs   p2diffr   fnoderesultsr   r   r'   s                              @@r+   r   z-wraprepo.<locals>.shallowrepository._prefetch   s   ,,L !IIo|D	#!%		94"J
 ")!} 	""C~~c*HT$Z4467<<>6<<>*u IIKE))+KeGKK 4yHww++An,=X+NHOOAd| %3ic46A"33C8))+ V, ",,U3B=R7] [113F [--/F||~::DDDDi'&&t,LL&E"""$9%< ##D)))$/ CNO-4D#e*-OO  ))')> CHI-4D#e*-II  ))'2 	 P
 Js   LLc                 V    t         |           | j                  j                          y rm   )rg   closer   )rY   rj   rk   s    r+   r   z)wraprepo.<locals>.shallowrepository.closeG  s#    #T02%%'r-   )FN)NFNN)NNN)__name__
__module____qualname__r   propertycacher%   r\   rc   rh   rn   r   unfilteredmethodrz   r   ry   r   r   __classcell__)rj   r'   rk   s   @r+   rk   rU      s    				A 
	A 
			 
			>	 
	#	#	 
$	, BF	&	7M	3^	( 	(r-   rk   rW   s   includepatterns   excludepatternr   r-   )rj   r	   r`   rf   rR   r0   
configlistincludepatternexcludepatternhasattrr   root)r'   rk   s   `@r+   wraprepor      s    |(DNN |(| 'DNDD'',,+TD '',,+TD 4)*,;;DAd11!KKIIsD$"5"5t7J7J
 2r-   )!r   mercurial.i18nr   mercurial.noder   r   	mercurialr   r   r   r	   r
   r   r   mercurial.utilsr    r   r   r   r   r   r   r   r   r   r   r,   r8   r?   rJ   rR   r   r   r-   r+   <module>r      sS    
  '   %  ' '$
)/&RQ
r-   