a
    &0_Z                     @   sv   d dl mZ d dlZddlmZ ddlmZmZ ddlm	Z	m
Z
mZmZ d ZdZdddZd	d
 ZG dd deZdS )    )absolute_importN   )_)nullidshort)errorpycompatrevlogutilc                 C   s>   |   " t| |}| W  d    S 1 s00    Y  d S )N)lockverifierverify)repolevelv r   2/usr/lib/python3/dist-packages/mercurial/verify.pyr      s    

r   c                 C   s   d| v r|  dd} q | S )Ns   //   /)replace)fr   r   r   	_normpath#   s    r   c                   @   sl   e Zd ZdddZdd ZdddZddd	Zd
d Zdd Zdd Z	dd Z
dddZdd Zdd ZdS )r   Nc                 C   s   |  | _|j| _| | _|d u r(t}|| _t | _d| _	d| _
t|jdk| _t|jddk| _|jjtjk| _t|  j| _d| _d| _|jdd| _d| _d S )Nr       Fs   verify	   skipflagsT)Z
unfilteredr   uiZnarrowmatchmatchVERIFY_DEFAULT_levelsetbadrevserrorswarningslen	changeloghaveclmanifestlog
getstoragehavemfversionr	   REVLOGV0revlogv1r
   Zlrucachefunc__getitem__	lrugetctxrefersmffncachewarnedZ	configint	skipflagswarnorphanstorefiles)selfr   r   r   r   r   __init__,   s"    

zverifier.__init__c                 C   s"   | j |d  |  jd7  _dS )zrecord a "warning" level issue   
r   N)r   warnr    )r0   msgr   r   r   _warn@   s    zverifier._warnc                 C   sd   |dur| j | d| }nd}d||f }|r>d||f }| jd| d  |  jd7  _dS )	zrecord a "error" level issueNs   %d   ?   %s: %ss   %s@%s    r2   r   )r   addr   r3   r   )r0   linkrevr4   filenamer   r   r   _errE   s    
zverifier._errc                 C   s2   t |}|st |}| |d||f | dS )z1record exception raised during the verify processr7   N)r   bytestrZbytereprr<   )r0   r:   r4   instr;   Zfmsgr   r   r   _excR   s    

zverifier._excc                 C   s   t |s,| js| jr,| |td|  dS | }|d rV| dtd|d  | |d rx| dtd|d  | |jtjkr| j	s| 
td|  n| j	r| 
td|  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&   r<   r   Z	checksizer'   r	   r(   r)   r5   )r0   objnamer:   dr   r   r   _checkrevlogY   s    zverifier._checkrevlogc              
      s  | |}|dk s&jr||vr|dk s>|tjjkrHtd}ntd}d|||f   |rȈ rt|dkrz fdd|D }W n ty   Y n0 	tdd	
ttj|  d}z~|\}	}
|	|vr|	tkr|td
t|	tf   |
|vrH|
tkrH|tdt|
tf   W nB ty } z(|tdt |  W Y d}~n
d}~0 0 |v r|td|| f   ||< |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   c                    s&   g | ]} |   kr|qS r   )r+   Zfilenode).0lr   noder0   r   r   
<listcomp>   s   z(verifier._checkentry.<locals>.<listcomp>s    (expected %s)r8   s   unknown parent 1 %s of %ss   unknown parent 2 %s of %ss   checking parents of %ss   duplicate revision %d (%d))r:   revr#   r!   r   r"   r   r<   	Exceptionr5   joinmapr   r=   parentsr   r   r?   )r0   rA   irH   seenlinkrevsr   lrr4   Zp1Zp2r>   r   rG   r   _checkentryq   sP    

2
zverifier._checkentryc                 C   s4  | j }|j}| ds(ttdtj	|
drH|td |jsT| jsp|td| jrhdpjd  |  \}}| |}~| || | ||\}}|tdt|j||f  | jr|td	| j  | jr|td
 | jr0|td| j  | jr,|tdt| j  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!
sC   hint: run "hg debugrebuildfncache" to recover from corrupt fncache
s!   %d integrity errors encountered!
s+   (first damaged changeset appears to be %d)
)r   r   Zurl
startswithr   ZAbortr   ospathexistsZsjoinr3   verboser)   status_verifychangelog_verifymanifest_crosscheckfiles_verifyfilesr!   r"   r    r-   r   r   min)r0   r   r   
mflinkrevsfilelinkrevs	filenodesZ
totalfilesZfilerevisionsr   r   r   r      sP    
zverifier.verifyc                 C   sJ  | j }| j}| j}|j}|td i }i }i }| |dd |jtdtdt|d}|D ]}	|	|	 |
|	}
| ||	|
||	gd zb||
}|d tkr||d g |	 d| _|d D ]"}||r|t|g |	 qW q` ty6 } z,d| _| |	td	t|
 | W Y d
}~q`d
}~0 0 q`|  ||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ZunittotalT   s   unpacking changeset %sN)r   r   r   r"   rY   r   rD   makeprogressr!   updaterH   rS   readr   
setdefaultappendr,   r   rK   r?   r   complete)r0   r   r   r   Zclr_   r`   rP   progressrO   nZchangesr   r>   r   r   r   rZ      s:    


2zverifier._verifychangelogr   c           $         sN  | j }| j}| j}| j j}||}	|s8| jtd i }
i }i }d}|rn|}|	 }|| |rn|	  | j
r| |	|d |jtdtdt|	d}|	D ]}|s|| |	|}| |	||| |g |}| v r |= n<|r| |tdt| | n| |tdt| | z|||jd	d
}| D ]\}}}|sh| |td n|dkrvqF|t| }|dkr||sqF||d i |g | n"||sʐqF|
|i || qFW nB ty& } z(| |tdt| || W Y d}~n
d}~0 0 | jtkrz||| }W q ty } z(| |tdt| || W Y d}~qd}~0 0 q|s|  | j r fdd D }t!|D ]F\}}|r| |tdt| | n| |tdt| | q|s|r| jtd t" }t" }| j#}|j$% D ]d\}}}|sb| dtd|  n<|dksr|s<|&dr<|'t| |'t(j)*| q<|jtdtdt|d}t+,|D ]B\} }!| -|!| ||}"t+,|"D ]\}}#|
|i |# qq|sJ|rJ|  | j.rJt!|D ]}| /td|  q0|
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   rb   s	   manifestsrc   s#   %s not in parent-directory manifests   %s not in changesetsT)Zshallows   entry without name in manifests	   /dev/null   tr   s   reading delta %sNs   reading full manifest %sc                    s"   g | ]} | D ]}||fqqS r   r   )rE   mcr_   r   r   rI     r   z,verifier._verifymanifest.<locals>.<listcomp>s7   parent-directory manifest refers to unknown revision %ss'   changeset refers to unknown revision %ss   checking directory manifests
   cannot decode filename '%s's   meta/   warning: orphan data file '%s')0r   r   r   r$   r%   rY   r   filesdifference_update	incrementr,   rD   rf   r!   rg   rH   rS   getr<   r   Z	readdeltaZiterentriesr   Zvisitdirri   rj   rK   r?   r   VERIFY_FULLrh   rk   r&   sortedr   r)   store	datafilesrT   r9   rU   rV   dirnamer   	iteritemsr[   r/   r5   )$r0   r_   dir
storefilesZsubdirprogressr   r   r   ZmflZmfra   ZsubdirnodesrP   ZlabelZrevlogfilesrl   rO   rm   rR   Zmfdeltar   fnflfullpathr>   Zchangesetpairsrp   ro   Zsubdirsr)   f2sizeZsubdirrQ   ZsubdirfilenodesZonefilenodesr   rq   r   r[     s    







2

zverifier._verifymanifestc           	   	      s  | j }| j}|td t|t| }|jtdtd|d}| jrt|D ]2}|  ||vrP|| d }| 	|td| qP| j
rt|D ]f}|  ||vrz(|| t fdd|| D }W n ty   d }Y n0 | 	|td	| q|  d S )
Ns0   crosschecking files in changesets and manifests
s   crosschecking   filesrc   r   s    in changeset but not in manifestc                    s   g | ]}   |qS r   )r:   rJ   )rE   rm   r   r   r   rI     r   z-verifier._crosscheckfiles.<locals>.<listcomp>s    in manifest but not in changeset)r   r   rY   r   r!   rf   r&   ry   rv   r<   r#   filer^   rK   rk   )	r0   r`   ra   r   r   rd   rl   r   rR   r   r   r   r\     s0    

zverifier._crosscheckfilesc                    s   | j }| j}| j}| j}| j}|td t }|j	 D ]H\}	}
}|	s`| 
d td|
  q<|dksl|s<|	dr<|t|	 q<| j jjd@ | j|dddkd	}tt|t|B }d}|jtd
tdt|d}t|D ]\}}	|j||	d z||	 }W n ty"   g }Y n0 |r4|d }nd }z||	}W nJ tjy } z.| 
|td| |	 W Y d }~qW Y d }~n
d }~0 0 | D ]J}z|| W n4 ty   | jr| td|  d| _Y n0 qt|s| j s | jr| 
|td|	  nt |d< t |d< |!|D ]x}|j"d urX|#|$|j"}nd }|j%rr| |j% n8|jr| 
|d ur|n||j|	 nt&d|j' q4i }|D ]}|d7 }|"|}| (||||||	}|	|v r&|r|||	 vr| 
|tdt)| |	 n
||	 |= ||d v rF||d vrFqz|*|  r(|d ur|j+r||}t, fdd|- D s| td|	|f  | d }t|s| 
|td d t) d f |	 nD d t.kr|/td|	| d t) d f  n|$ d  W nB t0yl } z(| 1|tdt)| ||	 W Y d }~n
d }~0 0 q|	|v rdd t23||	 D }t|D ]$\}}| 
|tdt)| |	 qq|4  | jrt|D ]}	| td |	  qt||fS )!Ns   checking files
rr   r   s   data/i  s   censors   policys   abort)s   expectedversionr   s   erroroncensoredrb   r   rc   )items   broken revlog! (%s)s%    warning: revlog '%s' not in fncache!Tr@   s   skipreads   safe_renameds<   problem instance does not set warning or error attribute: %sr   s   %s not in manifestsc                 3   s   | ]} d  |v V  qdS )r   Nr   )rE   ZpctxZrpr   r   	<genexpr>B  r   z(verifier._verifyfiles.<locals>.<genexpr>s1   warning: copy source of '%s' not in parents of %ss)   empty or missing copy source revlog %s:%ss5   warning: %s@%s: copy source revision is nullid %s:%s
s   checking rename of %sc                 S   s   g | ]\}}||fqS r   r   )rE   kr   r   r   r   rI   f  r   z)verifier._verifyfiles.<locals>.<listcomp>s&   manifest refers to unknown revision %srs   )5r   r   r+   r)   r&   rY   r   r   rz   r{   r<   rT   r9   r   r"   r'   r.   Zconfigry   rf   r!   	enumeraterg   KeyErrorr   r   ZStorageErrorrt   remover/   r5   r-   r#   ZverifyintegrityrH   r:   rJ   ZwarningZProgrammingErrorr4   rS   r   ZrenamedrX   anyrN   r   ZnoterK   r?   r   r}   rk   )r0   ra   r`   r   r   r+   r)   r&   r   r   r   r   statert   Z	revisionsrl   rO   rQ   rR   r   eZffZproblemr:   rP   rm   ctxZfl2r>   ZfnsrH   r   r   r   r]     s    

"








	
zverifier._verifyfiles)N)N)N)r   NN)__name__
__module____qualname__r1   r5   r<   r?   rD   rS   r   rZ   r[   r\   r]   r   r   r   r   r   +   s   


B41 
 #r   )N)Z
__future__r   rU   Zi18nr   rH   r   r    r   r   r	   r
   r   rx   r   r   objectr   r   r   r   r   <module>   s   
