comparison mercurial/revlogutils/debug.py @ 49250:61cf3d39fd9e

debugindex: move the logic into its own module Adding more information will significantly increase the amount of code. So we move the code into its own module before making it more complex.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 30 May 2022 23:24:14 +0200
parents
children ccd76e292be5
comparison
equal deleted inserted replaced
49249:db19f6be0442 49250:61cf3d39fd9e
1 # revlogutils/debug.py - utility used for revlog debuging
2 #
3 # Copyright 2005-2007 Olivia Mackall <olivia@selenic.com>
4 # Copyright 2022 Octobus <contact@octobus.net>
5 #
6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2 or any later version.
8
9 from .. import (
10 node as nodemod,
11 )
12
13
14 def debug_index(
15 ui,
16 repo,
17 formatter,
18 revlog,
19 full_node,
20 ):
21 """display index data for a revlog"""
22 if full_node:
23 hexfn = nodemod.hex
24 else:
25 hexfn = nodemod.short
26
27 idlen = 12
28 for i in revlog:
29 idlen = len(hexfn(revlog.node(i)))
30 break
31
32 fm = formatter
33
34 fm.plain(
35 b' rev linkrev %s %s p2\n'
36 % (b'nodeid'.ljust(idlen), b'p1'.ljust(idlen))
37 )
38
39 for rev in revlog:
40 node = revlog.node(rev)
41 parents = revlog.parents(node)
42
43 fm.startitem()
44 fm.write(b'rev', b'%6d ', rev)
45 fm.write(b'linkrev', b'%7d ', revlog.linkrev(rev))
46 fm.write(b'node', b'%s ', hexfn(node))
47 fm.write(b'p1', b'%s ', hexfn(parents[0]))
48 fm.write(b'p2', b'%s', hexfn(parents[1]))
49 fm.plain(b'\n')
50
51 fm.end()