ó
î8¥Qc           @   sÞ  d  Z  d d l Z d d l Z d d l 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 d d l m Z d d l Z d d l Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e e d „ Z  d „  Z! d d „ Z# d d „ Z$ d e% d „ Z& d „  Z' d d „ Z( i e d d d e d ƒ d f d d e e d ƒ f g e d ƒ f d  6e( d! d" g  e d# ƒ f g e j) e d$ ƒ f d% 6Z* e j+ d& 7_+ d S('   s=   High-level command function for lfconvert, plus the cmdtable.iÿÿÿÿN(	   t   utilt   matcht   hgt   nodet   contextt   errort   cmdutilt   scmutilt   commands(   t   _(   t   releasec            sÍ  | d r t  } n* t } t j |  t | j d ƒ d d ƒ} t j | ƒ sh t j	 t
 d ƒ | ƒ ‚ n  t j | ƒ s“ t j	 t
 d ƒ | ƒ ‚ n  t j |  | ƒ ‰  |  j t
 d ƒ | ƒ t j |  | d t ƒ} t  } d }	 }
 z®| j ƒ  }	 | j ƒ  }
 ‡  f d †  ˆ  j j d ˆ  j ƒ  ƒ d Dƒ } i t j t j 6} | rt ƒ  } t ƒ  } | s}|  j t j d	 d g  ƒ} n  | r¤t j ˆ  j d
 t | ƒ ƒ } n d } i  } xh | D]` } |  j t
 d ƒ | j ƒ  d t
 d ƒ d ˆ  d j ƒ  ƒt ˆ  | | | | | | | | ƒ	 q·W|  j t
 d ƒ d ƒ t j j  | j! t j" ƒ ƒ rkt# j$ | j! t j" ƒ ƒ n  x‚ | j% ƒ  D]t } t j j& | j! | ƒ ƒ r²t j' | j! | ƒ ƒ n  y& t j( t j j) | j! | ƒ ƒ ƒ Wqxt* k
 rëqxXqxW| r‹| j+ j, d ƒ | j- ƒ  q‹nu x\ | D]T } |  j t
 d ƒ | j ƒ  d t
 d ƒ d ˆ  d j ƒ  ƒt. |  ˆ  | | | ƒ qW|  j t
 d ƒ d ƒ t } Wd | j/ j0 ƒ  t1 |
 |	 ƒ | sÈt# j$ | j ƒ n  Xd S(   sM  convert a normal repository to a largefiles repository

    Convert repository SOURCE to a new repository DEST, identical to
    SOURCE except that certain files will be converted as largefiles:
    specifically, any file that matches any PATTERN *or* whose size is
    above the minimum size threshold is converted as a largefile. The
    size used to determine whether or not to track a file as a
    largefile is the size of the first version of the file. The
    minimum size can be specified either with --size or in
    configuration as ``largefiles.size``.

    After running this command you will need to make sure that
    largefiles is enabled anywhere you intend to push the new
    repository.

    Use --to-normal to convert largefiles back to normal files; after
    this, the DEST repository can be used without largefiles at all.t	   to_normalt   sizet   defaults    %s is not a local Mercurial repos   initializing destination %s
t   createc         3   s   |  ] } ˆ  | Vq d  S(   N(    (   t   .0t   ctx(   t   rsrc(    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pys	   <genexpr>G   s    i    t   patternst    s   converting revisionst   unitt   revisiont   totalt   tipt
   largefilesN(2   t   Falset   Truet   lfutilt
   getminsizet   gett   NoneR   t   islocalR    t   AbortR	   t
   repositoryt   statust   wlockt   lockt	   changelogt   nodesbetweent   headsR   t   nullidt   sett
   configlistt   longnamet   match_R   t   roott   listt   progresst   revt   _lfconvert_addchangesett   ost   patht   existst   wjoint	   shortnamet   shutilt   rmtreet   keyst   isfilet   unlinkt
   removedirst   dirnamet   OSErrort   requirementst   addt   _writerequirementst   _addchangesett   dirstatet   clearR
   (   t   uit   srct   destt   patst   optst   tolfileR   t   rdstt   successt   dstwlockt   dstlockt   ctxst   revmapt   lfilest   normalfilest   matchert   lfiletohashR   t   f(    (   R   s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyt	   lfconvert   sp    
	$
		!&
c   	         s¢   t  ˆ  ˆ ƒ } t ˆ  | ƒ ‰ ‡  ‡ ‡ ‡ ‡ f d †  } g  } xC ˆ D]; } t j | ƒ rt | j t j | ƒ ƒ qF | j | ƒ qF Wt | | ˆ  | | ˆ ƒ d  S(   Nc   	         s›  t  j | ƒ ˆ k ry ˆ  j t  j | ƒ ƒ } Wn t j k
 rM t ‚ n X| j ƒ  } | rv t  j | d ƒ } n  | j ƒ  j	 ƒ  } t  j
 ˆ | ƒ } | d  k rt ˆ ˆ ˆ  j ƒ  ƒ t  j
 ˆ | ƒ } | d  k rt j t d ƒ | t j ˆ  j ƒ  ƒ f ƒ ‚ qn  d } d  } z t | d ƒ } | j ƒ  } Wd  | rO| j ƒ  n  Xt j | | d | j ƒ  k d | j ƒ  k | ƒ St |  j ˆ  | ˆ ƒ Sd  S(   Ni    s'   missing largefile '%s' from revision %sR   t   rbt   lt   x(   R   t   standint   filectxR   t   LookupErrort   IOErrort   renamedt   splitstandint   datat   stript   findfileR   t   cachelfilesR   R    R    R	   t   hext   opent   readt   closeR   t
   memfilectxt   flagst   _getnormalcontextRE   (	   t   repot   memctxRU   t   fctxR^   t   hashR3   R`   t   fd(   R   t   filesRP   R   RE   (    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyt
   getfilectx‚   s6    
	%(   t   _convertparentst   _getchangedfilesR   t	   isstandint   appendR_   t   _commitcontext(	   RE   R   RK   R   RP   t   parentsRq   t   dstfilest   file(    (   R   Rp   RP   R   RE   s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyRB   {   s    &c	      
      s§  t  ˆ  ˆ ƒ }	 t ˆ  |	 ƒ }
 g  } xN|
 D]F} | | k r| | k rt | ˆ  | | ƒ } | ˆ  j ƒ  k rë ˆ  j | ƒ } | j ƒ  } | ož | d | k } | | O} d | j ƒ  k rë | rß t j t	 d ƒ | ƒ ‚ n  t
 } që n  | r| j | ƒ q| j | ƒ n  | | k rd| j t j | ƒ ƒ | ˆ  j ƒ  k rqˆ  j | ƒ } d | j ƒ  k r§| j ƒ  } | r§| d | k r§t j t	 d ƒ | ƒ ‚ q§n  t j d ƒ } | j ˆ  | j ƒ  ƒ | j ƒ  } | ˆ k sõˆ | | k ra| j | ˆ  | j ƒ  ˆ  | j ƒ  ƒ d ˆ  | j ƒ  k } t j | t j | ƒ | | ƒ | ˆ | <qaqqq+ | j | ƒ q+ W‡  ‡ ‡ f d †  } t | |	 ˆ  | | ˆ ƒ d  S(   Ni    RX   s+   renamed/copied largefile %s becomes symlinks   largefile %s becomes symlinkR   RY   c            sÉ   t  j | ƒ r¯ t  j | ƒ } y ˆ  j | ƒ } Wn t j k
 rM t ‚ n X| j ƒ  } | rv t  j | d ƒ } n  t	 j
 | ˆ | d d | j ƒ  k d | j ƒ  k | ƒ St |  j ˆ  | ˆ ƒ Sd  S(   Ni    s   
RX   RY   (   R   Rt   R_   R[   R   R\   R]   R^   RZ   R   Rh   Ri   Rj   RE   (   Rk   Rl   RU   t   srcfnameRm   R^   (   R   RT   RP   (    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyRq   ç   s    
"(   Rr   Rs   t   _islfilet   manifestR[   R^   Ri   R    R    R	   R   R@   Ru   R   RZ   t   sha1t   updateR`   t	   hexdigestt   wwritet   writestandinRv   (   R   RK   R   RP   RQ   RR   RS   R   RT   Rw   Rp   Rx   RU   t   islfileRm   R^   t   renamedlfilet   mRn   t
   executableRq   (    (   R   RT   RP   s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyR1   ±   sP    
	'c      	   C   su   t  j |  | | j ƒ  | | | j ƒ  | j ƒ  | j ƒ  ƒ } |  j | ƒ } |  j | ƒ |  j j	 ƒ  | | j
 ƒ  <d  S(   N(   R   Rl   t   descriptiont   usert   datet   extrat	   commitctxt
   setparentsR%   R   R   (   RK   Rw   R   Rx   Rq   RP   t   mctxt   ret(    (    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyRv   þ   s
    $c         C   sÝ   t  |  j ƒ  ƒ } t j | k rÙ |  j ƒ  } |  j ƒ  d j ƒ  } |  j ƒ  d j ƒ  } | t  | ƒ t  | ƒ Bt  | ƒ O} xY | D]N } | | | j | d  ƒ k sÂ | | | j | d  ƒ k r„ | j | ƒ q„ q„ Wn  | S(   Ni    i   (	   R)   Rp   R   R(   R|   Rw   R   R   R@   (   R   Rw   Rp   t   mct   mp1t   mp2RU   (    (    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyRs     s    $8c         C   sa   g  } x+ |  j  ƒ  D] } | j | | j ƒ  ƒ q Wx& t | ƒ d k  r\ | j t j ƒ q7 W| S(   Ni   (   Rw   Ru   R   t   lenR(   (   R   RP   Rw   t   p(    (    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyRr     s    c         C   s­   y | j  | ƒ } Wn t j k
 r/ t ‚ n X| j ƒ  } | rO | d } n  | j ƒ  } | d k r| t |  | | ƒ } n  t j | | d | j	 ƒ  k d | j	 ƒ  k | ƒ S(   Ni    s   .hgtagsRX   RY   (
   R[   R   R\   R]   R^   R`   t   _converttagsR   Rh   Ri   (   RE   R   RU   RP   Rm   R^   R`   (    (    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyRj     s    
c         C   s  g  } xõ | j  ƒ  D]ç } y | j d d ƒ \ } } Wn+ t k
 rb |  j t d | ƒ ƒ q n Xy t j | ƒ } Wn+ t k
 r£ |  j t d | ƒ ƒ q n Xy( | j d t j	 | | ƒ | f ƒ Wq t
 k
 rù |  j t d ƒ | ƒ q q Xq Wd j | ƒ S(   Nt    i   s&   skipping incorrectly formatted tag %s
s%   skipping incorrectly formatted id %s
s   %s %s
s   no mapping for id %s
R   (   t
   splitlinest   splitt
   ValueErrort   warnR	   R   t   bint	   TypeErrorRu   Rd   t   KeyErrort   join(   RE   RP   R`   t   newdatat   linet   idt   namet   newid(    (    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyR“   ,  s*    c         C   s   |  d k s$ |  d k s$ |  d k r( t  S| r> | |  ƒ r> t Sy% | j |  ƒ j ƒ  | d d k SWn t j k
 rz t  SXd S(   sl   Return true if file should be considered a largefile, i.e.
    matcher matches it or it is larger than size.s   .hgtagss	   .hgignores   .hgsigsi   N(   R   R   R[   R   R   R\   (   Ry   R   RS   R   (    (    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyR{   C  s    $%c      	      s  | s
 d St  j | | d t ƒ} d } |  j d t | ƒ ƒ | j | ƒ ‰  t ‡  f d †  | ƒ } |  j d t | ƒ ƒ x„ | D]| } |  j t d ƒ | d d	 d
 t | ƒ ƒt	 j
 | | ƒ } | sæ t j t d ƒ | ƒ ‚ n  | j | | ƒ | d 7} q„ W|  j t d ƒ d ƒ d S(   s&   upload largefiles to the central storeNt   puti    s,   sending statlfile command for %d largefiles
c            s	   ˆ  |  S(   N(    (   t   h(   t   retval(    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyt   <lambda>[  s    s"   %d largefiles need to be uploaded
s   uploading largefilesR   t	   largefileR   s6   largefile %s missing from store (needs to be uploaded)i   (   t	   basestoret
   _openstoreR   t   debugR‘   R4   t   filterR/   R	   R   Rb   R    R    R¢   R   (   RE   R   RK   Rp   t   storet   atRn   t   source(    (   R¤   s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyt   uploadlfilesP  s$    c         C   sF   | r t  t | ƒ ƒ } n	 d g } t j | ƒ } | j | d | ƒS(   s)  Verify that every largefile revision in the current changeset
    exists in the central store.  With --contents, also verify that
    the contents of each local largefile file revision are correct (SHA-1 hash
    matches the revision ID).  With --all, check every changeset in
    this repository.t   .t   contents(   t   rangeR‘   R§   R¨   t   verify(   RE   Rk   t   allR°   t   revsR«   (    (    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyt   verifylfilesj  s
    	c         C   s{   t  j |  | ƒ } xb t | j j ƒ  ƒ D]K \ } } d | d d @t j @} |  j d | d | | d | f ƒ q( Wd S(   s2   Show basic information for the largefiles dirstates   %3oi   iÿ  s   %c %s %10d %s
i    i   N(   R   t   openlfdirstatet   sortedt   _mapt	   iteritemsR    t   umaskt   write(   RE   Rk   t
   lfdirstatet   file_t   entt   mode(    (    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyt   debugdirstatez  s    "c         C   sú   t  j | | ƒ } | r1 t | ƒ t | ƒ @} n  g  } xŽ | D]† } y' | | t  j | ƒ j ƒ  j ƒ  } Wn. t k
 r› } | j t j k r• q> n  ‚  n Xt  j	 | | ƒ s> | j
 | | f ƒ q> q> W| rð t j | ƒ }	 |	 j | ƒ }
 |
 Sg  g  f S(   s.  cachelfiles ensures that all largefiles needed by the specified revision
    are present in the repository's largefile cache.

    returns a tuple (cached, missing).  cached is the list of files downloaded
    by this operation; missing is the list of files that were needed but could
    not be found.(   R   t
   listlfilesR)   RZ   R`   Ra   R]   t   errnot   ENOENTRb   Ru   R§   R¨   R   (   RE   Rk   R   t   filelistRQ   t   togett   lfilet   expectedhasht   errR«   R   (    (    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyRc     s$    'c   
      C   sû   t  j | d  | j t j ƒ g i  ƒ } d „  } d } d } | g  k r´ xh t j | | i | d 6| ƒ D]D } t |  | | j	 ƒ  ƒ \ } }	 | t
 | ƒ 7} | t
 |	 ƒ 7} qi Wn  |  j t d ƒ | ƒ | d k rñ |  j t d ƒ | ƒ n  | | f S(   Nc         S   s   d  S(   N(    (   R   t   fns(    (    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyt   prepare¡  s    i    R0   s    %d additional largefiles cached
s!   %d largefiles failed to download
(   R   R   R   R5   R   R6   R   t   walkchangerevsRc   R   R‘   R"   R	   (
   RE   Rk   R0   t   matchfnRÊ   t   totalsuccesst   totalmissingR   RL   t   missing(    (    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyt   downloadlfilesž  s    	c         C   sŽ  | j  ƒ  } zpt j |  | ƒ } t t j | ƒ ƒ t | ƒ B} | d  k	 rt g  | D] } | | k rS | ^ qS } n  t } | rµ | rµ |  j t d ƒ ƒ t	 } t
 |  | d  | ƒ n  d \ }	 }
 x | D]y } t | | | ƒ } | r| d k rÿ |	 | 7}	 q|
 | 8}
 n  | rÈ |
 s|	 rÈ | rÈ |  j t d ƒ ƒ t	 } qÈ qÈ W| j ƒ  | r{| r{|  j t d ƒ |	 |
 f ƒ n  Wd  | j ƒ  Xd  S(   Ns   getting changed largefiles
i    s"   %d largefiles updated, %d removed
(   i    i    (   R#   R   R¶   R)   RÁ   R   R   R"   R	   R   Rc   t   _updatelfileR»   R
   (   RE   Rk   RÄ   t   printmessageR#   R¼   RQ   RU   t   printedt   updatedt   removedt   i(    (    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyt   updatelfiles°  s4    (
c   	      C   s\  d } |  j  | ƒ } |  j  t j | ƒ ƒ } t j j | ƒ rlt j j | d ƒ r~ t j j | ƒ r~ t j | | d ƒ n  t j |  | ƒ } | d k r&t j j | ƒ sÄ | t j	 | ƒ k r&t j
 |  | | ƒ s| |  d k rÿ t j | d t ƒn  | j | ƒ d S| j | ƒ d } n  t j | ƒ j } | t j | ƒ j k r°t j | | ƒ d } q°nD t j j | ƒ r°|  j j | ƒ |  d k r°t j | ƒ d } n  |  j t j | ƒ } | d k rt |  d t ƒ rô| j | ƒ qX| j | ƒ nT | d	 k r | j | ƒ n8 | d
 k r<| j | ƒ n | d k rX| j | ƒ n  | S(   s(  updates a single largefile and copies the state of its standin from
    the repository's dirstate to its state in the lfdirstate.

    returns 1 if the file was modified, -1 if the file was removed, 0 if the
    file was unchanged, and None if the needed largefile was missing from the
    cache.i    s   .origR   t   ignoremissingi   iÿÿÿÿt   nt   _isrebasingt   rt   at   ?N(   R5   R   RZ   R2   R3   R4   R7   t   copyfilet   readstandint   hashfilet   copyfromcacheR   R    t
   unlinkpathR   t   normallookupt   normalt   statt   st_modet   chmodRC   t	   normalizet   getattrR   t   removeR@   t   drop(	   Rk   R¼   RÆ   R   t   abslfilet
   absstandint
   expecthashR¿   t   state(    (    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyRÑ   Ò  sJ    (		R   c   	      K   s¼   | | _  | j d g  ƒ } | s9 t j t d ƒ ƒ ‚ n  t j | | ƒ } d } xM | D]E } |  j t d ƒ | ƒ t |  | | ƒ \ } } | t	 | ƒ 7} qX W|  j
 t d ƒ | ƒ d S(   s0  pull largefiles for the specified revisions from the specified source

    Pull largefiles that are referenced from local changesets but missing
    locally, pulling from a remote repository to the local cache.

    If SOURCE is omitted, the 'default' path will be used.
    See :hg:`help urls` for more information.

    .. container:: verbose

      Some examples:

      - pull largefiles for all branch heads::

          hg lfpull -r "head() and not closed()"

      - pull largefiles on the default branch::

          hg lfpull -r "branch(default)"
    R0   s   no revisions specifiedi    s#   pulling largefiles for revision %s
s   %d largefiles cached
N(   t   lfpullsourceR   R    R    R	   R   t   revranget   noteRc   R‘   R"   (	   RE   Rk   R­   RI   R´   t	   numcachedR0   t   cachedRÏ   (    (    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyt   lfpull  s    	t   sR   R   s9   minimum size (MB) for files to be converted as largefilest   SIZEs	   to-normals/   convert from a largefiles repo to a normal repos#   hg lfconvert SOURCE DEST [FILE ...]RV   RÛ   R0   s#   pull largefiles for these revisionss-   -r REV... [-e CMD] [--remotecmd CMD] [SOURCE]Rõ   s
    lfconvert(,   t   __doc__R2   RÂ   R7   t	   mercurialR    R   R,   R   R   R   R   R   R   R   t   mercurial.i18nR	   t   mercurial.lockR
   R   R§   RV   RB   R1   Rv   Rs   Rr   Rj   R“   R{   R®   R   Rµ   RÀ   R   Rc   RÐ   R   R×   RÑ   Rõ   t
   remoteoptst   cmdtablet	   inferrepo(    (    (    s?   /sys/lib/python2.7/site-packages/hgext/largefiles/lfcommands.pyt   <module>	   sJ   @	c	6	M									"	<%			