
    6h]]                        S SK Jr  S SKrSSKJr  SSKJr  SSKJr  SSK	J
r
JrJrJrJrJr  S rSrSS jrSS	 jr\" S
5      r\" S5      r\" S5      r\" S5      r " S S5      rg)    )annotationsN   )_)short)
stringutil)errorpycompatrequirementsrevlogtransactionutilc                    U R                  5          [        X5      nUR                  5       sS S S 5        $ ! , (       d  f       g = fN)lockverifierverify)repolevelvs      2/usr/lib/python3/dist-packages/mercurial/verify.pyr   r      s(    	T!xxz 
s	   6
Ac                F    SU ;   a  U R                  SS5      n SU ;   a  M  U $ )Ns   //   /)replace)fs    r   	_normpathr   #   s)     1*IIeT" 1*H    sC   hint: run "hg debugrebuildfncache" to recover from corrupt fncache
s7   parent-directory manifest refers to unknown revision %ss1   warning: copy source of '%s' not in parents of %ss5   warning: %s@%s: copy source revision is nullid %s:%s
c                  n    \ rS rSrSS jrS rSS jrSS jrS rS r	S	 r
S
 r SS jrS rS rS rSrg)r   <   Nc                   UR                  5       U l        UR                  U l        UR                  5       U l        Uc  [
        nX l        [        5       U l        SU l	        SU l
        [        UR                  5      S:  U l        [        UR                  R                  S5      5      S:  U l        UR                  R"                  [$        R&                  :g  U l        [*        R,                  " UR                  5       R.                  5      U l        SU l        SU l        UR                  R7                  SS5      U l        SU l        g )Nr   r   Fs   verify	   skipflagsT)
unfilteredr   uinarrowmatchmatchVERIFY_DEFAULT_levelsetbadrevserrorswarningslen	changeloghaveclmanifestlog
getstoragehavemf_format_versionr   REVLOGV0revlogv1r   lrucachefunc__getitem__	lrugetctxrefersmffncachewarned	configint	skipflagswarnorphanstorefiles)selfr   r   s      r   __init__verifier.__init__=   s    OO%	''%%'
="Eu$..)A-$**55c:;a?66&//I**4??+<+H+HI"**9lC$(!r   c                j    U R                   R                  US-   5        U =R                  S-  sl        g)zrecord a "warning" level issue   
r   N)r"   warnr*   )r<   msgs     r   _warnverifier._warnQ   s$    S5[!r   c                    Ub!  U R                   R                  U5        SU-  nOSnSX4-  nU(       a  SX24-  nU R                  R                  SU-   S-   5        U =R                  S-  sl        g)	zrecord a "error" level issueNs   %d   ?   %s: %ss   %s@%s    r@   r   )r(   addr"   rA   r)   )r<   linkrevrB   filenames       r   _errverifier._errV   sj    LLW%goGG7.(h_,CTCZ%'(qr   c                    [         R                  " U5      nU(       d  [        R                  " U5      nU R	                  USX%4-  U5        g)z1record exception raised during the verify processrG   N)r   forcebytestrr	   bytereprrL   )r<   rJ   rB   instrK   fmsgs         r   _excverifier._excc   s<    &&t,$$T*D		'9{2H=r   c                p   [        U5      (       dA  U R                  (       d  U R                  (       a  U R                  U[	        S5      U-  5        gUR                  5       nUS   (       a"  U R                  S[	        S5      US   -  U5        US   (       a"  U R                  S[	        S5      US   -  U5        UR                  [        R                  :w  a0  U R                  (       d  U R                  [	        S5      U-  5        ggU R                  (       a  U R                  [	        S5      U-  5        gg)	zverify high level property of a revlog

- revlog is present,
- revlog is non-empty,
- sizes (index and data) are correct,
- revlog's format version is correct.
   empty or missing %sNr   s   data length off by %d bytesr   s   index contains %d extra bytess"   warning: `%s' uses revlog format 1s"   warning: `%s' uses revlog format 0)r+   r-   r0   rL   r   	checksizer1   r   r2   r3   rC   )r<   objnamerJ   ds        r   _checkrevlogverifier._checkrevlogj   s     3xxT[[DKKIIgq!784?@MMOQ4IIdA<=!DdKQ4IIdA>?!A$FM&//1==

1BCdJK !]]JJq>?$FG r   c                   UR                  UR                  U5      5      nUS:  d  U R                  (       Ga	  Xu;  Ga  US:  d#  U[        U R                  R
                  5      :  a  [        S5      nO[        S5      nU R                  SXU4-  U5        U(       a  U(       aT  [        U5      S:  aE   / nU H<  nU R                  U5      U   R                  5       U:X  d  M+  UR                  U5        M>     [        S5      nUSR                  [        [        R                  U5      5      -  nU R!                  U5        Sn UR#                  U5      u  pX;  aM  XR                  R$                  :w  a4  [        S5      ['        U	5      ['        U5      4-  nU R                  XxU5        X;  aM  XR                  R$                  :w  a4  [        S	5      ['        U
5      ['        U5      4-  nU R                  XxU5        X4;   a#  U R                  U[        S5      X$U   4-  U5        X$U'   U$ ! [         a     GN=f = f! [         a2  nU R)                  U[        S
5      ['        U5      -  X5         SnANvSnAff = f)a  verify a single revlog entry

arguments are:
- obj:      the source revlog
- i:        the revision number
- node:     the revision node id
- seen:     nodes previously seen for this revlog
- linkrevs: [changelog-revisions] introducing "node"
- f:        string label ("changelog", "manifest", or filename)

Performs the following checks:
- linkrev points to an existing changelog revision,
- linkrev points to a changelog revision that introduces this revision,
- linkrev points to the lowest of these changesets,
- both parents exist in the revlog,
- the revision is not duplicated.

Return the linkrev of the revision (or None for changelog's revisions).
r   s)   rev %d points to nonexistent changeset %ds(   rev %d points to unexpected changeset %dNr   s    (expected %s)rH   s   unknown parent 1 %s of %ss   unknown parent 2 %s of %ss   checking parents of %ss   duplicate revision %d (%d))rJ   revr-   r+   r   r,   r   rL   r6   filenodeappend	Exceptionjoinmapr	   bytestrrC   parentsnullidr   rS   )r<   rX   inodeseenlinkrevsr   lrrB   p1p2rQ   s               r   _checkentryverifier._checkentry   s   ( [['6dkkkb&8Avs499#6#677DECDIIdCb'M1-X*#%"*B#~~b1!4==?4G ( 3 #+
 )*tyyX%5%5x!@AA

3B		O[[&FB~"		(8(8"845rE$K8PP		"1%~"		(8(8"845rE$K8PP		"1% <IIb!9:ad_LaPT
	+ %   	OIIb!56tDdNN	Os1   4+H( #H( B7H9 (
H65H69
I5(I00I5c                ~   U R                   nUR                  nUR                  5       R                  S5      (       d  [        R
                  " [        S5      5      e[        R                  " U5      (       a  UR                  [        S5      5        UR                  (       d  U R                  (       d9  UR                  [        S5      U R                  =(       a    S=(       d    S-  5        U R                  5       u  p4U R                  U5      nAU R                  XE5        U R!                  XT5      u  pgU R"                  (       a  UR                  [        S5      5        SnOU R%                  5       nUR                  [        S5      ['        UR(                  5      Xv4-  5        U R*                  (       a'  UR                  [        S	5      U R*                  -  5        U R,                  (       a  UR                  [.        5        U R"                  (       a  UR                  [        S
5      U R"                  -  5        U R0                  (       a4  [        S5      n	U	[3        U R0                  5      -  n	UR                  U	5        U(       a7  UR                  [        S5      5        UR                  [        S5      U-  5        gg)zverify the content of the Mercurial repository

This method run all verifications, displaying issues as they are found.

return 1 if any error have been encountered, 0 otherwise.s   file:s$   cannot verify bundle or remote reposs-   abandoned transaction found - run hg recover
s!   repository uses revlog format %d
r   r   s1   not checking dirstate because of previous errors
s2   checked %d changesets with %d changes to %d files
s   %d warnings encountered!
s!   %d integrity errors encountered!
s+   (first damaged changeset appears to be %d)
s5   dirstate inconsistent with current parent's manifest
s   %d dirstate errors
)r   r"   url
startswithr   Abortr   r   has_abandoned_transactionrA   verboser3   status_verifychangelog_verifymanifest_crosscheckfiles_verifyfilesr)   _verify_dirstater+   r,   r*   r8   HINT_FNCACHEr(   min)
r<   r   r"   
mflinkrevsfilelinkrevs	filenodes
totalfilesfilerevisionsdirstate_errorsrB   s
             r   r   verifier.verify   s    yyWWxxz$$X..++a GHII0066GGAGHI::T]]II78==&Q+!- $(#8#8#: 
((4	l6$($5$5i$N!
;;GGAKLMO"335O 			DE4>>"M>?	
 ==GGA34t}}DEGGL!;;GGA;<t{{JK||GHs4<<((OP 12_DEr   c           
        U R                   nU R                  nU R                  nUR                  nUR	                  [        S5      5        0 n0 n0 nU R                  USS5        UR                  [        S5      [        S5      [        U5      S9nUR                  5          U H  n	UR                  U	5        UR                  U	5      n
U R                  XIXU	/S5         UR                  U
5      nUS   U R                  R                  :w  a+  UR                  US   / 5      R!                  U	5        SU l        US    H<  nU" U5      (       d  M  UR                  [%        U5      / 5      R!                  U	5        M>     M     S
S
S
5        UR-                  5         XV4$ ! [&         a;  nSU l        U R)                  U	[        S	5      [+        U
5      -  U5         S
nAGM8  S
nAff = f! , (       d  f       Ni= f)a  verify the changelog of a repository

The following checks are performed:
- all of `_checkrevlog` checks,
- all of `_checkentry` checks (for each revisions),
- each revision can be read.

The function returns some of the data observed in the changesets as a
(mflinkrevs, filelinkrevs) tuples:
- mflinkrevs:   is a { manifest-node -> [changelog-rev] } mapping
- filelinkrevs: is a { file-path -> [changelog-rev] } mapping

If a matcher was specified, filelinkrevs will only contains matched
files.
s   checking changesets
s	   changelogr      checkings
   changesetsunittotalT   s   unpacking changeset %sN)r"   r   r$   r,   rv   r   r[   makeprogressr+   readingupdaterh   rn   readrf   
setdefaultr`   r7   r   ra   rS   r   complete)r<   r"   r   r$   clr~   r   ri   progressrg   nchangesr   rQ   s                 r   rw   verifier._verifychangelog   s     WWyy

^^
		!,-.
"lA.??kN=!1T # 
 ZZ\"GGAJ  !lC
P ggajGqzTYY%5%55"--gaj"=DDQG(,$QZ 88(33IaL"ELLQO (  " 	''	 ! P$(DMIIa#<!=a!H$OOP \s=    =G#A,F.F<G#
G %/GG#G  G##
G1c                4   U R                   nU R                  nU R                  nU R                   R                  nUR	                  U5      n	U(       d$  U R                  R                  [        S5      5        0 n
0 n0 nSnU(       a:  UnU	R                  5       nUR                  U5        U(       a  UR                  5         U R                  (       a  U R                  U	R                  US5        UR                  [        S5      [        S5      [        U	5      S9nU	 GH  nU(       d  UR                  U5        U	R!                  U5      nU R#                  U	UUXR%                  U/ 5      U5      nUU;   a  UU	 OZU(       a+  [        S5      ['        U5      -  nU R)                  UUU5        O(U R)                  U[        S5      ['        U5      -  U5         UR%                  UU5      R+                  S	S
9nUR-                  5        H  u  nnnU(       d  U R)                  U[        S5      5        OUS:X  a  M2  U[/        U5      -   nUS:X  aP  UR1                  U5      (       d  M^  UR3                  US-   0 5      nUR3                  U/ 5      R5                  U5        M  U" U5      (       d  M  U
R3                  U0 5      R3                  UU5        M     U R:                  [<        :  d  GM   UR%                  UU5      R?                  5       nGM     U(       d  URA                  5         U RB                  (       a  U VVs/ s H  nUU     H  nUU4PM	     M     nnn[E        U5       H^  u  nnU(       a%  U R)                  U[F        ['        U5      -  U5        M2  [        S5      nU['        U5      -  nU R)                  UUU5        M`     U(       Gdx  U(       Gap  U R                  R                  [        S5      5        [I        5       n[I        5       nU RJ                  n/ n URL                  RO                  U S9 H  n!U!R                  5        H  n"U"RP                  nU"RS                  URL                  RT                  5      n#U#S:  d	  U(       a  MC  URW                  S5      (       d  M[  URY                  [/        U5      5        URY                  [Z        R\                  R_                  U5      5        M     M     U  H!  nU R)                  S[        S5      U-  5        M#     UR                  [        S5      [        S5      [        U5      S9nURa                  5        HT  u  n$n%U Rc                  U%U$X45      n&U&Ra                  5        H'  u  nn'U
R3                  U0 5      R                  U'5        M)     MV     U(       d\  U(       aU  Uc   eURA                  5         U Rd                  (       a/  [E        U5       H   nU Rg                  [        S5      U-  5        M"     U
$ ! [6         a4  nU R9                  U[        S5      ['        U5      -  UU5         SnAGN{SnAff = f! [6         a7  n[        S5      ['        U5      -  nU R9                  UUUU5         SnAGMp  SnAff = fs  snnf )a  verify the manifestlog content

Inputs:
- mflinkrevs:     a {manifest-node -> [changelog-revisions]} mapping
- dir:            a subdirectory to check (for tree manifest repo)
- storefiles:     set of currently "orphan" files.
- subdirprogress: a progress object

This function checks:
* all of `_checkrevlog` checks (for all manifest related revlogs)
* all of `_checkentry` checks (for all manifest related revisions)
* nodes for subdirectory exists in the sub-directory manifest
* each manifest entries have a file path
* each manifest node refered in mflinkrevs exist in the manifest log

If tree manifest is in use and a matchers is specified, only the
sub-directories matching it will be verified.

return a two level mapping:
    {"path" -> { filenode -> changelog-revision}}

This mapping primarily contains entries for every files in the
repository. In addition, when tree-manifest is used, it also contains
sub-directory entries.

If a matcher is provided, only matching paths will be included.
s   checking manifests
s   manifestr   r   s	   manifestsr   s#   %s not in parent-directory manifests   %s not in changesetsT)shallows   entry without name in manifests	   /dev/null   tr   s   reading delta %sNs   reading full manifest %ss'   changeset refers to unknown revision %ss   checking directory manifests
undecodables   meta/   cannot decode filename '%s'   warning: orphan data file '%s')4r   r"   r$   r.   r/   rv   r   filesdifference_update	incrementr7   r[   _revlogr   r+   r   rh   rn   getr   rL   read_delta_new_entriesiterentriesr   visitdirr   r`   ra   rS   r&   VERIFY_FULLr   r   r0   sortedWARN_PARENT_DIR_UNKNOWN_REVr'   r3   storedata_entriesunencoded_path	file_sizevfsrr   rI   ospathdirnameitemsrx   r;   rC   )(r<   r~   dir
storefilessubdirprogressr   r"   r$   mflmfr   subdirnodesri   labelrevlogfilesr   rg   r   rk   rB   mfdeltar   fnflfullpathsdnrQ   mcchangesetpairssubdirsr3   r   entryfile_sizesubdirrj   subdirfilenodesonefilenodess(                                           r   rx   verifier._verifymanifest&  sf   < yyWW

ii##^^C GGNN1456	E((*K((5((*== bjj%3??kN<B # 
 A"
A!!"aD..B2GOBJqM>?%(J		"c5)		"a 7858CUKN''#q/@@@N!(!4!4!6IAr2		"a(I&JKl* "Yq\1HTz$~~h77$)44X_bIr2.55b9$X$!,,Xr:EEb"M "7" {{k)4 "ggc1o224GK T ;; /9Pj*Q-Qq!f-fjNP~.1IIa!<uQx!GOFGC58OCIIae, / {GGNN1>?@JeG}}HK00[0I"[[]E,,A ??4::>>:Dqall86L6L"y|4BGGOOA$67 + J !		$"@ AA EF !__+Q|_CL - N !, 1 1 3FH"22&*O $3#8#8#:<$$Q+22<@ $;	 !4 {!---##%((
+AJJq!BCaGH , y  N		"a 34uQx?uMMN ! 47858CCIIb#tU334 Qs7   C:X% Y7Z
Y)YY
Z+ZZc                *   U R                   nU R                  nUR                  [        S5      5        [	        U5      [	        U5      -   nUR                  [        S5      [        S5      US9nU R                  (       aL  [        U5       H=  nUR                  5         Xr;  d  M  X   S   nU R                  U[        S5      U5        M?     U R                  (       a  [        U5       H  nUR                  5         Xq;  d  M   UR                  U5      n	[        X'    V
s/ s H"  oR                  U	R                  U
5      5      PM$     sn
5      nU R                  U[        S5      U5        M     UR!                  5         g s  sn
f ! [         a    S n NDf = f)Ns0   crosschecking files in changesets and manifests
s   crosschecking   filesr   r   s    in changeset but not in manifests    in manifest but not in changeset)r   r"   rv   r   r+   r   r0   r   r   rL   r-   filer}   rJ   r^   ra   r   )r<   r   r   r   r"   r   r   r   rk   r   r   s              r   ry   verifier._crosscheckfiles  sO   yyWW
		!HIJL!C	N2??ak # 
 ;;L)""$%%+BIIb!$G"H!L	 * ;;I&""$("!YYq\ !NA**RVVAY"7!NO IIb!$G"H!L ' 	 "O$ "!"s$   F)E>
F>FFFc                  ^& U R                   nU R                  nU R                  nU R                  nU R                  nUR                  [        S5      5        [        5       n/ n	UR                  R                  U	S9 H  n
U
R                  5        Hu  nUR                  UR                  R                  5      nUR                  nUS:  d	  U(       a  MC  UR                  S5      (       d  M[  UR                  [!        U5      5        Mw     M     U	 H!  nU R#                  S [        S5      U-  5        M#     U R                   R$                  R&                  U R(                  UR+                  SS5      S:H  S	.n[-        [        U5      [        U5      -  5      nSnUR/                  [        S
5      [        S5      [1        U5      S9n[3        U5       GH  u  nnUR5                  UUS9   X-   nU(       a  US   nOS n UR9                  U5      nUR                  5        H  n UR?                  U5        M     [1        U5      (       dA  U RF                  (       d  U R                  (       a  U R#                  U[        S5      U-  5        O[        5       US'   [        5       US'   URI                  U5       H  nURJ                  b+  URM                  URO                  URJ                  5      5      nOS nURP                  (       a  U RC                  URP                  5        Mk  UR:                  (       a&  Ub  UOUnU R#                  UUR:                  U5        M  [:        RR                  " SURT                  -  5      e   0 nU GH  nUS-  nURK                  U5      nU RW                  UUUUUU5      nX;   a=  U(       a1  UX   ;  a)  U R#                  U[        S5      [Y        U5      -  U5        OX   U	 UUS   ;   a  UUS   ;  a  M   UR[                  U5      m&T&(       Ga  Ub[  UR\                  (       aJ  U" U5      n[_        U&4S jURa                  5        5       5      (       d  U RC                  [b        UU4-  5        UR9                  T&S   5      n[1        U5      (       d5  [        S5      n U R#                  UU T&S   [Y        T&S   5      4-  U5        GMW  T&S   U R                   Rd                  :X  a2  [f        nUUUT&S   [Y        T&S   5      4-  nURi                  U5        GM  URO                  T&S   5        GM  GM     X;   d  GMw  X   Ro                  5        V"V#s/ s H
  u  n"n#U#U"4PM     n$n"n#[-        U$5       H0  u  nn%[        S5      nU R#                  UU[Y        U%5      -  U5        M2     GM     URq                  5         U R@                  (       a/  [-        U5       H   nU RC                  [        S5      U-  5        M"     [1        U5      U4$ ! [6         a    / n GN4f = f! [:        R<                   a+  nU R#                  U[        S5      U-  U5         S nAGM  S nAff = f! [6         a@    U R@                  (       a*  [        S5      nU RC                  UU-  5        SU l"         GM   GM  f = f! [j         a5  n!U Rm                  U[        S5      [Y        U5      -  U!U5         S n!A!GMp  S n!A!ff = fs  sn#n"f )Ns   checking files
r   r   s   data/r   s   censors   policys   abort)s   expectedversionr    s   erroroncensoredr   r   r   )items   broken revlog! (%s)s%    warning: revlog '%s' not in fncache!TrV   s   skipreads   safe_renameds<   problem instance does not set warning or error attribute: %sr   s   %s not in manifestsc              3  4   >#    U  H  nTS    U;   v   M     g7f)r   N ).0pctxrps     r   	<genexpr>(verifier._verifyfiles.<locals>.<genexpr>C  s     &Or!u}s   s)   empty or missing copy source revlog %s:%ss   checking rename of %ss&   manifest refers to unknown revision %sr   )9r   r"   r6   r3   r0   rv   r   r'   r   r   r   r   r   r   rr   rI   r   rL   r,   r1   r:   configr   r   r+   	enumerater   KeyErrorr   r   StorageErrorremover;   rC   r8   r-   verifyintegrityrh   rJ   r^   warningProgrammingErrorrB   rn   r   renamedru   anyre   WARN_UNKNOWN_COPY_SOURCErf   WARN_NULLID_COPY_SOURCEnotera   rS   r   r   )'r<   r   r   r   r"   r6   r3   r0   r   r   r   r   r   r   stater   	revisionsr   rg   rj   rk   r   effrB   problemrJ   linkrev_msgri   r   ctxfl2r   rQ   kr   fnsrh   r   s'                                         @r   rz   verifier._verifyfiles  s   yyWWNN	==
		!'()U
ZZ,,,EEtzz~~6((1HHH!,,x2H2HNN9Q<0	 ' F AIIdA<=AB 
 !%		 3 3 C C.. "		)Y ?8 K
 s9~L(99:	??kN8CJ # 
 e$DAqOOAAO&'?
 a[YYq\
 hhj2%%b) ! r77t{{		"a 67!;< &)Uk"),o&!11%8G||/"$**RVVGLL-A"B"&

7??3 181Dg"		+w}}a@#44-/6{{;   9" DQ	GGAJ%%b!QhB>!9<"7		"a(>&?58&LaP%LOk**qo8N/N
 AB>bjj"+B-C#&&O&O#O#O $

+Cq#h+N O"ii1."3xx !"N OA IIb!r!ueBqEl.C*CQGUdii&6&66"9CAr2a5%1,#??CGGCLGGBqEN ) R ~*3,*<*<*>?*>$!Q1v*>? &sHBEFCIIb#d"3Q7 !,A %F 	$$J'

1>?!CD ( 5z9$$K   %% 		"a 67!;Q?   200 HI

38,-1** 12D ! IIA67%(BD!  @si   &X:X"Y$CZ1AZ1!Z1[3XX"Y!6YY!$AZ.-Z.1
[0;)[++[0c                   U R                   nU R                  nUR                  [        S5      5        UR                  R                  5       u  p4X   R                  5       nX   R                  5       nSn[        R                  UR                  ;   nU(       a  UR                  5       OSn	UR                  R                  XVX95       H  n
UR                  U
5        US-  nM     U(       a  U =R                  U-  sl        U$ )z@Check that the dirstate is consistent with the parent's manifests   checking dirstate
r   Nr   )r   r"   rv   r   dirstatere   manifestr
   NARROW_REQUIREMENTr#   r   r   r)   )r<   r   r"   parent1parent2m1m2r   	is_narrownarrow_matchererrs              r   r{   verifier._verify_dirstateb  s    yyWW
		!*+,==002]##%]##% 33t7H7HH	/8))+d==''HCHHSMq O I KK?*Kr   )r&   r(   r)   r8   r-   r0   r6   r$   r7   r   r3   r:   r"   r*   r;   r   )r   NN)__name__
__module____qualname____firstlineno__r=   rC   rL   rS   r[   rn   r   rw   rx   ry   rz   r{   __static_attributes__r   r   r   r   r   <   sM    )(
>H08t7r/(d DHRh:I%Vr   r   r   )r   bytesreturnr   )
__future__r   r   i18nr   rh   r   utilsr    r   r	   r
   r   r   r   r%   r   r   r   r|   r   r   r   r   r   r   r   <module>r     s    # 	      K  >  8  = 
z zr   