comparison mercurial/revlog.py @ 39842:97986c9c69d3

verify: start to abstract file verification Currently, the file storage interface has a handful of attributes that are exclusively or near-exclusively used by repo verification code. In order to support verification on non-revlog/alternate storage backends, we'll need to abstract verification so it can be performed in a storage-agnostic way. This commit starts that process. We establish a new verifyintegrity() method on revlogs and expose it to the file storage interface. Most of verify.verifier.checklog() has been ported to this new method. We need a way to represent verification problems. So we invent an interface to represent a verification problem, invent a revlog type to implement that interface, and use it. The arguments to verifyintegrity() will almost certainly change in the future, once more functionality is ported from the verify code. And the "revlogv1" version check is very hacky. (The code in verify is actually buggy because it is comparing the full 32-bit header integer instead of just the revlog version short. I'll likely fix this in a subsequent commit.) Differential Revision: https://phab.mercurial-scm.org/D4701
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 19 Sep 2018 11:17:28 -0700
parents 7a9e2d85f475
children e6d3d39cc1c7
comparison
equal deleted inserted replaced
39841:39f51064e9f5 39842:97986c9c69d3
251 linknode = attr.ib() 251 linknode = attr.ib()
252 flags = attr.ib() 252 flags = attr.ib()
253 baserevisionsize = attr.ib() 253 baserevisionsize = attr.ib()
254 revision = attr.ib() 254 revision = attr.ib()
255 delta = attr.ib() 255 delta = attr.ib()
256
257 @interfaceutil.implementer(repository.iverifyproblem)
258 @attr.s(frozen=True)
259 class revlogproblem(object):
260 warning = attr.ib(default=None)
261 error = attr.ib(default=None)
256 262
257 # index v0: 263 # index v0:
258 # 4 bytes: offset 264 # 4 bytes: offset
259 # 4 bytes: compressed length 265 # 4 bytes: compressed length
260 # 4 bytes: base rev 266 # 4 bytes: base rev
2579 idxread.close() 2585 idxread.close()
2580 idxwrite.close() 2586 idxwrite.close()
2581 if dataread is not idxread: 2587 if dataread is not idxread:
2582 dataread.close() 2588 dataread.close()
2583 datawrite.close() 2589 datawrite.close()
2590
2591 def verifyintegrity(self, state):
2592 """Verifies the integrity of the revlog.
2593
2594 Yields ``revlogproblem`` instances describing problems that are
2595 found.
2596 """
2597 dd, di = self.checksize()
2598 if dd:
2599 yield revlogproblem(error=_('data length off by %d bytes') % dd)
2600 if di:
2601 yield revlogproblem(error=_('index contains %d extra bytes') % di)
2602
2603 if self.version != REVLOGV0:
2604 if not state['revlogv1']:
2605 yield revlogproblem(warning=_("warning: `%s' uses revlog "
2606 "format 1") % self.indexfile)
2607 elif state['revlogv1']:
2608 yield revlogproblem(warning=_("warning: `%s' uses revlog "
2609 "format 0") % self.indexfile)