
    q&f]                         d dl 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mZmZ d ZdZddZd Z ed	      Z ed
      Z ed      Z ed      Z G d d      Zy)    N   )_)short)
stringutil)errorpycompatrequirementsrevlogtransactionutilc                     | j                         5  t        | |      }|j                         cd d d        S # 1 sw Y   y xY wN)lockverifierverify)repolevelvs      2/usr/lib/python3/dist-packages/mercurial/verify.pyr   r      s5    	 T5!xxz  s	   7A c                 <    d| v r| j                  dd      } d| v r| S )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                   ^    e Zd ZddZd ZddZddZd Zd Zd Z	d	 Z
	 dd
Zd Zd Zd Zy)r   Nc                    |j                         | _        |j                  | _        |j                         | _        |t
        }|| _        t               | _        d| _	        d| _
        t        |j                        dkD  | _        t        |j                  j                  d            dkD  | _        |j                  j"                  t$        j&                  k7  | _        t+        j,                  |j                         j.                        | _        d| _        d| _        |j                  j7                  dd      | _        d| _        y )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__zverifier.__init__<   s    OO%	''%%'
="Eu$..)A-$**55c:;a?66&//I**4??+<+H+HI"**9lC$(!r   c                 j    | j                   j                  |dz          | xj                  dz  c_        y)zrecord a "warning" level issue   
r   N)r    warnr(   )r:   msgs     r   _warnzverifier._warnP   s$    S5[!r   c                     |!| j                   j                  |       d|z  }nd}d||fz  }|rd||fz  }| j                  j                  d|z   dz          | xj                  dz  c_        y)	zrecord a "error" level issueNs   %d   ?   %s: %ss   %s@%s    r=   r   )r&   addr    r>   r'   )r:   linkrevr?   filenames       r   _errzverifier._errU   sn    LLW%goGG7C.(h_,CTCZ%'(qr   c                     t        j                  |      }|st        j                  |      }| j	                  |d||fz  |       y)z1record exception raised during the verify processrC   N)r   forcebytestrr   bytereprrH   )r:   rF   r?   instrG   fmsgs         r   _exczverifier._excb   s>    &&t,$$T*D		'9T{2H=r   c                 (   t        |      s7| j                  s| j                  r| j                  |t	        d      |z         y|j                         }|d   r"| j                  dt	        d      |d   z  |       |d   r"| j                  dt	        d      |d   z  |       |j                  t        j                  k7  r+| j                  s| j                  t	        d      |z         yy| j                  r| j                  t	        d      |z         yy)	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+   r.   rH   r   	checksizer/   r
   r0   r1   r@   )r:   objnamerF   ds        r   _checkrevlogzverifier._checkrevlogi   s     3xT[[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                    |j                  |j                  |            }|dk  s| j                  r||vr|dk  s"|t        | j                  j
                        k\  rt        d      }nt        d      }| j                  d|||fz  |       |r|rPt        |      dkD  rB	 g }|D ]9  }| j                  |      |   j                         |k(  s)|j                  |       ; 	 t        d      }|dj                  t        t        j                  |            z  }| j!                  |       d}	 |j#                  |      \  }	}
|	|vrN|	| j                  j$                  k7  r5t        d      t'        |	      t'        |      fz  }| j                  |||       |
|vrN|
| j                  j$                  k7  r5t        d	      t'        |
      t'        |      fz  }| j                  |||       ||v r$| j                  |t        d      |||   fz  |       |||<   |S # t        $ r Y >w xY w# t        $ r3}| j)                  |t        d
      t'        |      z  ||       Y d}~vd}~ww xY w)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)rD   s   unknown parent 1 %s of %ss   unknown parent 2 %s of %ss   checking parents of %ss   duplicate revision %d (%d))rF   revr+   r)   r   r*   r   rH   r4   filenodeappend	Exceptionjoinmapr   bytestrr@   parentsnullidr   rN   )r:   rR   inodeseenlinkrevsr   lrr?   p1p2rL   s               r   _checkentryzverifier._checkentry   s2   ( [['6dkkb&8Avs499#6#677DECDIIdC1b'M1-X*#%"* 4B#~~b1!4==?4G ( 34
 )*tyyX%5%5x!@AA

3B		O[[&FB~"		(8(8"845rE$K8PP		"c1%~"		(8(8"845rE$K8PP		"c1% 4<IIb!9:ad_LaPT
	+ %   	OIIb!56tDdANN	Os1   ,H H +B8H" 	HH"	I+)IIc                    | j                   }|j                  }|j                         j                  d      st	        j
                  t        d            t        j                  |      r|j                  t        d             |j                  s| j                  s/|j                  t        d      | j                  xr dxs dz         | j                         \  }}| j                  |      }~| j                  ||       | j!                  ||      \  }}| j"                  r|j                  t        d             d}n| j%                         }|j                  t        d      t'        |j(                        ||fz         | j*                  r'|j                  t        d	      | j*                  z         | j,                  r|j                  t.               | j"                  r|j                  t        d
      | j"                  z         | j0                  r4t        d      }	|	t3        | j0                        z  }	|j                  |	       |r7|j                  t        d             |j                  t        d      |z         yy)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_transactionr>   verboser1   status_verifychangelog_verifymanifest_crosscheckfiles_verifyfilesr'   _verify_dirstater)   r*   r(   r6   HINT_FNCACHEr&   min)
r:   r   r    
mflinkrevsfilelinkrevs	filenodes
totalfilesfilerevisionsdirstate_errorsr?   s
             r   r   zverifier.verify   s    yyWWxxz$$X.++a GHII006GGAGHI::T]]II78==&Q+!- $(#8#8#: 
L((4	lI6$($5$5i$N!
M;;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           
         | j                   }| j                  }| j                  }|j                  }|j	                  t        d             i }i }i }| j                  |dd       |j                  t        d      t        d      t        |            }|j                         5  |D ]  }	|j                  |	       |j                  |	      }
| j                  ||	|
||	gd       	 |j                  |
      }|d   | j                  j                  k7  r+|j                  |d   g       j!                  |	       d| _        |d   D ]5  } ||      s|j                  t%        |      g       j!                  |	       7  	 d
d
d
       |j-                          ||fS # t&        $ r:}d| _        | j)                  |	t        d	      t+        |
      z  |       Y d
}~/d
}~ww xY w# 1 sw Y   cxY w)aI  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*   rn   r   rU   makeprogressr)   readingupdatera   rg   readr_   
setdefaultrY   r5   r   rZ   rN   r   complete)r:   r    r   r"   clrv   rw   rb   progressr`   nchangesr   rL   s                 r   ro   zverifier._verifychangelog   s     WWyy

^^
		!,-.
"lA.??kN=!1T # 
 ZZ\ 	P P"GGAJ  Q4!lC
P ggajGqzTYY%5%55"--gaj"=DDQG(,$QZ P 8(33IaL"ELLQOPP	P" 	<''	 ! P$(DMIIa#<!=a!H$OOP	P 	Ps=   #?G#A(F,F8G	G /GGGGG&c                 @   | j                   }| j                  }| j                  }| j                   j                  }|j	                  |      }	|s$| j                  j                  t        d             i }
i }i }d}|r5|}|	j                         }|j                  |       |r|j                          | j                  r| j                  |	j                  |d       |j                  t        d      t        d      t        |	            }|	D ]  }|s|j                  |       |	j!                  |      }| j#                  |	||||j%                  |g       |      }||v r||= nU|r+t        d      t'        |      z  }| j)                  |||       n(| j)                  |t        d      t'        |      z  |       	 |j%                  ||      j+                  d	
      }|j-                         D ]  \  }}}|s| j)                  |t        d             n|dk(  r+|t/        |      z   }|dk(  rI|j1                  |      sP|j3                  |dz   i       }|j3                  |g       j5                  |        ||      s|
j3                  |i       j3                  ||        	 | j:                  t<        k\  s	 |j%                  ||      j?                         } |s|jA                          | jB                  r|D cg c]  }||   D ]  }||f  }}}tE        |      D ]W  \  }}|r$| j)                  |tF        t'        |      z  |       ,t        d      }|t'        |      z  }| j)                  |||       Y |sf|rc| j                  j                  t        d             tI               }tI               }| jJ                  }g } |jL                  jO                  |       D ]  }!|!j                         D ]  }"|"jP                  }|"jS                  |jL                  jT                        }#|#dkD  s|r<|jW                  d      sN|jY                  t/        |             |jY                  tZ        j\                  j_                  |               | D ]   }| j)                  dt        d      |z         " |j                  t        d      t        d      t        |            }|ja                         D ]R  \  }$}%| jc                  |%|$||      }&|&ja                         D ]&  \  }}'|
j3                  |i       j                  |'       ( T |sO|rM|J |jA                          | jd                  r-tE        |      D ]  }| jg                  t        d      |z         ! |
S # t6        $ r4}| j9                  |t        d      t'        |      z  ||       Y d}~2d}~ww xY w# t6        $ r6}t        d      t'        |      z  }| j9                  ||||       Y d}~d}~ww xY wc c}}w )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-   rn   r   filesdifference_update	incrementr5   rU   _revlogr   r)   r   ra   rg   getr   rH   	readdeltaiterentriesr   visitdirr   rY   rZ   rN   r$   VERIFY_FULLr   r   r.   sortedWARN_PARENT_DIR_UNKNOWN_REVr%   r1   storedata_entriesunencoded_path	file_sizevfsrj   rE   ospathdirnameitemsrp   r9   r@   )(r:   rv   dir
storefilessubdirprogressr   r    r"   mflmfrx   subdirnodesrb   labelrevlogfilesr   r`   r   rd   r?   mfdeltar   fnflfullpathsdnrL   mcchangesetpairssubdirsr1   r   entryfile_sizesubdirrc   subdirfilenodesonefilenodess(                                           r   rp   zverifier._verifymanifest%  s   < yyWW

ii##^^C GGNN1456	E((*K((5((*== bjj%3??kN<B # 
  (	4A"
A!!"aD*..B2GOBJqM>?%(J		"c5)		"a 7858CUKN''#q/33D3A!(!4!4!6 NIAr2		"a(I&JKl* "Yq\1HTz$~~h7$)44X_bIr2.55b9$X$!,,Xr:EEb"MN" {{k)4 "ggc1o224GK(	4T ;; /9P*Q-PQq!fPfPNP~. -1IIa!<uQx!GOFGC58OCIIae,- {GGNN1>?@JeG}}HK00[0I 8"[[] 8E,,A ??4::>>:Dqall86L"y|4BGGOOA$6788 ! G		$"@ AA EFG__+Q|_CL - N !, 1 1 3 	AFH"22&*nO $3#8#8#: A<$$Q+22<@A		A {!---##%((
+ IAJJq!BCaGHI y  N		"a 34uQx?uMMN ! 47858CCIIb#tU334 Qs7   7C&V4 W:X	W!)WW	X!+XXc                 
   | j                   }| j                  }|j                  t        d             t	        |      t	        |      z   }|j                  t        d      t        d      |      }| j                  rIt        |      D ];  }|j                          ||vs||   d   }| j                  |t        d      |       = | j                  rt        |      D ]  }|j                          ||vs	 |j                  |      }	t        ||   D 
cg c]"  }
|	j                  |	j                  |
            $ c}
      }| j                  |t        d      |        |j!                          y c c}
w # t        $ r d }Y Aw xY w)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    rn   r   r)   r   r.   r   r   rH   r+   fileru   rF   rW   rZ   r   )r:   rw   rx   r   r    r   r   r   rd   r   r   s              r   rq   zverifier._crosscheckfiles  sc   yyWW
		!HIJL!C	N2??ak # 
 ;;L) M""$I%%a+BIIb!$G"H!L	M ;;I& M""$L("!YYq\ 1!NA"**RVVAY"7!NO IIb!$G"H!LM 	 "O$ "!"s$   5E4'E/
9E4/E44FFc                    & | j                   }| j                  }| j                  }| j                  }| j                  }|j                  t        d             t               }g }	|j                  j                  |	      D ]|  }
|
j                         D ]g  }|j                  |j                  j                        }|j                  }|dkD  s|r<|j                  d      sN|j                  t!        |             i ~ |	D ]   }| j#                  d t        d      |z         " | j                   j$                  j&                  | j(                  |j+                  dd      dk(  d	}t-        t        |      t        |      z        }d}|j/                  t        d
      t        d      t1        |            }t3        |      D ]  \  }}|j5                  ||       	 ||   }|r|d   }nd }	 |j9                  |      }|j                         D ]  }	 |j?                  |        t1        |      s7| jF                  s| j                  r| j#                  |t        d      |z         nt               |d<   t               |d<   |jI                  |      D ]  }|jJ                  +|jM                  |jO                  |jJ                              }nd }|jP                  r| jC                  |jP                         d|j:                  r$||n|}| j#                  ||j:                  |       t;        jR                  d|jT                  z         i }|D ]  }|dz  }|jK                  |      }| jW                  ||||||      }||v r8|r0|||   vr)| j#                  |t        d      tY        |      z  |       n||   |= ||d   v r||d   vr{	 |j[                  |      &&r|P|j\                  rD ||      }t_        &fd|ja                         D              s| jC                  tb        ||fz         |j9                  &d         }t1        |      s3t        d      } | j#                  || &d   tY        &d         fz  |       n`&d   | j                   jd                  k(  r0tf        }|||&d   tY        &d         fz  }|ji                  |       n|jO                  &d           ||v s(||   jo                         D "#cg c]	  \  }"}#|#|"f }$}"}#t-        |$      D ]/  \  }}%t        d      }| j#                  ||tY        |%      z  |       1  |jq                          | j@                  r-t-        |      D ]  }| jC                  t        d      |z         ! t1        |      |fS # t6        $ r g }Y w xY w# t:        j<                  $ r*}| j#                  |t        d      |z  |       Y d }~/d }~ww xY w# t6        $ r6 | j@                  r&t        d      }| jC                  ||z         d| _"        Y )w xY w# tj        $ r4}!| jm                  |t        d      tY        |      z  |!|       Y d }!~!&d }!~!ww xY wc c}#}"w )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!TrP   s   skipreads   safe_renameds<   problem instance does not set warning or error attribute: %sr   s   %s not in manifestsc              3   ,   K   | ]  }d    |v   yw)r   N ).0pctxrps     r   	<genexpr>z(verifier._verifyfiles.<locals>.<genexpr>B  s     &Or!u}&Os   s)   empty or missing copy source revlog %s:%ss   checking rename of %ss&   manifest refers to unknown revision %sr   )9r   r    r4   r1   r.   rn   r   r%   r   r   r   r   r   r   rj   rE   r   rH   r*   r/   r8   configr   r   r)   	enumerater   KeyErrorr   r   StorageErrorremover9   r@   r6   r+   verifyintegrityra   rF   rW   warningProgrammingErrorr?   rg   r   renamedrm   anyr^   WARN_UNKNOWN_COPY_SOURCEr_   WARN_NULLID_COPY_SOURCEnoterZ   rN   r   r   )'r:   rx   rw   r   r    r4   r1   r.   r   r   r   r   r   r   stater   	revisionsr   r`   rc   rd   r   effr?   problemrF   linkrev_msgrb   r   ctxfl2r   rL   kr   fnsra   r   s'                                         @r   rr   zverifier._verifyfiles  s
   yyWWNN	==
		!'()U
ZZ,,,E 	1E 1tzz~~6((1HH!,,x2HNN9Q<0	1	1  	CAIIdA<=AB	C
 !%		 3 3 C C.. "		)Y ?8 K
 s9~L(99:	??kN8CJ # 
 e$ b	8DAqOOAAO&'?
 a[YYq\
 hhj 22%%b)2 r7t{{		"a 67!;< &)Uk"),o&!11%8 G||/"$**RVVGLL-A"B"&

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

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

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

38,-1*	2D ! IIA67%(BD!  @s[   V&,V8W8DX:?Y:&V54V58W5W00W58;X76X7:	Y7)Y22Y7c                    | j                   }| j                  }|j                  t        d             |j                  j                         \  }}||   j                         }||   j                         }d}t        j                  |j                  v }|r|j                         nd}	|j                  j                  ||||	      D ]  }
|j                  |
       |dz  } |r| xj                  |z  c_        |S )z@Check that the dirstate is consistent with the parent's manifests   checking dirstate
r   Nr   )r   r    rn   r   dirstater^   manifestr	   NARROW_REQUIREMENTr!   r   r   r'   )r:   r   r    parent1parent2m1m2r{   	is_narrownarrow_matchererrs              r   rs   zverifier._verify_dirstatea  s    yyWW
		!*+,==002']##%']##% 33t7H7HH	/8))+d==''BH 	!CHHSMq O	! KK?*Kr   r   )r   NN)__name__
__module____qualname__r;   r@   rH   rN   rU   rg   r   ro   rp   rq   rr   rs   r   r   r   r   r   ;   sM    )(
>H08t7r/(d DHRh:I%Vr   r   r   )r   i18nr   ra   r   utilsr    r   r   r	   r
   r   r   r#   r   r   r   rt   r   r   r   r   r   r   r   <module>r      s~    
      K  >  8  = 
z zr   