
    	^cV                         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 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dS )    N   )_)short)
stringutil)errorpycompatrevlogutilc                     |                                  5  t          | |          }|                                cd d d            S # 1 swxY w Y   d S N)lockverifierverify)repolevelvs      2/usr/lib/python3/dist-packages/mercurial/verify.pyr   r      s    	  T5!!xxzz                 s   $AA
A
c                 B    d| v r|                      dd          } d| v | S )Ns   //   /)replace)fs    r   	_normpathr       s0     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                   Z    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S )r   Nc                    |                                 | _        |j        | _        |                                | _        |t
          }|| _        t                      | _        d| _	        d| _
        t          |j                  dk    | _        t          |j                            d                    dk    | _        |j        j        t$          j        k    | _        t+          j        |                                 j                  | _        d| _        d| _        |j                            dd          | _        d| _        d S )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uu$.))A-$*55c::;;a?6&/I*4??+<+<+HII"**9lCC$(!!!r   c                 `    | j                             |dz              | xj        dz  c_        dS )zrecord a "warning" level issue   
r   N)r   warnr&   )r8   msgs     r   _warnzverifier._warnN   s.    S5[!!!r   c                     | | j                             |           d|z  }nd}d||fz  }|rd||fz  }| j                            d|z   dz              | xj        dz  c_        dS )	zrecord a "error" level issueNs   %d   ?   %s: %ss   %s@%s    r;   r   )r$   addr   r<   r%   )r8   linkrevr=   filenames       r   _errzverifier._errS   s    LW%%%goGGG7C.( 	-h_,CTCZ%'(((qr   c                     t          j        |          }|st          j        |          }|                     |d||fz  |           dS )z1record exception raised during the verify processrA   N)r   forcebytestrr   bytereprrF   )r8   rD   r=   instrE   fmsgs         r   _exczverifier._exc`   sO    &t,, 	+$T**D		'9T{2H=====r   c                 r   t          |          s6| j        s| j        r(|                     |t	          d          |z             dS |                                }|d         r-|                     dt	          d          |d         z  |           |d         r-|                     dt	          d          |d         z  |           |j        t          j        k    r0| j	        s'| 
                    t	          d          |z             dS dS | j	        r'| 
                    t	          d          |z             dS dS )	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,   rF   r   	checksizer-   r	   r.   r/   r>   )r8   objnamerD   ds        r   _checkrevlogzverifier._checkrevlogg   sL    3xx 	T[ 	DK 	IIgq!7884?@@@FMMOOQ4 	LIIdA<==!DdKKKQ4 	NIIdA>??!A$FMMM&/11= L

1BCCdJKKKKKL L] 	HJJq>??$FGGGGG	H 	Hr   c                 p   |                     |                    |                    }|dk     s| j        r/||vr*|dk     s|t          | j        j                  k    rt          d          }nt          d          }|                     d|||fz  |           |r|rrt          |          dk    r_	 g }|D ]H}|                     |          |         	                                |k    r|
                    |           In# t          $ r Y nw xY wt          d          }|d                    t          t          j        |                    z  }|                     |           d}	 |                    |          \  }	}
|	|vrU|	| j        j        k    rEt          d          t'          |	          t'          |          fz  }|                     |||           |
|vrU|
| j        j        k    rEt          d	          t'          |
          t'          |          fz  }|                     |||           nL# t          $ r?}|                     |t          d
          t'          |          z  ||           Y d}~nd}~ww xY w||v r/|                     |t          d          |||         fz  |           |||<   |S )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)rB   s   unknown parent 1 %s of %ss   unknown parent 2 %s of %ss   checking parents of %ss   duplicate revision %d (%d))rD   revr)   r'   r   r(   r   rF   r2   filenodeappend	Exceptionjoinmapr   bytestrr>   parentsnullidr   rL   )r8   rP   inodeseenlinkrevsr   lrr=   p1p2rJ   s               r   _checkentryzverifier._checkentry   s   ( [[''66dk6b&8&8Avvs49#67777DEECDDIIdC1b'M1---   X**#%"* 4 4B#~~b11!4==??4GG ( 3 3 34 %   )**tyyX%5x!@!@AAA

3B		O[[&&FB~~"	(8"8"8455rE$KK8PP		"c1%%%~~"	(8"8"8455rE$KK8PP		"c1%%% 	O 	O 	OIIb!566tDdANNNNNNNN	O 4<<IIb!9::ad_LaPPPT
	s,   2AD   
DD'C
H2 2
I;<5I66I;c                    | j         }|j        }|                                                    d          s!t	          j        t          d                    t          j        	                    |
                    d                    r"|                    t          d                     |j        s| j        s.|                    t          d          | j        rdpdz             |                                 \  }}|                     |          }~|                     ||           |                     ||          \  }}|                    t          d          t'          |j                  ||fz             | j        r*|                    t          d	          | j        z             | j        r|                    t.                     | j        rn|                    t          d
          | j        z             | j        r;t          d          }|t5          | j                  z  }|                    |           dS dS )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   journals-   abandoned transaction found - run hg recover
s!   repository uses revlog format %d
r   r   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)
)r   r   url
startswithr   Abortr   ospathexistssjoinr<   verboser/   status_verifychangelog_verifymanifest_crosscheckfiles_verifyfilesr'   r(   r&   r4   HINT_FNCACHEr%   r$   min)	r8   r   r   
mflinkrevsfilelinkrevs	filenodes
totalfilesfilerevisionsr=   s	            r   r   zverifier.verify   s)    yWxxzz$$X.. 	J+a GHHIII7>>$**Z0011 	JGGAGHHIII: 	T] 	II788=&Q+!-   $(#8#8#:#: 
L((44	lI666$($5$5i$N$N!
M 			DEE4>""M:>?	
 	
 	
 = 	FGGA344t}DEEE 	"GGL!!!; 	GGA;<<t{JKKK| GHHs4<(((1qr   c           	         | j         }| j        }| j        }|j        }|                    t          d                     i }i }i }|                     |dd           |                    t          d          t          d          t          |                    }|D ]H}	|	                    |	           |
                    |	          }
|                     ||	|
||	gd           	 |                    |
          }|d         | j        j        k    r6|                    |d         g                               |	           d| _        |d         D ]C} ||          r6|                    t#          |          g                               |	           D# t$          $ rF}d| _        |                     |	t          d	          t)          |
          z  |           Y d
}~Bd
}~ww xY w|                                 ||fS )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(   ro   r   rS   makeprogressr'   updater_   re   readr]   
setdefaultrW   r3   r   rX   rL   r   complete)r8   r   r   r    clrv   rw   r`   progressr^   nchangesr   rJ   s                 r   rp   zverifier._verifychangelog   s     Wy
^
		!,--...
"lA...??kNN=!1!1T # 
 
  	L 	LAOOA

ARAtaS,???
L''!**1:!111))'!*b99@@CCC$(DM  L LAuQxx L$//	!bAAHHKKKL  L L L $		!Q899E!HHDdKKKKKKKKL 	<''s   &B-F
G$;GG$r   c                 8   | j         }| j        }| j        }| j         j        }|                    |          }	|s'| j                            t          d                     i }
i }i }d}|rA|}|	                                }|                    |           |r|	                                 | j
        r|                     |	j        |d           |                    t          d          t          d          t          |	                    }|	D ]}|s|                    |           |	                    |          }|                     |	|||                    |g           |          }|v r|= nm|r7t          d          t'          |          z  }|                     |||           n4|                     |t          d          t'          |          z  |           	 |                    ||                              d	
          }|                                D ]\  }}}|s$|                     |t          d                     n|dk    r3|t/          |          z   }|dk    rY|                    |          sa|                    |dz   i           }|                    |g                               |            ||          s|
                    |i                               ||           nL# t6          $ r?}|                     |t          d          t'          |          z  ||           Y d}~nd}~ww xY w| j        t<          k    rz	 |                    ||                                          }t# t6          $ rB}t          d          t'          |          z  }|                     ||||           Y d}~d}~ww xY w|s|                                  | j!        rfdD             }tE          |          D ]l\  }}|r-|                     |tF          t'          |          z  |           4t          d          }|t'          |          z  }|                     |||           m|sL|rI| j                            t          d                     tI                      }tI                      }| j%        }g } |j&        '                    |           D ]w\  }!}}"|"dk    s|si|(                    d          rT|)                    t/          |                     |)                    tT          j+        ,                    |                     x| D ](}|                     dt          d          |z             )|                    t          d          t          d          t          |                    }|-                                D ]`\  }#}$| .                    |$|#||          }%|%-                                D ].\  }}&|
                    |i                               |&           /a|sX|rV|J |                                  | j/        r7tE          |          D ]'}| 0                    t          d          |z             (|
S )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 %sc                 .    g | ]}|         D ]}||fS  r   ).0mcrv   s      r   
<listcomp>z,verifier._verifymanifest.<locals>.<listcomp>  s.    PPP*Q-PPQq!fPPPPr   s'   changeset refers to unknown revision %ss   checking directory manifests
undecodables   meta/   cannot decode filename '%s'   warning: orphan data file '%s')1r   r   r    r*   r+   ro   r   filesdifference_update	incrementr3   rS   _revlogr   r'   r   r_   re   getr   rF   	readdeltaiterentriesr   visitdirr   rW   rX   rL   r"   VERIFY_FULLr   r   r,   sortedWARN_PARENT_DIR_UNKNOWN_REVr#   r/   store	datafilesrh   rC   rj   rk   dirnameitemsrq   r7   r>   )'r8   rv   dir
storefilessubdirprogressr   r   r    mflmfrx   subdirnodesr`   labelrevlogfilesr   r^   r   rb   r=   mfdeltar   fnflfullpathsdnrJ   changesetpairsr   r   subdirsr/   r   tsizesubdirra   subdirfilenodesonefilenodess'    `                                     r   rq   zverifier._verifymanifest  s   < yW
i#^^C   	7GNN1455666	 	+E((**K((555 +((***= 	4 bj%333??kNN<B # 
 
  (	4 (	4A #"""

A!!"aD*..B2G2GOOBJqMM L>??%((J		"c5))))		"a 788588CUKKKN''#q//33D3AA!(!4!4!6!6 N NIAr2 !		"a(I&J&JKKKKl** "Yq\\1HTzz$~~h77 %$)44X_bIIr2..55b9999$uX %$!,,Xr::EEb"MMMMN  N N N		"a 344uQxx?uMMMMMMMMN{k))4 "ggc1oo2244GG  4 4 4788588CCIIb#tU333333334 *  	 ; 
	- QPPPjPPPN~.. - -1 -IIa!<uQxx!GOOOOFGGC588OCIIae,,,, 	{ 	GNN1>??@@@JeeG}HK"j22{2KK 4 4
1d1HHHH!,,x2H2HHNN9Q<<000KK 2 2333  G G		$"@ A AA EFFFF__+Q|__CLL -  N !, 1 1 3 3 	A 	AFH"22&*n O $3#8#8#:#: A A<$$Q++22<@@@@A  	I{ 	I!---##%%%( I
++ I IAJJq!BCCaGHHHHs1   #DK==
M5MM(N
O7OOc                 6  	 | j         }| j        }|                    t          d                     t	          |          t	          |          z   }|                    t          d          t          d          |          }| j        r\t          |          D ]L}|                                 ||vr2||         d         }| 	                    |t          d          |           M| j
        rt          |          D ]}|                                 ||vrn	 |                    |          	t          	fd||         D                       }n# t          $ r d }Y nw xY w| 	                    |t          d          |           |                                 d S )	Ns0   crosschecking files in changesets and manifests
s   crosschecking   filesr}   r   s    in changeset but not in manifestc                 `    g | ]*}                                         |                    +S r   )rD   rU   )r   r   r   s     r   r   z-verifier._crosscheckfiles.<locals>.<listcomp>  s/    !N!N!NA"**RVVAYY"7"7!N!N!Nr   s    in manifest but not in changeset)r   r   ro   r   r'   r   r,   r   r   rF   r)   fileru   rX   r   )
r8   rw   rx   r   r   r   r   r   rb   r   s
            @r   rr   zverifier._crosscheckfiles  s   yW
		!HIIJJJL!!C	NN2??akk # 
 
 ; 	ML)) M M""$$$I%%%a+BIIb!$G"H"H!LLL; 		MI&& M M""$$$L(("!YYq\\ !N!N!N!N1!N!N!NOO$ " " "!"IIb!$G"H"H!LLLs   6EEEc                   # | j         }| j        }| j        }| j        }| j        }|                    t          d                     t                      }g }	|j        	                    |	          D ]E\  }
}}|dk    s|s7|
                    d          r"|                    t          |                     F|	D ](}|                     d t          d          |z             )| j         j        j        | j        |                    dd          dk    d	}t%          t          |          t          |          z            }d}|                    t          d
          t          d          t)          |                    }t+          |          D ]\  }}|                    ||           	 ||         }n# t.          $ r g }Y nw xY w|r	|d         }nd }	 |                    |          }nC# t2          j        $ r1}|                     |t          d          |z  |           Y d }~d }~ww xY w|                                D ]]}	 |                    |           # t.          $ r8 | j        r.t          d          }|                     ||z             d| _        Y Zw xY wt)          |          s5| j         s| j        r'|                     |t          d          |z             nt                      |d<   t                      |d<   |!                    |          D ]}|j"        .|#                    |$                    |j"                            }nd }|j%        r|                     |j%                   [|j        r#||n|}|                     ||j        |           t3          j&        d|j'        z            i }|D ]?}|dz  }|"                    |          }| (                    ||||||          }||v rJ|r?|||         vr5|                     |t          d          tS          |          z  |           n	||         |= ||d         v r||d         vr	 |*                    |          ##r?|^|j+        rW ||          }tY          #fd|-                                D                       s|                     t\          ||fz             |                    #d                   }t)          |          sEt          d          }|                     ||#d         tS          #d                   fz  |           np#d         | j         j/        k    r?t`          }|||#d         tS          #d                   fz  }|1                    |           n|$                    #d                    # td          $ r@} | 3                    |t          d          tS          |          z  | |           Y d } ~ 9d } ~ ww xY w||v rod ||         4                                D             }!t%          |!          D ];\  }}"t          d          }|                     ||tS          |"          z  |           <|5                                 | j        r7t%          |          D ]'}|                     t          d          |z             (t)          |          |fS )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!TrN   s   skipreads   safe_renameds<   problem instance does not set warning or error attribute: %sr   s   %s not in manifestsc              3   ,   K   | ]}d          |v V  dS )r   Nr   )r   pctxrps     r   	<genexpr>z(verifier._verifyfiles.<locals>.<genexpr>.  s+      &O&Or!u}&O&O&O&O&O&Or   s)   empty or missing copy source revlog %s:%ss   checking rename of %sc                     g | ]	\  }}||f
S r   r   )r   kr   s      r   r   z)verifier._verifyfiles.<locals>.<listcomp>A  s     ???$!Q1v???r   s&   manifest refers to unknown revision %sr   )6r   r   r2   r/   r,   ro   r   r#   r   r   rh   rC   r   rF   r(   r-   r6   configr   r   r'   	enumerater   KeyErrorr   r   StorageErrorr   remover7   r>   r4   r)   verifyintegrityr_   rD   rU   warningProgrammingErrorr=   re   r   renamedrn   anyr\   WARN_UNKNOWN_COPY_SOURCEr]   WARN_NULLID_COPY_SOURCEnoterX   rL   r   r   )$r8   rx   rw   r   r   r2   r/   r,   r   r   r   r   r   stater   	revisionsr   r^   ra   rb   r   effr=   problemrD   linkrev_msgr`   r   ctxfl2r   rJ   fnsr_   r   s$                                      @r   rs   zverifier._verifyfiles  s_   yWN	=
		!'(()))UU
*..;.GG 	- 	-JAq$qall8.D.Dy||,,, 	C 	CAIIdA<==ABBBB !%	 3 C. "		)Y ? ?8 K
 
 s9~~L(9(99::	??kNN8CJJ # 
 
 e$$ b	8 b	8DAqOOAAO&&&'?     a[YYq\\%   		"a 677!;Q??? hhjj 2 22%%b)))) 2 2 20 2 HII

38,,,-1*	2 r77  t{ 		"a 677!;<<<< &)UUk"),o&!11%88  G|/"$**RVVGL-A-A"B"B"& 	

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

+Cq#h+N O O O"ii1.."3xx + !"N O OA IIb!r!ueBqEll.C*CQGGGGUdi&666"9CAr2a5%1,,#??CGGCLLLLGGBqENNN    IIA677%((BD!        I~~??)A,*<*<*>*>??? &s 8 8HBEFFCIIb#d"3Q7777$ 	EJ'' E E

1>??!CDDDD5zz9$$sU   /F88GGG..H.='H))H.I?J J EV77
X5W<<Xr   )r   NN)__name__
__module____qualname__r9   r>   rF   rL   rS   re   r   rp   rq   rr   rs   r   r   r   r   r   9   s        ) ) ) )(  
   > > > >H H H08 8 8t, , ,\.( .( .(b DHO O O Ob  :F% F% F% F% F%r   r   r   )rj   i18nr   r_   r   utilsr    r   r   r	   r
   r!   r   r   r   rt   r   r   r   r   r   r   r   <module>r      sH   
			                                    qK   a>   18   !=  
R% R% R% R% R% R% R% R% R% R%r   