
    q&fS                        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m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 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   ejB                  d
      Z"dZ#d Z$d Z% e&e"de%      Z'd Z(d Z)d Z* e*       \  Z+Z,d Z-d Z.d Z/ e&e"dd      xs  e/       Z0dZ1dZ2d Z3dZ4dZ5de5dz   z  dz
  Z6d Z7d Z8d Z9 e&e"de9      Z9d  Z:d! Z;g d"Z<d#Z=d$Z>d%Z? ej                  d&      ZAd' ZBd( ZC ej                  d)*       G d+ d,             ZE ej                  d)d-.       G d/ d0             ZF ej                  d)d-.       G d1 d2eF             ZG ej                  d)d-.       G d3 d4eF             ZHd5 ZId6 ZJd7 ZK G d8 d9      ZL G d: d;eL      ZM G d< d=      ZN G d> d?ej                        ZP G d@ dAeL      ZQy)B    N)	GeneratorList   )_)attr)hex)INDEX_HEADERKIND_CHANGELOGKIND_FILELOGKIND_MANIFESTLOG)		changelogerrorfilelogmanifestpolicypycompatrevlogutilvfs)hashutilparsersi@B c                     |y| j                   r || j                        S | j                  r*|j                  | j                  j	                  d            S t        j                  d| z        )zparses a fncache entry and returns whether the entry is tracking a path
    matched by matcher or not.

    If matcher is None, returns TrueT   /s   cannot process entry %r)
is_filelog	target_idis_manifestlogvisitdirrstripr   ProgrammingError)entrymatchers     1/usr/lib/python3/dist-packages/mercurial/store.py_match_tracked_entryr#   +   sd     u''			 6 6t <==

 
 !;e!C
DD    c                 f    | j                  dd      j                  dd      j                  dd      S )aM  
    >>> _encodedir(b'data/foo.i')
    'data/foo.i'
    >>> _encodedir(b'data/foo.i/bla.i')
    'data/foo.i.hg/bla.i'
    >>> _encodedir(b'data/foo.i.hg/bla.i')
    'data/foo.i.hg.hg/bla.i'
    >>> _encodedir(b'data/foo.i\ndata/foo.i/bla.i\ndata/foo.i.hg/bla.i\n')
    'data/foo.i\ndata/foo.i.hg/bla.i\ndata/foo.i.hg.hg/bla.i\n'
       .hg/   .hg.hg/   .i/   .i.hg/   .d/   .d.hg/replacepaths    r"   
_encodedirr0   <   s/     	Wj)		#		#r$   	encodedirc                 r    d| vr| S | j                  dd      j                  dd      j                  dd      S )z
    >>> decodedir(b'data/foo.i')
    'data/foo.i'
    >>> decodedir(b'data/foo.i.hg/bla.i')
    'data/foo.i/bla.i'
    >>> decodedir(b'data/foo.i.hg.hg/bla.i')
    'data/foo.i.hg/bla.i'
    r&   r+   r*   r)   r(   r'   r,   r.   s    r"   	decodedirr3   Q   s<     dY'	F	#	W	%r$   c               #      K   dD  cg c]  } t        |        }} t        d      D ]  } |   t        dd      D ]  } |   |D ]  } |   yc c} w w)zcharacters that are problematic for filesystems

    * ascii escapes (0..31)
    * ascii hi (126..255)
    * windows specials

    these characters will be escaped by encodefunctions
    z\:*?"<>|    ~      N)ordrange)xwinreserveds     r"   	_reservedr<   c   sj      $00a3q60K02Y 3_   1s   AA<Ac                    	 d} t         j                  }t        t        |t	        d                  }t        t	        t        d      t        d      dz               }|D ci c]  }|| c}t               D ]  }d|z   ||      <    |t        |       gz   D ]$  }|  ||      j                         z    ||      <   & i 	j                         D ]
  \  }}|	|<    	fdfdfd	fS c c}w )
a  
    >>> enc, dec = _buildencodefun()

    >>> enc(b'nothing/special.txt')
    'nothing/special.txt'
    >>> dec(b'nothing/special.txt')
    'nothing/special.txt'

    >>> enc(b'HELLO')
    '_h_e_l_l_o'
    >>> dec(b'_h_e_l_l_o')
    'HELLO'

    >>> enc(b'hello:world?')
    'hello~3aworld~3f'
    >>> dec(b'hello~3aworld~3f')
    'hello:world?'

    >>> enc(b'the\x07quick\xADshot')
    'the~07quick~adshot'
    >>> dec(b'the~07quick~adshot')
    'the\x07quick\xadshot'
       _      A   Zr      ~%02xc              3      K   d}|t        |       k  r;t        dd      D ]  }	 | |||z        ||z  } n t        |t        |       k  r:y y # t        $ r Y ;w xY ww)Nr   r      )lenr9   KeyError)sildmaps      r"   decodez_buildencodefun.<locals>.decode   sy     #a&j1a[ qQU|,,FA	  #a&j   s-    AAAA	AAAAc           
          dj                  t        t        |             D cg c]  }| ||dz        c}      S c c}w )Nr$   r   )joinr9   rE   rG   ccmaps     r"   <lambda>z!_buildencodefun.<locals>.<lambda>   s5    #((c!fF1D1q1u.FG Fs   <c                 D    dj                  t         |                   S Nr$   )rM   list)rG   rK   s    r"   rQ   z!_buildencodefun.<locals>.<lambda>   s    #((4q	?+ r$   )	r   bytechrrT   mapr9   r8   r<   loweritems)
exchrasciistrcapitalsr:   kvrP   rK   rJ   s
          @@@r"   _buildencodefunr_   u   s    0 	ADCeCj)*HE#d)SY]34H"#QAqD#D[ % 1T!W%Q  ,DGMMO+T!W, D

 1Q 	H+ / $s   "
C0c                 *    t        t        |             S )z~
    >>> encodefilename(b'foo.i/bar.d/bla.hg/hi:world?/HELLO')
    'foo.i.hg/bar.d.hg/bla.hg.hg/hi~3aworld~3f/_h_e_l_l_o'
    )_encodefnamer1   rG   s    r"   encodefilenamerc      s    
 	!%%r$   c                 *    t        t        |             S )z~
    >>> decodefilename(b'foo.i.hg/bar.d.hg/bla.hg.hg/hi~3aworld~3f/_h_e_l_l_o')
    'foo.i/bar.d/bla.hg/hi:world?/HELLO'
    )r3   _decodefnamerb   s    r"   decodefilenamerf      s    
 \!_%%r$   c                  L   t         j                  } t        d      D ci c]  } | |       | |       c}t               D ]  }d|z   | |      <    t        t	        d      t	        d      dz         D ]!  } | |      j                          | |      <   # fd}|S c c}w )z
    >>> f = _buildlowerencodefun()
    >>> f(b'nothing/special.txt')
    'nothing/special.txt'
    >>> f(b'HELLO')
    'hello'
    >>> f(b'hello:world?')
    'hello~3aworld~3f'
    >>> f(b'the\x07quick\xADshot')
    'the~07quick~adshot'
    r?   rB   r@   rA   r   c                 x    dj                  t        j                  |       D cg c]  }|   	 c}      S c c}w rS   )rM   r   iterbytestrrN   s     r"   lowerencodez)_buildlowerencodefun.<locals>.lowerencode   s/    xx(*>*>q*ABQaBCCBs   7)r   rU   r9   r<   r8   rW   )rZ   r:   rj   rP   s      @r"   _buildlowerencodefunrk      s     D&+Cj1DGT!W1D[ % 1T!W%3t9c$i!m, (QT!W(D  2s   B!rj   )s   auxs   cons   prns   nul)s   coms   lptc                    t        |       D ]  \  }}|s	|r$|d   dv rdt        |dd       z  |dd z   }|| |<   nu|j                  d      }|dk(  rt        |      }|dk(  r|dd t        v s |d	k(  r?|dd	 d
k  r7|dd	 dk\  r/|dd t
        v r$dt        |dd       z  }|dd |z   |dd z   }|| |<   |d   dv s|dd dt        |dd       z  z   | |<    | S )a  
    Encodes filenames containing names reserved by Windows or which end in
    period or space. Does not touch other single reserved characters c.
    Specifically, c in '\:*?"<>|' or ord(c) <= 31 are *not* encoded here.
    Additionally encodes space or period at the beginning, if dotencode is
    True. Parameter path is assumed to be all lowercase.
    A segment only needs encoding if a reserved name appears as a
    basename (e.g. "aux", "aux.foo"). A directory or file named "foo.aux"
    doesn't need encoding.

    >>> s = b'.foo/aux.txt/txt.aux/con/prn/nul/foo.'
    >>> _auxencode(s.split(b'/'), True)
    ['~2efoo', 'au~78.txt', 'txt.aux', 'co~6e', 'pr~6e', 'nu~6c', 'foo~2e']
    >>> s = b'.com1com2/lpt9.lpt4.lpt1/conprn/com0/lpt0/foo.'
    >>> _auxencode(s.split(b'/'), False)
    ['.com1com2', 'lp~749.lpt4.lpt1', 'conprn', 'com0', 'lpt0', 'foo~2e']
    >>> _auxencode([b'foo. '], True)
    ['foo.~20']
    >>> _auxencode([b' .foo'], True)
    ['~20.foo']
    r      . rB   r   N   .   rD      9   1   )	enumerater8   findrE   _winres3_winres4)r/   	dotencoderH   nrI   ecs         r"   
_auxencoder{      s$   , $ 6113q1v;&12.ADGtABwFQ1Ra5H,QaFdNaFdNbqEX% AaF+aFRK!AB%'QR5E>fx#af+55DG-6. Kr$   x      rD   c                 |   t        t        j                  |       j                               }t	        | dd        j                  d      }t        ||      }|d   }t        j                  j                  |      \  }}g }d}	|d d D ]Z  }
|
d t         }|d   dv r|d d dz   }|	dk(  rt        |      }n|	dz   t        |      z   }|t        kD  r n|j                  |       |}	\ dj                  |      }t        |      dkD  r|dz  }d|z   |z   |z   }t        t        |      z
  }|dkD  r|d | }d|z   |z   |z   |z   }|S )	N   r   ro   r   rm   r>   r   s   dh/)r   r   sha1digestrj   splitr{   osr/   splitext_dirprefixlenrE   _maxshortdirslenappendrM   _maxstorepathlen)r/   rx   r   lepartsbasename_rootextsdirssdirslenpdtdirsres	spaceleftfillers                    r"   _hashencoder     s^   t$++-.F	T!"X		$	$T	*Br9%ERyH!!(+JE3EH3BZ n}R5E>#2Aq=AA1s1v%A##Q 99UD
4y1}
4-&
 3
&C 3s8+I1}*9%tmf$v-3Jr$   c                     t        |       } t        |       j                  d      }dj                  t	        ||            }t        |      t        kD  rt        | |      }|S )ae  encodes path with a length limit

    Encodes all paths that begin with 'data/', according to the following.

    Default encoding (reversible):

    Encodes all uppercase letters 'X' as '_x'. All reserved or illegal
    characters are encoded as '~xx', where xx is the two digit hex code
    of the character (see encodefilename).
    Relevant path components consisting of Windows reserved filenames are
    masked by encoding the third character ('aux' -> 'au~78', see _auxencode).

    Hashed encoding (not reversible):

    If the default-encoded path is longer than _maxstorepathlen, a
    non-reversible hybrid hashing of the path is done instead.
    This encoding uses up to _dirprefixlen characters of all directory
    levels of the lowerencoded path, but not more levels than can fit into
    _maxshortdirslen.
    Then follows the filler followed by the sha digest of the full path.
    The filler is the beginning of the basename of the lowerencoded path
    (the basename is everything after the last path separator). The filler
    is as long as possible, filling in characters from the basename until
    the encoded path has _maxstorepathlen characters (or all chars of the
    basename have been taken).
    The extension (e.g. '.i' or '.d') is preserved.

    The string 'data/' at the beginning is replaced with 'dh/', if the hashed
    encoding was used.
    r   )r1   ra   r   rM   r{   rE   r   r   )r/   rx   efr   s       r"   _hybridencoder   7  sU    > T?D	d		!	!$	'B
))Jr9-
.C
3x""$	*Jr$   c                     t        |       }t        |       t        kD  rt        |d      S t	        |      j                  d      }dj                  t        |d            }t        |      t        kD  rt        |d      S |S )NTr   )r1   rE   r   r   ra   r   rM   r{   )r/   der   r   s       r"   _pathencoder   ^  sn    	4B
4y##2t$$	b				%B
))Jr4(
)C
3x""2t$$Jr$   
pathencodec                     t        | d      S NF)r   fs    r"   _plainhybridencoder   l  s    E""r$   c                     	 | j                         j                  }dt        j                   z  d|z  k(  rd }|S # t        $ r d }Y |S w xY w)Ni  )statst_moder   umaskOSError)r   modes     r"   	_calcmoder   p  sV    xxz!!TZZKUT\2D K  Ks   6: A	A	)	   bookmarks
   narrowspec   data   meta   00manifest.d   00manifest.i   00changelog.d   00changelog.i
   phaseroots   obsstore   requires)   .i   .idx   .d   .dat   .n   .nd   .sda)r   r   r   r   )r   r   s   .*undo\.[^/]+\.(nd?|i)$c                 X    |t         j                  k7  ry| j                  t              ryy)NFT)r   S_IFREGendswithREVLOG_FILES_EXT)r   kindsts      r"   	is_revlogr     s$    t||zz"#r$   c                 0    | j                  t              ryyNTF)r   r   r   s    r"   is_revlog_filer     s    zz"#r$   T)slotsc                       e Zd ZdZ ej
                         Z ej
                  d      Z ej
                  d      Zd Z	d Z
y)	StoreFileza file matching a store entryNdefaultFc                 2   | j                   _|&d}|| j                  z  }t        j                  |      	 |j	                  | j                        j
                  | _         | j                   S | j                   S # t        $ r d| _         Y | j                   S w xY w)Ns1   calling vfs-less file_size without prior call: %sr   )
_file_sizeunencoded_pathr   r   r   st_sizeFileNotFoundError)selfr   msgs      r"   	file_sizezStoreFile.file_size  s    ??"{Jt***,,S11$"%((4+>+>"?"G"G t % $"#$s   *A8 8BBc                 ~      j                  d       fd} |       }t        |        j                  |fS )zvreturn data "stream" information for this file

        (unencoded_file_path, content_iterator, content_size)
        Nc               3     K   j                  j                           } t        | d      5 }d  dk  r|j                         nt	        j
                  |      E d {    d d d        y 7 # 1 sw Y   y xY ww)Nrb   limit)rM   r   openreadr   filechunkiter)actual_pathfpcopiesr   sizer   s     r"   
get_streamz(StoreFile.get_stream.<locals>.get_stream  s      $*=*=!>?Kk4( BB
5=''$-'#11"DAAAB B
 BB Bs.   +B8A6&A4'A6+	B4A66A?;B)r   nextr   )r   r   r   r   rG   r   s   ```  @r"   r   zStoreFile.get_stream  s<    
 ~~d#	B LQ##Q--r$   )__name__
__module____qualname____doc__r   ibr   r   is_volatiler   r    r$   r"   r   r     s<    'TWWYN&J$''%(K
.r$   r   F)r   initc                   4    e Zd ZdZdee   fdZ	 	 	 	 	 ddZy)BaseStoreEntryzaAn entry in the store

    This is returned by `store.walk` and represent some data in the store.returnc                     t         N)NotImplementedErrorr   s    r"   fileszBaseStoreEntry.files  s    !!r$   Nc                 p    |J | j                         D cg c]  }|j                  ||       c}S c c}w )u   return a list of data stream associated to files for this entry

        return [(unencoded_file_path, content_iterator, content_size), …]
        )r   r   )r   repor   r   max_changesetpreserve_file_countr   s          r"   get_streamszBaseStoreEntry.get_streams  s3     37::<@aS&)@@@s   3NNNNF)r   r   r   r   r   r   r   r   r   r$   r"   r   r     s/    N"tI "
 !Ar$   r   c                        e Zd ZdZdZ ej                         Z ej                  d      Z ej                  d      Z	 ej                  d      Z
	 	 d fd	Zdee   fdZ xZS )	SimpleStoreEntryzA generic entry in the storeFr   Nc                 Z    t         |           || _        || _        || _        d | _        y r   )super__init___entry_path_is_volatiler   _files)r   
entry_pathr   r   	__class__s       r"   r   zSimpleStoreEntry.__init__  s.     	%'#r$   r   c                     | j                   2t        | j                  | j                  | j                        g| _         | j                   S )N)r   r   r   )r   r   r   r   r   r   s    r"   r   zSimpleStoreEntry.files  sB    ;;#'#3#3"oo $ 1 1DK {{r$   )FN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r  s   @r"   r   r     se    &I$'')K4775)L&JTWWT"F
 	
	tI 	r$   r   c                   H    e Zd ZdZdZ ej                  d      Z ej                  d      Z ej                  d      Z	 ej                  d      Z
 ej                  d      Z fdZed        Zed        Zed        Zd	 Zd
ee   fdZ	 	 	 	 	 d fd	Zd Z xZS )RevlogStoreEntryzA revlog entry in the storeTNr   c                     t         |           || _        || _        || _        d|v s	J ||f       || _        d | _        y )Nr   )r   r   revlog_typer   _path_prefix_detailsr   )r   r	  path_prefixr   detailsr  s        r"   r   zRevlogStoreEntry.__init__%  sM     	&"'7+w!77r$   c                 (    | j                   t        k(  S r   )r	  r
   r   s    r"   is_changelogzRevlogStoreEntry.is_changelog4  s    >11r$   c                 (    | j                   t        k(  S r   )r	  r   r   s    r"   r   zRevlogStoreEntry.is_manifestlog8  s    #333r$   c                 (    | j                   t        k(  S r   )r	  r   r   s    r"   r   zRevlogStoreEntry.is_filelog<  s    <//r$   c                      | j                   dz   S )z&unencoded path of the main revlog filer   )r
  r   s    r"   main_file_pathzRevlogStoreEntry.main_file_path@  s      5((r$   r   c                 6   | j                   g | _         t        | j                  t              D ]]  }| j                  |z   }| j                  |   }|j                  t              }t        |||      }| j                   j                  |       _ | j                   S )N)key)	r   sortedr  _ext_keyr
  r   REVLOG_FILES_VOLATILE_EXTr   r   )r   r   r/   r   volatiler   s         r"   r   zRevlogStoreEntry.filesD  s    ;;DKdmm: 
&((3. MM#.	 <<(ABdIx8""1%
& {{r$   c                    |:|8t        d | j                  j                         D              sd| j                  v rt        |   |||||      S |s| j                         D cg c]/  }|j                  j                  d      s|j                  ||      1 }}| j                  |      j                         }|j	                  |      }	|j                  |	       |S i }
| j                         D ]   }|j                  d       |
|j                  <   " | j                         D cg c]/  }|j                  j                  d      s|j                  ||      1 }}| j                  dz   }d 	  ||      j                  t        j                         }t"        j$                  j'                  |      r4|
|   fd} |       }t)        |       d |j+                  ||f       n| j                  |      j                         }|j	                  |d      }	|	D ]S  \  }}|
j-                  |d	      k7  st/        d
      }||
j-                  |d	      |fz  }t1        j2                  |       |j                  |	       j5                          	 | j                         }t7        |      t7        |      k(  sJ ||| j                  | j8                  f       |S c c}w c c}w # j5                          w w xY w)Nc              3   >   K   | ]  }|j                  d         yw)r   Nr   ).0r]   s     r"   	<genexpr>z/RevlogStoreEntry.get_streams.<locals>.<genexpr>`  s     E11::g&Es   r   )r   r   r   r   r   )r   r   r   c               3      K   } 	 | j                  d       d  dk  r| j                         nt        j                  |       E d {    | j	                          y 7 # | j	                          w xY ww)Nr   r   r   )seekr   r   r   close)r   
index_filer   s    r"   r   z0RevlogStoreEntry.get_streams.<locals>.get_stream  se     #B#
"
5="$''$-/'+'9'9"D'III
 J
s/   A<AA' A%A' A<%A' 'A99A<T)force_inliner   s(   expected %d bytes but %d provided for %s)anyr  keysr   r   r   r   r   r   get_revlog_instance
get_revlogextendr   r
  r   r	   r   	revlogmodr   is_inline_indexr   r   getr   r   Abortr!  rE   r   )r   r   r   r   r   r   r   streamrl	rl_streamname_to_size
index_pathheaderr   rG   namer   r   r"  r   r  s                     @@r"   r   zRevlogStoreEntry.get_streamsT  s    L$E0B0B0DEE%7&+$7 '   % ''00@ S&)F 
 ))$/::<B}5IMM)$M 	?A-.[[->L))*	?
 ZZ\
##,,U3 LLf%
 
 &&.

"	#ZJ__\%6%67F//7#J/
# LQ!
z1d34--d3>>@NN=tNL	%. /MD!T#''a0D8 KL|//a8$DD#kk#..	/
 i(%  "

6{c%j( 	
NN	+
 	
( E
T %  " &s    (4K (4K%0C
K* ;A
K* *K?c                 4   | j                   rt        j                  |j                        S | j                  r8| j                  }t        j                  |j                  |j                  |      S t        j                  |j                  | j                        S )zrObtain a revlog instance from this store entry

        An instance of the appropriate class is returned.
        )tree)	r  r   svfsr   r   r   manifestrevlognodeconstantsr   )r   r   mandirs      r"   r&  z$RevlogStoreEntry.get_revlog_instance  ss    
 &&tyy11  ^^F**""DIIF  ??499dnn==r$   r   )r   r   r   r   r   r   r   r	  r   r
  r  r   r   propertyr  r   r   r  r   r   r   r   r&  r  r  s   @r"   r  r    s    %I$''$'K%I4774(Ltwwt$HTWWT"F 2 2 4 4 0 0)tI $ !Zx>r$   r  c                     t        j                  t              }| D ]  \  }}t        |      \  }}|||   |<    t	        |j                               S )zgroup files per revlog prefix

    The returns a two level nested dict. The top level key is the revlog prefix
    without extension, the second level is all the file "suffix" that were
    seen for this revlog and arbitrary file data as value.
    )collectionsdefaultdictdict_split_revlog_extr  rX   )
files_datarevlogsuvaluer3  r   s         r"   _gather_revlogrD    sV     %%d+G #5%a(	c"c# '--/""r$   c                 l    | j                  t              rd}nd}| j                  |      }| d| | |d fS )z8split the revlog file prefix from the variable extension   -rn   N)r   REVLOG_FILES_LONG_EXTrfind)filenamecharidxs      r"   r?  r?    s@    ./
..
CDS>8CD>))r$   c                     | j                  d      rd| fS | j                  d      rd| fS | j                  d      rd| fS | j                  d      rd| fS d	| fS )
zJa key to order revlog suffix

    important to issue .i after other entry.r   r   r   
   r      r   2   (   r  )r   s    r"   r  r    se    
 ||E3x	f	Cy	e	Cy	e	CyCyr$   c                       e Zd ZdZd Zd ZddZddZd Z	 dde	e
ddf   fd	Z	 dde	e
ddf   fd
Z	 dde	e
ddf   fdZd Zd Zd Zd Zd Zy)
basicstorez&base class for local repository storesc                      ||      }|j                   | _        t        |      | _        | j                  |_        || _        t        j                  |t              | _        | j                  | _	        y r   )
baser/   r   
createmoderawvfsvfsmod	filtervfsr1   r   openerr   r/   vfstyper   s       r"   r   zbasicstore.__init__  sR    dmHH	#C.##C3hhr$   c                 8    | j                   dz   t        |      z   S Nr   )r/   r1   r   r   s     r"   rM   zbasicstore.join  s    yy4)A,..r$   Nc                 6   | j                   }|r|d|z   z  }t        | j                         dz   }g }| j                  j                  |      r|g}| j                  j                  }|r|j                         }	 ||	d      D ]  \  }
}}|	dz   |
z   }t        |
||      r?t        j                  ||d       }|j                  t        |      |j                  f       [|t        j                  k(  so|sr|j                  |        |r|j                          |S )z%yields (revlog_type, unencoded, size)r   r   T)r   N)r/   rE   rV  isdirreaddirpopr   r   pconvertr   r3   r   r   S_IFDIRsort)r   relpathrecurseundecodabler/   striplenrI   visitra  r   r   r   r   r   ry   s                  r"   _walkzbasicstore._walk  s    yyD7N"Dtyy>A%;;T"FEkk))GIIK#*14#8 )KAtRTAB D"- MM"XY-8)A,

!;<-'R()  	
r$   c                 F    t        j                   | j                  ||      S )N)
trypendingconcurrencychecker)r   r   )r   rm  rn  s      r"   r   zbasicstore.changelog  s"    ""HH!1
 	
r$   c                     t        j                  |j                  | j                        }t        j                  | j                  |||      S r   )r   r7  r8  r   manifestlog)r   r   storenarrowmatch	rootstores       r"   rp  zbasicstore.manifestlog  s:    ++D,>,>I	##DHHdI?OPPr$   r   c              #      K   dt         dfdt        dfg}|D ]s  \  }}}| j                  |d|      }t        |      D ]K  \  }}	|j	                  dd      d   }
|rd|v r|
j                  dd      d   }
|
dz  }
t        |||
|		       M u y
w)a4  Like walk, but excluding the changelog and root manifest.

        When [undecodable] is None, revlogs names that can't be
        decoded cause an exception. When it is provided, it should
        be a list and the filenames that can't be decoded are added
        to it instead. This is very rarely needed.r   Fr   Trh  r   r   r   r  r	  r   r  N)r   r   rk  rD  r   rsplitr  )r   r!   rh  r   base_dirrl_typestrip_filenamer   r   r  revlog_target_ids              r"   data_entrieszbasicstore.data_entries  s      lE*&-
 26 	-Hg~JJx;JGE#1%#8 
#)<<a#8#; !dfn'7'>'>tQ'G'J$$,$& & '.#	 
	s   BBc              #     K   |r*| j                   j                  d      rt        dd       |r*| j                   j                  d      rt        dd       t        | j	                  dd            }t        j                  t              }t        j                  t              }|D ]e  \  }}|j                  d      rt        |      \  }}	|||   |	<   .|j                  d      rt        |      \  }}	|||   |	<   Vt        |d|	       g |t        f|t        fg}
t        |      d
k  sJ t        |      d
k  sJ |
D ]7  \  }}t        |j                               D ]  \  }}t        ||d|        9 y w)Nr   T)r  r   r   r$   Fs   00changelogs
   00manifest)r  r   r   r   ru  )r   existsr   reversedrk  r<  r=  r>  
startswithr?  r   r
   rE   r  rX   r  )r   phaseobsolescencer   
changelogsmanifestlogsrB  rG   r3  r   top_rldatar	  r   r  s                  r"   top_entrieszbasicstore.top_entries5  s     TXX__]3"(  
 DHHOOK8"&  
 C/0 ,,T2
"..t4 	DAq||N+-a0	c()
4 %m,-a0	c*+T"3'&  % 	 +,(
 < A%%%:!###!' 	D+#)$**,#7 & & +!#	 	s   E=E?c              #   x   K   | j                  |      D ]  }|  | j                  ||      D ]  }|  yw)zreturn files related to data storage (ie: revlogs)

        yields instance from BaseStoreEntry subclasses

        if a matcher is passed, storage files of only those tracked paths
        are passed with matches the matcher
        )r  r  N)r{  r  )r   r!   r  r  r:   s        r"   walkzbasicstore.walkg  sK      ""7+ 	AG	!!L!I 	AG	s   8:c                     t         S r   _datar   s    r"   copylistzbasicstore.copylistw  s    r$   c                      y r   r   r   trs     r"   writezbasicstore.writez      r$   c                      y r   r   r   s    r"   invalidatecacheszbasicstore.invalidatecaches}  r  r$   c                      y r   r   r   fns     r"   markremovedzbasicstore.markremoved  r  r$   c                     dj                  d|f      }| j                  j                  |dz         ry|j                  d      s|dz   }| j                  j                  |      S )!Checks if the store contains pathr   r   r   T)rM   r   r}  r   r   r/   s     r"   __contains__zbasicstore.__contains__  sS    yy'4)88??4%<(}}T"$;Dxxt$$r$   r   NN)FF)NFF)r   r   r   r   r   rM   rk  r   rp  r   r   r{  r  r  r  r  r  r  r  r   r$   r"   rR  rR    s    0/.
Q
 )-	>4-	.8 ).0	>4-	.0f 7<	>4-	. 	%r$   rR  c                   R     e Zd Zd Zd fd	Z	 d	deeddf   f fdZd Zd Z	 xZ
S )
encodedstorec                      ||dz         }|j                   | _        t        |      | _        | j                  |_        || _        t        j                  |t              | _        | j                  | _	        y )N   /store)
rT  r/   r   rU  rV  rW  rX  rc   r   rY  rZ  s       r"   r   zencodedstore.__init__  sX    dY&'HH	#C.##C8hhr$   Nc                    t         
|   ||      }g }|D ]$  \  }}	 t        |      }|j                  ||f       & |S # t        $ r9 |#t	        d      |z  }	t        j                  |	      |j                  |       Y jw xY w)Ns   undecodable revlog name %s)r   rk  rf   rF   r   r   StorageErrorr   )r   rf  rg  rh  oldnewf1rC  f2r   r  s             r"   rk  zencodedstore._walk  s    gmGW- 
	$IB#B' JJE{#
	$ 
  &9:R?C,,S11&&r*s   ??B Br   c              #   f   K   t         t        |   |      }|D ]  }t        ||      s|  y w)Nrt  )r   r  r{  r#   )r   r!   rh  entriesr    r  s        r"   r{  zencodedstore.data_entries  sB      d8# 9 
  	E#E73	s   &11c                 8    | j                   dz   t        |      z   S r]  )r/   rc   r^  s     r"   rM   zencodedstore.join  s    yy4."333r$   c                 D    ddgt         D cg c]  }d|z   	 c}z   S c c}w )Nr   r      store/r  r^  s     r"   r  zencodedstore.copylist  s%    -.1OA)a-1OOO1Os   r   r  )r   r   r   r   rk  r   r   r{  rM   r  r  r  s   @r"   r  r    s6    " )-	>4-	.4Pr$   r  c                   L    e Zd Zd ZddZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zy)fncachec                 j    || _         t               | _        d | _        d| _        t               | _        y r   )r   set_ignoresr  _dirtyaddls)r   r   s     r"   r   zfncache.__init__  s)    U
r$   Nc                 @    | j                   | j                  |       yy)zread the fncache file if not already read.

        If the file on disk is corrupted, raise. If warn is provided,
        warn and keep going instead.N)r  _load)r   warns     r"   ensureloadedzfncache.ensureloaded  s    
 <<JJt  r$   c           	         d| _         	 | j                  dd      }t               | _        d}t        t        j                  |j                  t              d      D ]Y  }||z  }	 |j                  d      }| j                  j                  t        |d|dz          j                                ||dz   d }[ |r9t        d	      }|r ||dz          n t!        j"                  |t        d
            | j%                  ||       |j'                          y# t        $ r t               | _        Y yw xY w# t        $ r Y w xY w)z&fill the entries from the fncache fileF   fncache   rb)r   Nr$      
r   s$   fncache does not ends with a newlines3   use 'hg debugrebuildfncache' to rebuild the fncache)hint)r  r   IOErrorr  r  iter	functoolspartialr   fncache_chunksizerindexupdater3   
splitlines
ValueErrorr   r   r,  _checkentriesr!  )r   r  r   chunkrO   r   r   s          r"   r  zfncache._load  s:   	*51B ui''1BCSI 		AQJELL'##IeGa!en$=$H$H$JKa!eg		 ;<CS5[!kk/  	2t$

?  	5DL	   s$   D $AD3D0/D03	D?>D?c                     d| j                   v rj|j                  d       t        |      D ]J  \  }}|j                  d      rt	        d      |dz   z  }|r ||dz          7t        j                  |       yy)z-make sure there is no empty string in entriesr$   r   r  s!   invalid entry in fncache, line %dr   N)r  r   rt   r   r   r   r,  )r   r   r  ry   liner   s         r"   r  zfncache._checkentries  sq    $,,GGAJ$R= -4{{5)>?1q5IAQY#kk!n,- r$   c                    | j                   r| j                  J | j                  | j                  z  | _        t               | _        |j	                  d       | j                  ddd      }| j                  r6|j                  t        dj                  | j                        dz                |j                          d| _         | j                  r|j	                  d       | j                  ddd      }| j                  r6|j                  t        dj                  | j                        dz                |j                          d | _        t               | _        y y )Nr  s   wbT)r   
atomictempr  Fs   ab)
r  r  r  r  	addbackupr   r  r1   rM   r!  )r   r  r   s      r"   r  zfncache.write  s    ;;<<+++<<$**4DLDJLL$*5TBB||5::dll#;e#CDEHHJDK::LL$*5TBBzz5::djj#9E#ABCHHJDLDJ r$   c                 :    | j                   j                  |       y r   )r  addr  s     r"   	addignorezfncache.addignore  s    "r$   c                     || j                   v ry | j                  | j                          || j                  vr| j                  j	                  |       y y r   )r  r  r  r  r  r  s     r"   r  zfncache.add  sE    <<JJLT\\!JJNN2 "r$   c                     | j                   | j                          || j                  v r| j                  j                  |       y 	 | j                   j                  |       d| _        y # t
        $ r Y y w xY wNT)r  r  r  remover  rF   r  s     r"   r  zfncache.remove  sf    <<JJLJJb!	LL#DK 		s   "A+ +	A76A7c                 t    || j                   v ry| j                  | j                          || j                  v S r  )r  r  r  r  s     r"   r  zfncache.__contains__+  s3    <<JJLT\\!!r$   c                 ~    | j                   | j                          t        | j                   | j                  z        S r   )r  r  r  r  r   s    r"   __iter__zfncache.__iter__2  s-    <<JJLDLL4::-..r$   r   )r   r   r   r   r  r  r  r  r  r  r  r  r  r   r$   r"   r  r    s5    $L
-*
"/r$   r  c                   &    e Zd Zd ZddZd Zd Zy)_fncachevfsc                 `    t         j                  j                  | |       || _        || _        y r   )rW  proxyvfsr   r  encode)r   r   fncr  s       r"   r   z_fncachevfs.__init__9  s$      s+r$   c                    | j                  |      }|dvr|j                  d      s|j                  d      rt        |      ry| j                  j                  d u xrB | j
                  j                  |      xr% | j
                  j                  |      j                  }|s| j                  j                  |        | j
                  ||g|i |S )N)   rr     data/   meta/)
r  r  r   r  r  r   r}  r   r   r  )r   r/   r   argskwencodednotloads          r"   __call__z_fncachevfs.__call__>  s    ++d#%*dooh.Gt$ ll**d2  ( 3HHMM'*22    &txx3333r$   c                     |r*| j                   j                  | j                  |            S | j                   j                  |      S r   )r   rM   r  r  s     r"   rM   z_fncachevfs.joinR  s4    88==T!23388==&&r$   c                     |j                  d      s|j                  d      r| j                  j                  |       yy)z1generic hook point to lets fncache steer its stewr  r  N)r  r  r  r  s     r"   register_filez_fncachevfs.register_fileX  s1    ??8$(ALLT" )Br$   N)r  )r   r   r   r   r  rM   r  r   r$   r"   r  r  8  s    
4('#r$   r  c                   ^    e Zd Zd Zd Zd Z	 ddeeddf   fdZd Z	d Z
d	 Zd
 Zd Zd Zy)fncachestorec                 J   |rt         }nt        }|| _         ||dz         }|j                  | _        | j                  dz   | _        t        |      | _        | j                  |_        || _        t        |      }|| _	        t        |||      | _        | j                  | _        y )Nr  r   )r   r   r  rT  r/   pathsepr   rU  rV  r  r  r   rY  )r   r/   r[  rx   r  r   r  s          r"   r   zfncachestore.__init___  s     F'FdY&'HH	yy4'#C.clsC0hhr$   c                 >    | j                   | j                  |      z   S r   )r  r  r^  s     r"   rM   zfncachestore.joinp  s    ||dkk!n,,r$   c                 L    | j                   j                  |      j                  S r   )rV  r   r   r  s     r"   getsizezfncachestore.getsizes  s    {{%---r$   Nr   c              #     K   d | j                   D        }t        |      }|D ]  \  }}|j                  d      rt        }|j	                  dd      d   }nL|j                  d      r4t
        }|j	                  dd      d   }	|	j                  dd      d   dz   }nJ |       t        ||||      }
t        |
|      s|
  y w)Nc              3   <   K   | ]  }t        |      s|d f  y wr   )r   )r  r   s     r"   r  z,fncachestore.data_entries.<locals>.<genexpr>|  s     FqN14E!TFs   	r  r   r   r  r   ru  )	r  rD  r  r   r   r   rv  r  r#   )r   r!   rh  r   	by_revlogr   r  rx  rz  tmpr    s              r"   r{  zfncachestore.data_entriesv  s      GDLLF"5)	( 	OFG  *&#)<<a#8#; ""8,*ll4+A.#&::dA#6q#9D#@  %f$u$"#*	E $E73'	s   B;C>Cc                 @    d}ddg|D cg c]  }d|z   	 c}z   S c c}w )N)r   r   r   r   s   dhr  r   r   r   r   r   r   r   r   r   r  r   )r   r   r   s      r"   r  zfncachestore.copylist  s.    
 -.1KA)a-1KKK1Ks   c                 :    | j                   j                  |       y r   )r  r  r  s     r"   r  zfncachestore.write  s    2r$   c                 X    d | j                   _        t               | j                   _        y r   )r  r  r  r  r   s    r"   r  zfncachestore.invalidatecaches  s    # Ur$   c                 :    | j                   j                  |       y r   )r  r  r  s     r"   r  zfncachestore.markremoved  s    Br$   c                 h    | j                  |      }	 | j                  |       y# t        $ r Y yw xY wr   )r  r  r   )r   r   r   s      r"   _existszfncachestore._exists  s5    [[^	LL  		s   % 	11c                    dj                  d|f      }|dz   }|| j                  v r| j                  |      ry|j                  d      s|dz  }| j                  D ]'  }|j	                  |      s| j                  |      s' y y)r  r   r   r   TF)rM   r  r  r   r  )r   r/   rY   s      r"   r  zfncachestore.__contains__  s|    yy'4)5La}}T"DLD 	A||D!dll1o	 r$   r  )r   r   r   r   rM   r  r   r   r{  r  r  r  r  r  r  r   r$   r"   r  r  ^  sN    "-. )-	>4-	.:L$# r$   r  )Rr<  r  r   rer   typingr   r   i18nr   
thirdpartyr   noder   revlogutils.constantsr	   r
   r   r    r   r   r   r   r   r   r   r)  r   r   rW  utilsr   	importmodr   r  r#   r0   getattrr1   r3   r<   r_   ra   re   rc   rf   rk   rj   rv   rw   r{   r   r   r   r   r   r   r   r   r  r   rG  r  compileEXCLUDEDr   r   rG   r   r   r   r  rD  r?  r  rR  r  r  r  r  r  r   r$   r"   <module>r     sQ     	 	  "    
 
 
 
&

9
%  E"$ G[*5	$$7t -. l&&2 g}d3M7K7M ,-`  )*Q. @$N g|[9#		   , 
 2::12 d%. %. %.P dA A  A0 d~   D dc>~ c>  c>L#*"c% c%L(P: (PV{/ {/|##&// ##Lf: fr$   