
    q&fX              
       \   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 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j?                  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+	 d/d#Z,ej?                  d$d%d&g  ed'      fge
jZ                  z    ed(            d0d)       Z.ej?                  d*g e
jZ                  z    ed+            d,        Z/y)1z=High-level command function for lfconvert, plus the cmdtable.    N)_)binhex)
cmdutilcontexterror	exthelperhglock
logcmdutilmatchscmutilutil)hashutil   )convcmdfilemap   )lfutilstorefactorys	   lfconvert   ss   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                 @
   |d   rd}n*d}t        j                  | d|j                  d      d      }t        j                  |      s!t        j                  t        d      |z        t        j                  |      s!t        j                  t        d      |z        t        j                  | |      | j                  t        d      |z         t        j                  | |d	      }d}dx}	}
	 fd
j                  j                  dj                               d   D        }j                  |j                  i}|r|j                         }	|j                         }
t!               }t!               }|s | j#                  t         j$                  d      }|r+t'        j(                  j*                  dt-        |            }nd}i }| j/                  t        d      t        d      d   j1                               5 }|D ]4  }|j3                  |j1                                t5        |||||||	       6 	 ddd       |j6                  j9                  t         j:                        r)|j6                  j=                  t         j:                         |j?                         D ]m  }|j6                  jA                  |      r|j6                  jC                  |       	 |j6                  jE                  |j6                  jG                  |             o |r|jJ                  jM                  d       tO        jP                  |       n G fddtR        jT                         G fddtV        jX                        t[        |       \  }}|dk7  rt        j                  t        d            tV        jX                  }tV        _,        	 tW        j\                  | ||dd       |tV        _,        d}|rJ|j^                  ja                  |      5  |j^                  jc                          ddd       te        |
|	       |s tg        j<                  |j*                         yy# 1 sw Y   +xY w# tH        $ r Y w xY w# |tV        _,        w xY w# 1 sw Y   exY w# |rW|j^                  ja                  |      5  |j^                  jc                          ddd       n# 1 sw Y   nxY wte        |
|	       |s tg        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.	to_normalFTsizeN)defaults    %s is not a local Mercurial repos   initializing destination %s
)createc              3   (   K   | ]	  }|     y wN ).0ctxrsrcs     =/usr/lib/python3/dist-packages/hgext/largefiles/lfcommands.py	<genexpr>zlfconvert.<locals>.<genexpr>o   s      
 I
s   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                 v    t         |   ||d        d| j                  j                  t        j
                  <   y )N   .)super__init__
filemapperrenamer   	shortname)selfuisource	__class__lfsources      r&   r0   z$lfconvert.<locals>.lfsource.__init__   s0    (D22vtD?CDOO**6+;+;<r   c                 J   |\  }}t         	|   ||      }|j                  t        j                        r|d   |S |d   j                         }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5dC@A %//0E0EFQ4<  Q4::<D!??46D|#kkAB'12   ==.!44r   )__name__
__module____qualname__r0   r:   __classcell__)r7   r8   r%   s   @r&   r8   r,      s    D5 5r   r8   c                   $     e Zd Z fdZ xZS )lfconvert.<locals>.converterc                 >     	||      }t         |   |||||       y r!   )r/   r0   )
r4   r5   r6   dest
revmapfileoptssrcr7   	converterr8   s
          r&   r0   z%lfconvert.<locals>.converter.__init__   s)    "2v.C)T3Cz4r   )rH   rI   rJ   r0   rK   )r7   rS   r8   s   @r&   rS   rM      s     r   rS   s&   all largefiles must be present locallys   hg)source_type	dest_type)4r   
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changing_parentsclearreleaseshutil)r5   rR   rO   patsrQ   tolfiler   rdstsuccessdstwlockdstlockctxsrevmaplfilesnormalfilesmatcherlfiletohashprogressr$   rE   foundmissingorigrS   r8   r%   s                          @@@r&   	lfconvertr   1   s+   P K  T488F+;TJ::c?kk!?@3FGG::dkk!?@4GHH==S!DIIa01D89==T$/DGHwx%

~~224FqI
 ++t{{+ zz|HiikGUF%K}}V__kB"..CdDK)*|_6l&&( !    COOCGGI.+##
& yy 0 01		  !1!12 %%' 99##A&II$$Q'II(():):1)=>	 !!%%m4--d35711 54G--  ,B5NE7!|kk!$M"NOO$$D )G)Tu %)!//5 &##%&GX&MM$))$ w 6  p %)!
& & //5 &##%& & &GX&MM$))$ s   4DR  :Q'>B#R  "4Q4B:R  R +R  R'Q1,R  4	R=R   RR  RR  R T>S"	T"S+'6Tc	                    t              }	t        |	      }
g }|
D ])  }||vr||vrt        |||      }|j                         v rij	                  |      }|j                         }|d}|xr ||v }||z  }d|j                         v r%|r!t        j                  t        d      |z        d}|r|j                  |       n|j                  |       ||v rZt        j                  |      }|j                  |       |j                         v sj	                  |      }d|j                         v r7|j                         }|r%||v r!t        j                  t        d      |z        t        j                  d      }|j!                  |   j#                                t%        |j'                               }|vs
|   |k7  s|j)                  ||   j#                         |   j                                d|   j                         v }t        j*                  ||||       ||<   |j                  |       , fd}t-        ||	||       y )NF   ls+   renamed/copied largefile %s becomes symlinks   largefile %s becomes symlinkr      xc           
      t   t        j                  |      }|z	 j                  |      }|j                         }|rt        j                  |      }t        j                  | |||   dz   d|j                         v d|j                         v |      S t        | |      S # t        j                  $ r Y y w xY w)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, oo'G !..1%%H%-

$

$  %T36::% $$ s   B! !B76B7)_convertparents_getchangedfiles_islfilemanifestr   r   r   r   r?   r   rs   r   r   appendr   sha1rg   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&   rh   rh      s8    c6*G S'*EH 2F?q3q#w5G CLLN"{{1~//+? $G&<7f+<<'4::<'##kkLM   $G

1";~~a(HOOH%CLLN"{{1~4::<'"oo/G7f#4#kk=>B 
 MM#&Q'188:K';q>T+AKK3q6;;=#a&,,.A!%Q!7J''hjI%)KN OOAe2h;8 4#xVDr   c                 r   t        j                  | ||j                         |||j                         |j	                         |j                               }| j                  |      }t        j                  | |       | j                  |       | j                  j                         ||j                         <   y 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                 $   t        | j                               }| j                         j                  |vrZ| j	                         }| j                         D ]7  }|j	                         j                  |      D ]  }|j                  |        9 |S r!   )r`   r   r   r^   r   r   diffrs   )r$   r   r   mcpctxfns         r&   r   r   T  sx    		E
xxz'\\^KKM 	Dmmo**2. 		"	 Lr   c                    g }| j                         D ]$  }|j                  ||j                                   & t        |      dk  r8|j                  | j	                         j
                         t        |      dk  r8|S )Nr   )r   r   r   lenr   r^   )r$   r   r   ps       r&   r   r   _  sj    G[[] )vaffh'()
g,
sxxz(() g,
Nr   c           
      F   	 |j                  |      }|j                         }|j	                         }|dk(  rt        | j                  ||      }t        j                  | |||d|j                         v d|j                         v |      S # t        j                  $ r Y y w xY w)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~ ooG99;DJDGGVT2c1dDDJJL0$$**,2F   s   B
 
B B c                    g }|j                         D ]G  }	 |j                  dd      \  }}	 t        |      }	 |j                  dt        ||         |fz         I dj                  |      S # t        $ r  | j                  t	        d      |z         Y w xY w# t        j                  $ r  | j                  t	        d      |z         Y w xY w# t        $ r  | j                  t	        d      |z         Y w xY w)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  s    G! 	zz$*HB	GE	NN:VE]);T(BBC  88G  	GGA@ADHI	
 ~~ 	GGA?@2EF	
  	GGA/0256	s3   A.B"C.&BB0CC&C98C9c                     | dk(  s
| dk(  s| dk(  ry|r	 ||       ry	 |j                  |       j                         |dz  dz  k\  S # t        j                  $ r Y y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     sl     zT\1TZ5G74={{4 %%'4$;+=== s   'A AAc                 b   |syt        j                  ||d      }d}| j                  dt        |      z         |j	                  |      }|D cg c]
  }||   r	| }}| j                  dt        |      z         | j                  t        d      t        d      t        |      	      5 }|D ]c  }	|j                  |       t        j                  ||	      }
|
s!t        j                  t        d
      |	z        |j                  |
|	       |dz  }e 	 ddd       yc c}w # 1 sw Y   yxY w)z&upload largefiles to the central storeNT)putr   s,   sending statlfile command for %d largefiles
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   rj   rf   r   rg   r   r>   r   r?   r   )r5   r%   r   r   storeatretvalhr   rF   r6   s              r&   uploadlfilesr     s-    ""448E	
BHH=E
JK\\% F/1VAYQ/E/HH3c%j@A		
!"8CJ 
 
 	 	DOOB__T40Fkk3 	  IIfd#!GB	  0 s   
D D -A)D%%D.c                     |r|j                  d      }ndg}t        j                  |      }|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     s?     yy"v""4(E<<x<00r   c                    t        j                  ||      }|rt        |      t        |      z  }g }||   }|D ]X  }	 t        j                  |t        j                  |               }t        j                  ||      rF|j                  ||f       Z |r(t        j                  |      }	|	j                  |      }
|
S g g fS # t
        $ r Y w xY w)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   
listlfilesr`   readasstandinr   FileNotFoundErrorr>   r   r   r   rW   )r5   r   r   filelistr   togetr$   lfileexpectedhashr   r   s              r&   cachelfilesr     s     tT*FVs8},E
t*C 0	!//FNN54I0JKL t\2LL%./0 &&t,ii
8O ! 		s   +C	CCc                 p   |j                   j                  }d}d}|j                  ddt        j                  z         D ]4  }t        | | ||            \  }}|t        |      z  }|t        |      z  }6 | j                  t        d      |z         |dkD  r| j                  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   rZ   r   )r5   r   tonodetotalsuccesstotalmissingrB   r   r   s           r&   rv   rv     s    ^^  FLLyyh1A1A&AB %&r4=G$G$% IIa45DEa
		!9:\IJ%%r   c           	      .	   t        j                  | ||      }|j                         5  t        j                  | |      }t	        t        j
                  |            t	        |      z  }|t	        |      }|D cg c]	  }||v s| }}i }	t	               }
d\  }}|j                  }|d   }|D ]  }t        j                  j                  t        j                  | ||      |j                        }t        j                  |      }t        j                  j                  t        j                  | ||      |j                        }|j                  |      r|j                  |      rV|j                  |      rEt        j                   |j#                  |      |j#                  |             |j%                  |       t        j&                  ||         }|dk7  s0||vrJ|j(                  j+                  |      j,                  r|j%                  |d       n|
j/                  |       |j1                  |ddd       ||	|<   |j                  |      s|j(                  j3                  |      |vs|j%                  |       |dz  } |j5                  |j7                                |r|D cg c]	  }||
vs| }}|
D ]K  }|j                  j%                  t        j                  |             |j8                  j;                  |       M  |t=        d	             t?        | |d|       |D ]  }d
}|	jA                  |      }|r.t        jB                  |||      s1|j1                  |dd       d}t        j                  |      }|j                  |      r{|jE                  |      jF                  dz  }|jE                  |      }|jF                  }||dz  k7  r8|dz  }|r||dz	  dz  tH        jJ                   z  z  }|jM                  ||       d}||z  }t        jN                  ||||        |j5                  |j7                                |r |t=        d      ||fz         ddd       yc c}w c c}w # 1 sw Y   yxY w)zUpdate largefiles according to standins in the working directory

    If ``printmessage`` is other than ``None``, it means "print (or
    ignore, for false) message forcibly".
    N)r   r   )startr   T)ignoremissing)
p1_tracked
wc_trackedpossibly_dirtyr   s   getting changed largefiles
r   )r   r   @   ir   I   s"   %d largefiles updated, %d removed
)(r   getstatuswriterr_   openlfdirstater`   r   ri   osrG   relpathr   
backuppathrd   r   rj   r|   copyfiler   
unlinkpathr   rx   	get_entryany_trackedrs   hacky_extension_update_file	normalizewritecurrenttransaction_mapreset_stater   r   rW   copyfromcachestatst_moder   umaskchmodsynclfdirstate)r5   r   r   printmessagenormallookupstatuswriter
lfdirstater   rE   rg   droppedupdatedremovedri   wctxr   	lfileorigr   standinorig
expecthashupdate1standinexecstmodes                           r&   updatelfilesr#    s:    ))"dLAL	 o**2t4
V&&t,-J?8}H!'9A1=a9F9%yyDz (	!E""2tU3499 ( I nnU+G''//""2tW5TYY * K {{7#;;{+E0BOODIIe$4dii	6JKOOK0#11$w-@
$D(==227;GG OOEOF#KK.
 ::#'#''+	 ;  %/F5M KK&//6dBOOE*qLGQ(	!V 	0023!'<A1G+;a<F< /		$$V^^A%67 ++A.	/ :;<D$/ #	IEGE*J++D*eD 66## 7 
  nnU+G{{7#"ii0885@YYu%zz$,.FND"e 3tzzk AAJJud+GwG!!$
E<HG#	IJ 	002389Wg<NN[o o :j =wo osK   AR:	RRERA;RR:>R8	RRF2R
RRs   lfpull   rs   revs#   pull largefiles for these revisionss-   -r REV... [-e CMD] [--remotecmd CMD] [SOURCE]c                 d   ||_         |j                  dg       }|st        j                  t	        d            t        j                  ||      }d}|D ]=  }| j                  t	        d      |z         t        | ||      \  }}|t        |      z  }? | j                  t	        d      |z         y)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)lfpullsourcerW   r   r?   r   r   revrangenoter   r   rZ   )	r5   r   r6   rQ   r   	numcachedrB   cachedr   s	            r&   lfpullr+  r  s    6 D88E2Dkk!5677tT*DI !
9:S@A'D#6S[ 	! IIa)*Y67r   s
   debuglfputs   FILEc                     t        j                  |      }t        j                  |      j	                  ||       | j                  d|z         y)Ns   %s
r   )r   hashfiler   r   r   r
  )r5   r   filepathkwargsrF   s        r&   
debuglfputr0    s>    ??8$D4 $$Xt4HHWt^r   )FFr!   )NNF)s   default)0__doc__r   r  r|   mercurial.i18nr   mercurial.noder   r   	mercurialr   r   r   r	   r
   r   r   r   rc   r   r   mercurial.utilsr   rw   r   r    r   r   r{   ehcommandr   rh   r   r   r   r   r   r   r   r   r   rv   r#  
remoteoptsr+  r0  r"   r   r&   <module>r:     s   D  	  
   %
 #
,, Y  JK	
 @A		
 ,-'  *\%+*\%~ZEz.$ *B1:& >Cxv 
FB@ABC67	!8!8H M2 2 22AgJ? @r   