Mercurial > public > mercurial-scm > hg-stable
diff mercurial/revlogutils/nodemap.py @ 44361:20e125cdd719
nodemap: add basic checking of the on disk nodemap content
The simplest check it so verify we have all the revision we needs, and nothing
more.
Differential Revision: https://phab.mercurial-scm.org/D7845
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 15 Jan 2020 15:48:57 +0100 |
parents | 78721bbdb2ab |
children | d58206b70199 |
line wrap: on
line diff
--- a/mercurial/revlogutils/nodemap.py Wed Jan 15 15:48:47 2020 +0100 +++ b/mercurial/revlogutils/nodemap.py Wed Jan 15 15:48:57 2020 +0100 @@ -337,3 +337,37 @@ else: b[idx] = _transform_rev(v) return block + + +# debug utility + + +def check_data(ui, index, data): + """verify that the provided nodemap data are valid for the given idex""" + ret = 0 + ui.status((b"revision in index: %d\n") % len(index)) + root = parse_data(data) + all_revs = set(_all_revisions(root)) + ui.status((b"revision in nodemap: %d\n") % len(all_revs)) + for r in range(len(index)): + if r not in all_revs: + msg = b" revision missing from nodemap: %d\n" % r + ui.write_err(msg) + ret = 1 + else: + all_revs.remove(r) + if all_revs: + for r in sorted(all_revs): + msg = b" extra revision in nodemap: %d\n" % r + ui.write_err(msg) + ret = 1 + return ret + + +def _all_revisions(root): + """return all revisions stored in a Trie""" + for block in _walk_trie(root): + for v in block: + if v is None or isinstance(v, Block): + continue + yield v