##// END OF EJS Templates
copies: no longer cache the ChangedFiles during copy tracing...
copies: no longer cache the ChangedFiles during copy tracing Now that the copies information for both parents are processed all at once, we no longer needs to cache this information, so we simplify the code. The simpler code is also a (tiny) bit faster overall. Repo Case Source-Rev Dest-Rev # of revisions old time new time Difference Factor time per rev --------------------------------------------------------------------------------------------------------------------------------------------------------------- mercurial x_revs_x_added_0_copies ad6b123de1c7 39cfcef4f463 : 1 revs, 0.000041 s, 0.000041 s, +0.000000 s, × 1.0000, 41 µs/rev mercurial x_revs_x_added_x_copies 2b1c78674230 0c1d10351869 : 6 revs, 0.000102 s, 0.000096 s, -0.000006 s, × 0.9412, 16 µs/rev mercurial x000_revs_x000_added_x_copies 81f8ff2a9bf2 dd3267698d84 : 1032 revs, 0.004254 s, 0.004039 s, -0.000215 s, × 0.9495, 3 µs/rev pypy x_revs_x_added_0_copies aed021ee8ae8 099ed31b181b : 9 revs, 0.000282 s, 0.000189 s, -0.000093 s, × 0.6702, 21 µs/rev pypy x_revs_x000_added_0_copies 4aa4e1f8e19a 359343b9ac0e : 1 revs, 0.000048 s, 0.000047 s, -0.000001 s, × 0.9792, 47 µs/rev pypy x_revs_x_added_x_copies ac52eb7bbbb0 72e022663155 : 7 revs, 0.000211 s, 0.000103 s, -0.000108 s, × 0.4882, 14 µs/rev pypy x_revs_x00_added_x_copies c3b14617fbd7 ace7255d9a26 : 1 revs, 0.000375 s, 0.000286 s, -0.000089 s, × 0.7627, 286 µs/rev pypy x_revs_x000_added_x000_copies df6f7a526b60 a83dc6a2d56f : 6 revs, 0.010574 s, 0.010436 s, -0.000138 s, × 0.9869, 1739 µs/rev pypy x000_revs_xx00_added_0_copies 89a76aede314 2f22446ff07e : 4785 revs, 0.049974 s, 0.047465 s, -0.002509 s, × 0.9498, 9 µs/rev pypy x000_revs_x000_added_x_copies 8a3b5bfd266e 2c68e87c3efe : 6780 revs, 0.084300 s, 0.082351 s, -0.001949 s, × 0.9769, 12 µs/rev pypy x000_revs_x000_added_x000_copies 89a76aede314 7b3dda341c84 : 5441 revs, 0.060128 s, 0.058757 s, -0.001371 s, × 0.9772, 10 µs/rev pypy x0000_revs_x_added_0_copies d1defd0dc478 c9cb1334cc78 : 43645 revs, 0.686542 s, 0.674129 s, -0.012413 s, × 0.9819, 15 µs/rev pypy x0000_revs_xx000_added_0_copies bf2c629d0071 4ffed77c095c : 2 revs, 0.009277 s, 0.009434 s, +0.000157 s, × 1.0169, 4717 µs/rev pypy x0000_revs_xx000_added_x000_copies 08ea3258278e d9fa043f30c0 : 11316 revs, 0.114733 s, 0.111935 s, -0.002798 s, × 0.9756, 9 µs/rev netbeans x_revs_x_added_0_copies fb0955ffcbcd a01e9239f9e7 : 2 revs, 0.000081 s, 0.000078 s, -0.000003 s, × 0.9630, 39 µs/rev netbeans x_revs_x000_added_0_copies 6f360122949f 20eb231cc7d0 : 2 revs, 0.000107 s, 0.000106 s, -0.000001 s, × 0.9907, 53 µs/rev netbeans x_revs_x_added_x_copies 1ada3faf6fb6 5a39d12eecf4 : 3 revs, 0.000173 s, 0.000162 s, -0.000011 s, × 0.9364, 54 µs/rev netbeans x_revs_x00_added_x_copies 35be93ba1e2c 9eec5e90c05f : 9 revs, 0.000698 s, 0.000695 s, -0.000003 s, × 0.9957, 77 µs/rev netbeans x000_revs_xx00_added_0_copies eac3045b4fdd 51d4ae7f1290 : 1421 revs, 0.009248 s, 0.008901 s, -0.000347 s, × 0.9625, 6 µs/rev netbeans x000_revs_x000_added_x_copies e2063d266acd 6081d72689dc : 1533 revs, 0.015446 s, 0.014333 s, -0.001113 s, × 0.9279, 9 µs/rev netbeans x000_revs_x000_added_x000_copies ff453e9fee32 411350406ec2 : 5750 revs, 0.074373 s, 0.071998 s, -0.002375 s, × 0.9681, 12 µs/rev netbeans x0000_revs_xx000_added_x000_copies 588c2d1ced70 1aad62e59ddd : 66949 revs, 0.639870 s, 0.615346 s, -0.024524 s, × 0.9617, 9 µs/rev mozilla-central x_revs_x_added_0_copies 3697f962bb7b 7015fcdd43a2 : 2 revs, 0.000088 s, 0.000085 s, -0.000003 s, × 0.9659, 42 µs/rev mozilla-central x_revs_x000_added_0_copies dd390860c6c9 40d0c5bed75d : 8 revs, 0.000199 s, 0.000199 s, +0.000000 s, × 1.0000, 24 µs/rev mozilla-central x_revs_x_added_x_copies 8d198483ae3b 14207ffc2b2f : 9 revs, 0.000171 s, 0.000169 s, -0.000002 s, × 0.9883, 18 µs/rev mozilla-central x_revs_x00_added_x_copies 98cbc58cc6bc 446a150332c3 : 7 revs, 0.000592 s, 0.000590 s, -0.000002 s, × 0.9966, 84 µs/rev mozilla-central x_revs_x000_added_x000_copies 3c684b4b8f68 0a5e72d1b479 : 3 revs, 0.003151 s, 0.003122 s, -0.000029 s, × 0.9908, 1040 µs/rev mozilla-central x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 6 revs, 0.061612 s, 0.061192 s, -0.000420 s, × 0.9932, 10198 µs/rev mozilla-central x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 1593 revs, 0.005381 s, 0.005137 s, -0.000244 s, × 0.9547, 3 µs/rev mozilla-central x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 41 revs, 0.003742 s, 0.003585 s, -0.000157 s, × 0.9580, 87 µs/rev mozilla-central x000_revs_x000_added_x000_copies 7c97034feb78 4407bd0c6330 : 7839 revs, 0.061983 s, 0.060592 s, -0.001391 s, × 0.9776, 7 µs/rev mozilla-central x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 615 revs, 0.019861 s, 0.019596 s, -0.000265 s, × 0.9867, 31 µs/rev mozilla-central x0000_revs_xx000_added_x000_copies f78c615a656c 96a38b690156 : 30263 revs, 0.188101 s, 0.183558 s, -0.004543 s, × 0.9758, 6 µs/rev mozilla-central x00000_revs_x0000_added_x0000_copies 6832ae71433c 4c222a1d9a00 : 153721 revs, 1.806696 s, 1.758083 s, -0.048613 s, × 0.9731, 11 µs/rev mozilla-central x00000_revs_x00000_added_x000_copies 76caed42cf7c 1daa622bbe42 : 204976 revs, 2.682987 s, 2.592955 s, -0.090032 s, × 0.9664, 12 µs/rev mozilla-try x_revs_x_added_0_copies aaf6dde0deb8 9790f499805a : 2 revs, 0.000852 s, 0.000844 s, -0.000008 s, × 0.9906, 422 µs/rev mozilla-try x_revs_x000_added_0_copies d8d0222927b4 5bb8ce8c7450 : 2 revs, 0.000859 s, 0.000861 s, +0.000002 s, × 1.0023, 430 µs/rev mozilla-try x_revs_x_added_x_copies 092fcca11bdb 936255a0384a : 4 revs, 0.000150 s, 0.000150 s, +0.000000 s, × 1.0000, 37 µs/rev mozilla-try x_revs_x00_added_x_copies b53d2fadbdb5 017afae788ec : 2 revs, 0.001158 s, 0.001166 s, +0.000008 s, × 1.0069, 583 µs/rev mozilla-try x_revs_x000_added_x000_copies 20408ad61ce5 6f0ee96e21ad : 1 revs, 0.027240 s, 0.027359 s, +0.000119 s, × 1.0044, 27359 µs/rev mozilla-try x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 6 revs, 0.062824 s, 0.061848 s, -0.000976 s, × 0.9845, 10308 µs/rev mozilla-try x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 1593 revs, 0.005463 s, 0.005110 s, -0.000353 s, × 0.9354, 3 µs/rev mozilla-try x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 41 revs, 0.004238 s, 0.004168 s, -0.000070 s, × 0.9835, 101 µs/rev mozilla-try x000_revs_x000_added_x000_copies 1346fd0130e4 4c65cbdabc1f : 6657 revs, 0.064113 s, 0.063414 s, -0.000699 s, × 0.9891, 9 µs/rev mozilla-try x0000_revs_x_added_0_copies 63519bfd42ee a36a2a865d92 : 40314 revs, 0.294063 s, 0.288301 s, -0.005762 s, × 0.9804, 7 µs/rev mozilla-try x0000_revs_x_added_x_copies 9fe69ff0762d bcabf2a78927 : 38690 revs, 0.281493 s, 0.275798 s, -0.005695 s, × 0.9798, 7 µs/rev mozilla-try x0000_revs_xx000_added_x_copies 156f6e2674f2 4d0f2c178e66 : 8598 revs, 0.076323 s, 0.074640 s, -0.001683 s, × 0.9779, 8 µs/rev mozilla-try x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 615 revs, 0.020390 s, 0.020327 s, -0.000063 s, × 0.9969, 33 µs/rev mozilla-try x0000_revs_xx000_added_x000_copies 89294cd501d9 7ccb2fc7ccb5 : 97052 revs, 3.023879 s, 2.970385 s, -0.053494 s, × 0.9823, 30 µs/rev mozilla-try x0000_revs_x0000_added_x0000_copies e928c65095ed e951f4ad123a : 52031 revs, 0.735549 s, 0.719432 s, -0.016117 s, × 0.9781, 13 µs/rev mozilla-try x00000_revs_x_added_0_copies 6a320851d377 1ebb79acd503 : 363753 revs, 18.568900 s, 18.165143 s, -0.403757 s, × 0.9783, 49 µs/rev mozilla-try x00000_revs_x00000_added_0_copies dc8a3ca7010e d16fde900c9c : 34414 revs, 0.502584 s, 0.486769 s, -0.015815 s, × 0.9685, 14 µs/rev mozilla-try x00000_revs_x_added_x_copies 5173c4b6f97c 95d83ee7242d : 362229 revs, 18.356645 s, 17.913924 s, -0.442721 s, × 0.9759, 49 µs/rev mozilla-try x00000_revs_x000_added_x_copies 9126823d0e9c ca82787bb23c : 359344 revs, 18.250393 s, 17.660113 s, -0.590280 s, × 0.9677, 49 µs/rev mozilla-try x00000_revs_x0000_added_x0000_copies 8d3fafa80d4b eb884023b810 : 192665 revs, 2.792459 s, 2.709446 s, -0.083013 s, × 0.9703, 14 µs/rev mozilla-try x00000_revs_x00000_added_x0000_copies 1b661134e2ca 1ae03d022d6d : 228985 revs, 107.697264 s, 107.796891 s, +0.099627 s, × 1.0009, 470 µs/rev mozilla-try x00000_revs_x00000_added_x000_copies 9b2a99adc05e 8e29777b48e6 : 382065 revs, 63.961040 s, 63.575217 s, -0.385823 s, × 0.9940, 166 µs/rev Differential Revision: https://phab.mercurial-scm.org/D9423

File last commit:

r44572:e77b57e0 default
r46765:a132aa59 default
Show More
verify.py
628 lines | 22.7 KiB | text/x-python | PythonLexer
# verify.py - repository integrity checking for Mercurial
#
# Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
import os
from .i18n import _
from .node import (
nullid,
short,
)
from . import (
error,
pycompat,
revlog,
util,
)
VERIFY_DEFAULT = 0
VERIFY_FULL = 1
def verify(repo, level=None):
with repo.lock():
v = verifier(repo, level)
return v.verify()
def _normpath(f):
# under hg < 2.4, convert didn't sanitize paths properly, so a
# converted repo may contain repeated slashes
while b'//' in f:
f = f.replace(b'//', b'/')
return f
class verifier(object):
def __init__(self, repo, level=None):
self.repo = repo.unfiltered()
self.ui = repo.ui
self.match = repo.narrowmatch()
if level is None:
level = VERIFY_DEFAULT
self._level = level
self.badrevs = set()
self.errors = 0
self.warnings = 0
self.havecl = len(repo.changelog) > 0
self.havemf = len(repo.manifestlog.getstorage(b'')) > 0
self.revlogv1 = repo.changelog.version != revlog.REVLOGV0
self.lrugetctx = util.lrucachefunc(repo.unfiltered().__getitem__)
self.refersmf = False
self.fncachewarned = False
# developer config: verify.skipflags
self.skipflags = repo.ui.configint(b'verify', b'skipflags')
self.warnorphanstorefiles = True
def _warn(self, msg):
"""record a "warning" level issue"""
self.ui.warn(msg + b"\n")
self.warnings += 1
def _err(self, linkrev, msg, filename=None):
"""record a "error" level issue"""
if linkrev is not None:
self.badrevs.add(linkrev)
linkrev = b"%d" % linkrev
else:
linkrev = b'?'
msg = b"%s: %s" % (linkrev, msg)
if filename:
msg = b"%s@%s" % (filename, msg)
self.ui.warn(b" " + msg + b"\n")
self.errors += 1
def _exc(self, linkrev, msg, inst, filename=None):
"""record exception raised during the verify process"""
fmsg = pycompat.bytestr(inst)
if not fmsg:
fmsg = pycompat.byterepr(inst)
self._err(linkrev, b"%s: %s" % (msg, fmsg), filename)
def _checkrevlog(self, obj, name, linkrev):
"""verify 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.
"""
if not len(obj) and (self.havecl or self.havemf):
self._err(linkrev, _(b"empty or missing %s") % name)
return
d = obj.checksize()
if d[0]:
self._err(None, _(b"data length off by %d bytes") % d[0], name)
if d[1]:
self._err(None, _(b"index contains %d extra bytes") % d[1], name)
if obj.version != revlog.REVLOGV0:
if not self.revlogv1:
self._warn(_(b"warning: `%s' uses revlog format 1") % name)
elif self.revlogv1:
self._warn(_(b"warning: `%s' uses revlog format 0") % name)
def _checkentry(self, obj, i, node, seen, linkrevs, f):
"""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).
"""
lr = obj.linkrev(obj.rev(node))
if lr < 0 or (self.havecl and lr not in linkrevs):
if lr < 0 or lr >= len(self.repo.changelog):
msg = _(b"rev %d points to nonexistent changeset %d")
else:
msg = _(b"rev %d points to unexpected changeset %d")
self._err(None, msg % (i, lr), f)
if linkrevs:
if f and len(linkrevs) > 1:
try:
# attempt to filter down to real linkrevs
linkrevs = [
l
for l in linkrevs
if self.lrugetctx(l)[f].filenode() == node
]
except Exception:
pass
self._warn(
_(b" (expected %s)")
% b" ".join(map(pycompat.bytestr, linkrevs))
)
lr = None # can't be trusted
try:
p1, p2 = obj.parents(node)
if p1 not in seen and p1 != nullid:
self._err(
lr,
_(b"unknown parent 1 %s of %s") % (short(p1), short(node)),
f,
)
if p2 not in seen and p2 != nullid:
self._err(
lr,
_(b"unknown parent 2 %s of %s") % (short(p2), short(node)),
f,
)
except Exception as inst:
self._exc(lr, _(b"checking parents of %s") % short(node), inst, f)
if node in seen:
self._err(lr, _(b"duplicate revision %d (%d)") % (i, seen[node]), f)
seen[node] = i
return lr
def verify(self):
"""verify 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."""
# initial validation and generic report
repo = self.repo
ui = repo.ui
if not repo.url().startswith(b'file:'):
raise error.Abort(_(b"cannot verify bundle or remote repos"))
if os.path.exists(repo.sjoin(b"journal")):
ui.warn(_(b"abandoned transaction found - run hg recover\n"))
if ui.verbose or not self.revlogv1:
ui.status(
_(b"repository uses revlog format %d\n")
% (self.revlogv1 and 1 or 0)
)
# data verification
mflinkrevs, filelinkrevs = self._verifychangelog()
filenodes = self._verifymanifest(mflinkrevs)
del mflinkrevs
self._crosscheckfiles(filelinkrevs, filenodes)
totalfiles, filerevisions = self._verifyfiles(filenodes, filelinkrevs)
# final report
ui.status(
_(b"checked %d changesets with %d changes to %d files\n")
% (len(repo.changelog), filerevisions, totalfiles)
)
if self.warnings:
ui.warn(_(b"%d warnings encountered!\n") % self.warnings)
if self.fncachewarned:
ui.warn(
_(
b'hint: run "hg debugrebuildfncache" to recover from '
b'corrupt fncache\n'
)
)
if self.errors:
ui.warn(_(b"%d integrity errors encountered!\n") % self.errors)
if self.badrevs:
ui.warn(
_(b"(first damaged changeset appears to be %d)\n")
% min(self.badrevs)
)
return 1
return 0
def _verifychangelog(self):
"""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.
"""
ui = self.ui
repo = self.repo
match = self.match
cl = repo.changelog
ui.status(_(b"checking changesets\n"))
mflinkrevs = {}
filelinkrevs = {}
seen = {}
self._checkrevlog(cl, b"changelog", 0)
progress = ui.makeprogress(
_(b'checking'), unit=_(b'changesets'), total=len(repo)
)
for i in repo:
progress.update(i)
n = cl.node(i)
self._checkentry(cl, i, n, seen, [i], b"changelog")
try:
changes = cl.read(n)
if changes[0] != nullid:
mflinkrevs.setdefault(changes[0], []).append(i)
self.refersmf = True
for f in changes[3]:
if match(f):
filelinkrevs.setdefault(_normpath(f), []).append(i)
except Exception as inst:
self.refersmf = True
self._exc(i, _(b"unpacking changeset %s") % short(n), inst)
progress.complete()
return mflinkrevs, filelinkrevs
def _verifymanifest(
self, mflinkrevs, dir=b"", storefiles=None, subdirprogress=None
):
"""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.
"""
repo = self.repo
ui = self.ui
match = self.match
mfl = self.repo.manifestlog
mf = mfl.getstorage(dir)
if not dir:
self.ui.status(_(b"checking manifests\n"))
filenodes = {}
subdirnodes = {}
seen = {}
label = b"manifest"
if dir:
label = dir
revlogfiles = mf.files()
storefiles.difference_update(revlogfiles)
if subdirprogress: # should be true since we're in a subdirectory
subdirprogress.increment()
if self.refersmf:
# Do not check manifest if there are only changelog entries with
# null manifests.
self._checkrevlog(mf, label, 0)
progress = ui.makeprogress(
_(b'checking'), unit=_(b'manifests'), total=len(mf)
)
for i in mf:
if not dir:
progress.update(i)
n = mf.node(i)
lr = self._checkentry(mf, i, n, seen, mflinkrevs.get(n, []), label)
if n in mflinkrevs:
del mflinkrevs[n]
elif dir:
self._err(
lr,
_(b"%s not in parent-directory manifest") % short(n),
label,
)
else:
self._err(lr, _(b"%s not in changesets") % short(n), label)
try:
mfdelta = mfl.get(dir, n).readdelta(shallow=True)
for f, fn, fl in mfdelta.iterentries():
if not f:
self._err(lr, _(b"entry without name in manifest"))
elif f == b"/dev/null": # ignore this in very old repos
continue
fullpath = dir + _normpath(f)
if fl == b't':
if not match.visitdir(fullpath):
continue
subdirnodes.setdefault(fullpath + b'/', {}).setdefault(
fn, []
).append(lr)
else:
if not match(fullpath):
continue
filenodes.setdefault(fullpath, {}).setdefault(fn, lr)
except Exception as inst:
self._exc(lr, _(b"reading delta %s") % short(n), inst, label)
if self._level >= VERIFY_FULL:
try:
# Various issues can affect manifest. So we read each full
# text from storage. This triggers the checks from the core
# code (eg: hash verification, filename are ordered, etc.)
mfdelta = mfl.get(dir, n).read()
except Exception as inst:
self._exc(
lr,
_(b"reading full manifest %s") % short(n),
inst,
label,
)
if not dir:
progress.complete()
if self.havemf:
# since we delete entry in `mflinkrevs` during iteration, any
# remaining entries are "missing". We need to issue errors for them.
changesetpairs = [(c, m) for m in mflinkrevs for c in mflinkrevs[m]]
for c, m in sorted(changesetpairs):
if dir:
self._err(
c,
_(
b"parent-directory manifest refers to unknown"
b" revision %s"
)
% short(m),
label,
)
else:
self._err(
c,
_(b"changeset refers to unknown revision %s")
% short(m),
label,
)
if not dir and subdirnodes:
self.ui.status(_(b"checking directory manifests\n"))
storefiles = set()
subdirs = set()
revlogv1 = self.revlogv1
for f, f2, size in repo.store.datafiles():
if not f:
self._err(None, _(b"cannot decode filename '%s'") % f2)
elif (size > 0 or not revlogv1) and f.startswith(b'meta/'):
storefiles.add(_normpath(f))
subdirs.add(os.path.dirname(f))
subdirprogress = ui.makeprogress(
_(b'checking'), unit=_(b'manifests'), total=len(subdirs)
)
for subdir, linkrevs in pycompat.iteritems(subdirnodes):
subdirfilenodes = self._verifymanifest(
linkrevs, subdir, storefiles, subdirprogress
)
for f, onefilenodes in pycompat.iteritems(subdirfilenodes):
filenodes.setdefault(f, {}).update(onefilenodes)
if not dir and subdirnodes:
subdirprogress.complete()
if self.warnorphanstorefiles:
for f in sorted(storefiles):
self._warn(_(b"warning: orphan data file '%s'") % f)
return filenodes
def _crosscheckfiles(self, filelinkrevs, filenodes):
repo = self.repo
ui = self.ui
ui.status(_(b"crosschecking files in changesets and manifests\n"))
total = len(filelinkrevs) + len(filenodes)
progress = ui.makeprogress(
_(b'crosschecking'), unit=_(b'files'), total=total
)
if self.havemf:
for f in sorted(filelinkrevs):
progress.increment()
if f not in filenodes:
lr = filelinkrevs[f][0]
self._err(lr, _(b"in changeset but not in manifest"), f)
if self.havecl:
for f in sorted(filenodes):
progress.increment()
if f not in filelinkrevs:
try:
fl = repo.file(f)
lr = min([fl.linkrev(fl.rev(n)) for n in filenodes[f]])
except Exception:
lr = None
self._err(lr, _(b"in manifest but not in changeset"), f)
progress.complete()
def _verifyfiles(self, filenodes, filelinkrevs):
repo = self.repo
ui = self.ui
lrugetctx = self.lrugetctx
revlogv1 = self.revlogv1
havemf = self.havemf
ui.status(_(b"checking files\n"))
storefiles = set()
for f, f2, size in repo.store.datafiles():
if not f:
self._err(None, _(b"cannot decode filename '%s'") % f2)
elif (size > 0 or not revlogv1) and f.startswith(b'data/'):
storefiles.add(_normpath(f))
state = {
# TODO this assumes revlog storage for changelog.
b'expectedversion': self.repo.changelog.version & 0xFFFF,
b'skipflags': self.skipflags,
# experimental config: censor.policy
b'erroroncensored': ui.config(b'censor', b'policy') == b'abort',
}
files = sorted(set(filenodes) | set(filelinkrevs))
revisions = 0
progress = ui.makeprogress(
_(b'checking'), unit=_(b'files'), total=len(files)
)
for i, f in enumerate(files):
progress.update(i, item=f)
try:
linkrevs = filelinkrevs[f]
except KeyError:
# in manifest but not in changelog
linkrevs = []
if linkrevs:
lr = linkrevs[0]
else:
lr = None
try:
fl = repo.file(f)
except error.StorageError as e:
self._err(lr, _(b"broken revlog! (%s)") % e, f)
continue
for ff in fl.files():
try:
storefiles.remove(ff)
except KeyError:
if self.warnorphanstorefiles:
self._warn(
_(b" warning: revlog '%s' not in fncache!") % ff
)
self.fncachewarned = True
if not len(fl) and (self.havecl or self.havemf):
self._err(lr, _(b"empty or missing %s") % f)
else:
# Guard against implementations not setting this.
state[b'skipread'] = set()
state[b'safe_renamed'] = set()
for problem in fl.verifyintegrity(state):
if problem.node is not None:
linkrev = fl.linkrev(fl.rev(problem.node))
else:
linkrev = None
if problem.warning:
self._warn(problem.warning)
elif problem.error:
self._err(
linkrev if linkrev is not None else lr,
problem.error,
f,
)
else:
raise error.ProgrammingError(
b'problem instance does not set warning or error '
b'attribute: %s' % problem.msg
)
seen = {}
for i in fl:
revisions += 1
n = fl.node(i)
lr = self._checkentry(fl, i, n, seen, linkrevs, f)
if f in filenodes:
if havemf and n not in filenodes[f]:
self._err(lr, _(b"%s not in manifests") % (short(n)), f)
else:
del filenodes[f][n]
if n in state[b'skipread'] and n not in state[b'safe_renamed']:
continue
# check renames
try:
# This requires resolving fulltext (at least on revlogs,
# though not with LFS revisions). We may want
# ``verifyintegrity()`` to pass a set of nodes with
# rename metadata as an optimization.
rp = fl.renamed(n)
if rp:
if lr is not None and ui.verbose:
ctx = lrugetctx(lr)
if not any(rp[0] in pctx for pctx in ctx.parents()):
self._warn(
_(
b"warning: copy source of '%s' not"
b" in parents of %s"
)
% (f, ctx)
)
fl2 = repo.file(rp[0])
if not len(fl2):
self._err(
lr,
_(
b"empty or missing copy source revlog "
b"%s:%s"
)
% (rp[0], short(rp[1])),
f,
)
elif rp[1] == nullid:
ui.note(
_(
b"warning: %s@%s: copy source"
b" revision is nullid %s:%s\n"
)
% (f, lr, rp[0], short(rp[1]))
)
else:
fl2.rev(rp[1])
except Exception as inst:
self._exc(
lr, _(b"checking rename of %s") % short(n), inst, f
)
# cross-check
if f in filenodes:
fns = [(v, k) for k, v in pycompat.iteritems(filenodes[f])]
for lr, node in sorted(fns):
self._err(
lr,
_(b"manifest refers to unknown revision %s")
% short(node),
f,
)
progress.complete()
if self.warnorphanstorefiles:
for f in sorted(storefiles):
self._warn(_(b"warning: orphan data file '%s'") % f)
return len(files), revisions