
    	^cY              
          d Z ddlZddlZ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mZmZmZmZ ddlmZ ddlmZmZ d	d
lmZmZ ej        Z ej                    Ze                     dddd ed          dfddd ed          fg ed          dd          d             Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(d Z)d.d Z*d/d!Z+d" Z,	 d0d#Z-e                     d$d%d&g  ed'          fge
j.        z    ed(                    d1d*            Z/e                     d+g e
j.        z    ed,                    d-             Z0dS )2z=High-level command function for lfconvert, plus the cmdtable.    N)_)binhex)cmdutilcontexterror	exthelperhglock
logcmdutilmatchpycompatscmutilutil)hashutil   )convcmdfilemap   )lfutilstorefactorys	   lfconvert   s   size    s9   minimum size (MB) for files to be converted as largefiless   SIZEs	   to-normalFs/   convert from a largefiles repo to a normal repos#   hg lfconvert SOURCE DEST [FILE ...]T)norepo	inferrepoc                 
   t          j        |          }|d         rd}n-d}t          j        | d|                    d          d          }t          j        |          s$t          j        t          d          |z            t          j        |          s$t          j        t          d          |z            t          j
        | |          |                     t          d          |z             t          j
        | |d	          }d}dx}	}
	 fd
j                            d                                          d         D             }j        |j        i}|rB|                                }	|                                }
t%                      }t%                      }|s |                     t          j        d          }|r)t+          j        j        dt1          |                    }nd}i }|                     t          d          t          d          d                                                   5 }|D ]@}|                    |                                           t9          ||||||||	  	         A	 ddd           n# 1 swxY w Y   |j                            t          j                  r$|j                             t          j                   |!                                D ]y}|j        "                    |          r|j        #                    |           	 |j        $                    |j        %                    |                     j# tL          $ r Y vw xY w|r.|j'        (                    d           tS          j*        |           n G fddtV          j,                   G fddtZ          j.                  t_          |           \  }}|dk    r!t          j        t          d                    tZ          j.        }tZ          _.        	 t[          j0        | ||dd           |tZ          _.        n# |tZ          _.        w xY wd}|r)|j1        2                                 tg          |
|	           |sti          j         |j                   dS dS # |r)|j1        2                                 tg          |
|	           |sti          j         |j                   w w xY w)aM  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.s	   to_normalFTr   N)defaults    %s is not a local Mercurial repos   initializing destination %s
)createc              3   (   K   | ]}|         V  d S N ).0ctxrsrcs     =/usr/lib/python3/dist-packages/hgext/largefiles/lfcommands.py	<genexpr>zlfconvert.<locals>.<genexpr>q   s;       
 
 I
 
 
 
 
 
r   r   s   patternsr   s   converting revisionss	   revisionss   tipunittotals
   largefilesc                   0     e Zd Z fdZ fdZ xZS )lfconvert.<locals>.lfsourcec                     t          |                               ||d            d| j        j        t          j        <   d S )N   .)super__init__
filemapperrenamer   	shortname)selfuisource	__class__lfsources      r&   r0   z$lfconvert.<locals>.lfsource.__init__   s=    (D))222vtDDD?CDO*6+;<<<r   c                    |\  }}t          	|                               ||          }|                    t          j                  r|d         |S |d                                         }t          j        
|          }|&t          j        t          d          ||fz            t          j        |          |d         fS )Nr   s    missing largefile for '%s' in %sr   )r/   getfile
startswithr   shortnameslashstripfindfiler   Abortr   r   readfile)r4   namerevrealnamerealrevfhashpathr7   r8   r%   s           r&   r:   z#lfconvert.<locals>.lfsource.getfile   s    (+%Hgh--55dC@@A %//0EFF!Q4<  Q4::<<D!?466D|#kABB'12    =..!44r   )__name__
__module____qualname__r0   r:   __classcell__)r7   r8   r%   s   @r&   r8   r,      sg        D D D D D D5 5 5 5 5 5 5 5 5 5 5r   r8   c                   $     e Zd Z fdZ xZS )lfconvert.<locals>.converterc                 n     	||          }t          |                               |||||           d S r!   )r/   r0   )
r4   r5   r6   dest
revmapfileoptssrcr7   	converterr8   s
          r&   r0   z%lfconvert.<locals>.converter.__init__   sK    "(2v..C)T**33Cz4    r   )rH   rI   rJ   r0   rK   )r7   rS   r8   s   @r&   rS   rM      sC                  r   rS   s&   all largefiles must be present locallys   hg)source_type	dest_type)5r   byteskwargsr   
getminsizegetr
   islocalr   r?   r   
repositorystatus	changelognodesbetweenheadsnullidwlockr   set
configlistlongnamematchmodr   rootlistmakeprogressrB   update_lfconvert_addchangesetwvfsexistsr3   rmtreekeysisfileunlink
removedirsdirnameOSErrorrequirementsaddr   writereporequirementsr   filemap_sourcer   rS   downloadlfilesconvertdirstateclearreleaseshutil)r5   rR   rO   patsrQ   tolfilesizerdstsuccessdstwlockdstlockctxsrevmaplfilesnormalfilesmatcherlfiletohashprogressr$   rE   foundmissingorigrS   r8   r%   s                          @@@r&   	lfconvertr   2   s   P %%DL L T488G+<+<dKKK:c?? Hk!?@@3FGGG:d Ik!?@@4GHHH=S!!DIIa011D8999=T$///DGHwv%

 
 
 
~224FFqI
 
 
 +t{+ d	) zz||HiikkGUUF%%K C}}V_kBB ".CdDDK)**|__6l&&(( !      COOCGGII...+##
 
 
 
              & y 011 3	  !1222 %%''  9##A&& (I$$Q'''I(():):1)=)=>>>>   D
  4!%%m444-d3335 5 5 5 5 5 5 571 5 5 54       G-    ,B55NE7!||k!$M"N"NOOO$D )G)Tu    %)!!D!(((( 	'M!!!GX&&& 	%M$)$$$$$	% 	%  	'M!!!GX&&& 	%M$)$$$$	%sq   D/R6 AJR6 JR6 J BR6 62M)(R6 )
M63R6 5M66B<R6 3Q R6 Q''R6 6A	S?c	                    t                    }	t          |	          }
g }|
D ]}||vr||vrt          |||          }|                                v rv                    |          }|                                }|d}|o||v }||z  }d|                                v r(|r$t          j        t          d          |z            d}|r|
                    |           n|
                    |           ||v rt          j        |          }|                    |           |                                v rZ                    |          }d|                                v r>|                                }|r(||v r$t          j        t          d          |z            t          j        d          }|                    |                                                    t%          |                                          }|vs|         |k    r|                    ||                                         |                                                    d|                                         v }t          j        ||||           ||<   w|                    |           fd}t-          ||	||           d S )NF   ls+   renamed/copied largefile %s becomes symlinks   largefile %s becomes symlinkr      xc           
         t          j        |          }|	                     |          }n# t          j        $ r Y d S w xY w|                                }|rt          j        |          }t          j        | |||         dz   d|	                                v d|	                                v |          S t          | |          S )N   
r   r   )r   splitstandinfilectxr   LookupError
copysourcestandinr   
memfilectxflags_getnormalcontext)	repomemctxrE   srcfnamefctxrenamedr$   r   r   s	         r&   
getfilectxz+_lfconvert_addchangeset.<locals>.getfilectx#  s    &q)){{8,,$   ttoo''G 2 !.11%H%-

$

$   %T36:::s   / AA)_convertparents_getchangedfiles_islfilemanifestr   r   r   r   r?   r   rt   r   r   appendr   sha1rh   datar   digestwwritewritestandin_commitcontext)r%   r   r$   r   r   r   r   r   r   parentsfilesdstfilesrE   islfiler   r   renamedlfilefstandinmrF   
executabler   s     ``    `             r&   ri   ri      s    c6**G S'**EH 2 2F??q33q#w55G CLLNN""{{1~~//++? $G&<7f+<<'4::<<''# #kLMM    $G #

1""";;~a((HOOH%%%CLLNN""{{1~~4::<<''"oo//G 7f#4#4#k=>>B  
 M#&&Q'''188::K'';q>T+A+AKK3q6;;==#a&,,..AAA!%Q!7J'hjIII%)KN OOA; ; ; ; ; ; ;8 4#xVDDDDDr   c                    t          j        | ||                                |||                                |                                |                                          }|                     |          }t          j        | |           | 	                    |           | j
                                        ||                                <   d S r!   )r   r   descriptionuserdateextra	commitctxr   copyalltostore
setparentsr\   tipnode)r   r   r$   r   r   r   mctxrets           r&   r   r   B  s    >



			 	D ..

C
$$$$OOC++--F388::r   c                 R   t          |                                           }|                                 j        |vrj|                                 }|                                 D ]A}|                                                    |          D ]}|                    |           B|S r!   )ra   r   r   r_   r   r   diffrt   )r$   r   r   mcpctxfns         r&   r   r   T  s    		E
xxzz''\\^^KKMM 	 	Dmmoo**2..  		"Lr   c                 6   g }|                                  D ]/}|                    ||                                                    0t          |          dk     r?|                    |                                 j                   t          |          dk     ?|S )Nr   )r   r   r   lenr   r_   )r$   r   r   ps       r&   r   r   _  s    G[[]] ) )vaffhh'((((
g,,

sxxzz())) g,,

Nr   c           
      h   	 |                     |          }n# t          j        $ r Y d S w xY w|                                }|                                }|dk    rt          | j        ||          }t          j        | |||d|	                                v d|	                                v |          S )N   .hgtagsr   r   )
r   r   r   r   r   _converttagsr5   r   r   r   )r   r$   rE   r   r   r   r   s          r&   r   r   i  s    {{1~~   ttooG99;;DJDGVT22c1dDDJJLL0$$**,,2F  s    ++c                 \   g }|                                 D ] }	 |                    dd          \  }}n5# t          $ r( |                     t	          d          |z             Y Ow xY w	 t          |          }n:# t          j        $ r( |                     t	          d          |z             Y w xY w	 |                    dt          ||                   |fz             # t          $ r( |                     t	          d          |z             Y w xY wd                    |          S )N    r   s&   skipping incorrectly formatted tag %s
s%   skipping incorrectly formatted id %s
s   %s %s
s   no mapping for id %s
r   )
splitlinessplit
ValueErrorwarnr   r   binasciiErrorr   r   KeyErrorjoin)r5   r   r   newdatalineidrA   newids           r&   r   r   y  sV   G!!  	zz$**HB 	 	 	GGA@AADHIIIH		GGEE~ 	 	 	GGA?@@2EFFFH		NN:VE]););T(BBCCCC 	 	 	GGA/0025666H	 88Gs3   5/A'&A'+A;;4B21B26-C$$/DDc                     | dk    s| dk    s| dk    rdS |r ||           rdS 	 |                     |                                           |dz  dz  k    S # t          j        $ r Y dS w xY w)zlReturn true if file should be considered a largefile, i.e.
    matcher matches it or it is larger than size.r   s	   .hgignores   .hgsigsFTi   )r   r   r   r   )filer$   r   r   s       r&   r   r     s     zT\11TZ5G5Gu 774== t{{4  %%''4$;+===   uus   0A A)(A)c                   	 |sdS t          j        ||d          }d}|                     dt          |          z             |                    |          		fd|D             }|                     dt          |          z             |                     t          d          t          d	          t          |          
          5 }|D ]m}|                    |           t          j	        ||          }|s$t          j        t          d          |z            |                    ||           |dz  }n	 ddd           dS # 1 swxY w Y   dS )z&upload largefiles to the central storeNT)putr   s,   sending statlfile command for %d largefiles
c                 $    g | ]}|         
|S r"   r"   )r#   hretvals     r&   
<listcomp>z uploadlfiles.<locals>.<listcomp>  s"    ///1VAY/Q///r   s"   %d largefiles need to be uploaded
s   uploading largefiless   filesr(   s6   largefile %s missing from store (needs to be uploaded)r   )r   	openstoredebugr   rk   rg   r   rh   r   r>   r   r?   r   )
r5   r%   r   r   storeatr   rF   r6   r   s
            @r&   uploadlfilesr     s     "44888E	
BHH=E

JKKK\\%  F///////EHH3c%jj@AAA		
!""8CJJ 
 
 
 	 	 	DOOB_T400F k3  	   IIfd###!GBB	                 s   A1E

EEc                     |r|                     d          }ndg}t          j        |          }|                    ||          S )a)  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.s   all()r.   )contents)revsr   r   verify)r5   r   allr   r   r   s         r&   verifylfilesr     sL      yy""v"4((E<<x<000r   c                    t          j        ||          }|rt          |          t          |          z  }g }||         }|D ]l}	 t          j        |t          j        |                             }n# t
          $ r Y <w xY wt          j        ||          s|                    ||f           m|r+t          j	        |          }	|	
                    |          }
|
S g g fS )a.  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   
listlfilesra   readasstandinr   FileNotFoundErrorr>   r   r   r   rX   )r5   r   r   filelistr   togetr$   lfileexpectedhashr   r   s              r&   cachelfilesr     s     tT**F -Vs8}},E
t*C 0 0	!/FN54I4I0JKKLL  	 	 	H	t\22 	0LL%./// &t,,ii
8Os   ,A33
B ?B c                    |j         j        }d}d}|                    ddt          j        z             D ]C}t          | | ||                    \  }}|t          |          z  }|t          |          z  }D|                     t          d          |z             |dk    r%|                     t          d          |z             ||fS )Nr   s   file(%s)s   path:s    %d additional largefiles cached
s!   %d largefiles failed to download
)	r\   r   r   r   r3   r   r   r[   r   )r5   r   tonodetotalsuccesstotalmissingrB   r   r   s           r&   rw   rw     s    ^ FLLyyh1A&ABB % %&r4==G$G$IIa455DEEEa
		!9::\IJJJ%%r   c           
      N
   t          j        | ||          }|                                5  t          j        | |          }t	          t          j        |                    t	          |          z  }t	                    fd|D             }|                                5  i }t	                      d\  }	}
|j        }|d         }|D ]}t          j	        
                    t          j        | ||          |j                  }t          j        |          }t          j	        
                    t          j        | ||          |j                  }|                    |          r
|                    |          re|                    |          rPt!          j        |                    |          |                    |                     |                    |           t          j        ||                   }|dk    rn||vrL|j                            |          j        r|                    |d           n                    |           |                    |ddd           |||<   |                    |          r6|j                            |          |vr|                    |           |
d	z  }
	 ddd           n# 1 swxY w Y   |                    |                                           |rfd
|D             }D ]H}|j                            t          j        |                     |j                            |           I |t?          d                     tA          | |d|           |                                5  |D ]}d}|!                    |          }|r1t          j"        |||          s3|                    |dd           d	}t          j        |          }|                    |          rz|#                    |          j$        dz  }|#                    |          }|j$        }||dz  k    r8|dz  }|r||dz	  dz  tJ          j&         z  z  }|'                    ||           d	}|	|z  }	t          j(        ||||           	 ddd           n# 1 swxY w Y   |                    |                                           |r |t?          d          |	|
fz             ddd           dS # 1 swxY w Y   dS )zUpdate largefiles according to standins in the working directory

    If ``printmessage`` is other than ``None``, it means "print (or
    ignore, for false) message forcibly".
    Nc                     g | ]}|v |	S r"   r"   )r#   rE   r   s     r&   r   z updatelfiles.<locals>.<listcomp>  s    999A1==a===r   )r   r   )startr   T)ignoremissing)
p1_tracked
wc_trackedpossibly_dirtyr   c                     g | ]}|v|	S r"   r"   )r#   rE   droppeds     r&   r   z updatelfiles.<locals>.<listcomp><  s#    <<<A1G+;+;a+;+;+;r   s   getting changed largefiles
r   )r   r   @   ir   I   s"   %d largefiles updated, %d removed
))r   getstatuswriterr`   openlfdirstatera   r   parentchangerj   osrG   relpathr   
backuppathre   r   rk   r|   copyfiler   
unlinkpathr   ry   	get_entryany_trackedrt   update_file	normalizewritecurrenttransaction_mapreset_stater   r   rX   copyfromcachestatst_moder   umaskchmodsynclfdirstate)r5   r   r   printmessagenormallookupstatuswriter
lfdirstater   rh   updatedremovedrj   wctxr   	lfileorigr   standinorig
expecthashrE   update1standinexecstmoder  s     `                    @r&   updatelfilesr)    sW    )"dLAAL	 o o*2t44
V&t,,--J?8}}H9999999F$$&& .	% .	%FeeG#GW9D:D (% (%GOO&r477ty ,  	 !.// goo&r499 .   ;;w''  %{{;// 5DKK4F4F 5		%(8(8$))I:N:NOOO444!'!5d7m!D!DJ!S(( ,,#}66w??K 3 $T J J J J 'E 2 2 2
 #..!'+'++/	 /    )3u E**% M33E::$FF...1Q(%.	% .	% .	% .	% .	% .	% .	% .	% .	% .	% .	% .	% .	% .	% .	%b 	0022333 
	0<<<<<<<F / /	$$V^A%6%6777 ++A....L:;;<<<D$///$$&& "	M "	M !M !M#ZZ..
 	 !/j%HH !  **$4 +     G !.//;;w'' $"&))G"4"4"<u"DK5))B:D"dUl22& F TQY%$74:+$EED

5$///"#7"%dJ|LLLLC!M"	M "	M "	M "	M "	M "	M "	M "	M "	M "	M "	M "	M "	M "	M "	MH 	0022333 	L899Wg<NN  [o o o o o o o o o o o o o o o o o os^   A:T'HKTK	TK	CTDR<0T<S 	 TS 	A	TT!Ts   lfpull   rs   revs#   pull largefiles for these revisionss-   -r REV... [-e CMD] [--remotecmd CMD] [SOURCE]   defaultc                    ||_         |                    dg           }|s!t          j        t	          d                    t          j        ||          }d}|D ]M}|                     t	          d          |z             t          | ||          \  }}|t          |          z  }N| 
                    t	          d          |z             dS )a0  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)"
    rB   s   no revisions specifiedr   s#   pulling largefiles for revision %d
s   %d largefiles cached
N)lfpullsourcerX   r   r?   r   r   revrangenoter   r   r[   )	r5   r   r6   rQ   r   	numcachedrB   cachedr   s	            r&   lfpullr2  r  s    6 D88E2D 8k!566777tT**DI ! !
9::S@AAA'D#66S[[ 		IIa)**Y677777r   s
   debuglfputs   FILEc                     t          j        |          }t          j        |                              ||           |                     d|z             dS )Ns   %s
r   )r   hashfiler   r   r   r  )r5   r   filepathkwargsrF   s        r&   
debuglfputr7    sM    ?8$$D4  $$Xt444HHWt^1r   )FFr!   )NNF)r+  )1__doc__r   r  r|   mercurial.i18nr   mercurial.noder   r   	mercurialr   r   r   r	   r
   r   r   r   rd   r   r   r   mercurial.utilsr   rx   r   r    r   r   r{   ehcommandr   ri   r   r   r   r   r   r   r   r   r   rw   r)  
remoteoptsr2  r7  r"   r   r&   <module>rA     sk   D C  				              
                          % $ $ $ $ $       
 # " " " " " " "
, Y  AJKK	
 A@AA		
 A,--'   *[% [%+ *[%|ZE ZE ZEz. . .$         *    B1 1 1 1   :& & & >Cx x x xv 
FB@AABCA677	 !8 !8 !8 !8H M2 22AAgJJ??  @?  r   