##// END OF EJS Templates
debugindex: move to a flexible column...
marmoute -
r50148:a3213042 default
parent child Browse files
Show More
@@ -1877,11 +1877,13 b' def debugindex(ui, repo, file_=None, **o'
1877
1877
1878 fm = ui.formatter(b'debugindex', opts)
1878 fm = ui.formatter(b'debugindex', opts)
1879
1879
1880 revlog = getattr(store, b'_revlog', store)
1881
1880 return revlog_debug.debug_index(
1882 return revlog_debug.debug_index(
1881 ui,
1883 ui,
1882 repo,
1884 repo,
1883 formatter=fm,
1885 formatter=fm,
1884 revlog=store,
1886 revlog=revlog,
1885 full_node=ui.debugflag,
1887 full_node=ui.debugflag,
1886 )
1888 )
1887
1889
@@ -10,6 +10,86 b' from .. import ('
10 node as nodemod,
10 node as nodemod,
11 )
11 )
12
12
13 from . import (
14 constants,
15 )
16
17 INDEX_ENTRY_DEBUG_COLUMN = []
18
19 NODE_SIZE = object()
20
21
22 class _column_base:
23 """constains the definition of a revlog column
24
25 name: the column header,
26 value_func: the function called to get a value,
27 size: the width of the column.
28 """
29
30 def __init__(self, name, value_func, size=None):
31 self.name = name
32 self.value_func = value_func
33 if size is not NODE_SIZE:
34 if size is None:
35 size = 8 # arbitrary default
36 size = max(len(name), size)
37 self._size = size
38
39 def get_size(self, node_size):
40 if self._size is NODE_SIZE:
41 return node_size
42 else:
43 return self._size
44
45
46 def debug_column(name, size=None):
47 """decorated function is registered as a column
48
49 name: the name of the column,
50 size: the expected size of the column.
51 """
52
53 def register(func):
54 entry = _column_base(
55 name=name,
56 value_func=func,
57 size=size,
58 )
59 INDEX_ENTRY_DEBUG_COLUMN.append(entry)
60 return entry
61
62 return register
63
64
65 @debug_column(b"rev", size=6)
66 def _rev(index, rev, entry, hexfn):
67 return b"%d" % rev
68
69
70 @debug_column(b"linkrev", size=6)
71 def _linkrev(index, rev, entry, hexfn):
72 return b"%d" % entry[constants.ENTRY_LINK_REV]
73
74
75 @debug_column(b"nodeid", size=NODE_SIZE)
76 def _nodeid(index, rev, entry, hexfn):
77 return hexfn(entry[constants.ENTRY_NODE_ID])
78
79
80 @debug_column(b"p1-nodeid", size=NODE_SIZE)
81 def _p1_node(index, rev, entry, hexfn):
82 parent = entry[constants.ENTRY_PARENT_1]
83 p_entry = index[parent]
84 return hexfn(p_entry[constants.ENTRY_NODE_ID])
85
86
87 @debug_column(b"p2-nodeid", size=NODE_SIZE)
88 def _p2_node(index, rev, entry, hexfn):
89 parent = entry[constants.ENTRY_PARENT_2]
90 p_entry = index[parent]
91 return hexfn(p_entry[constants.ENTRY_NODE_ID])
92
13
93
14 def debug_index(
94 def debug_index(
15 ui,
95 ui,
@@ -31,25 +111,29 b' def debug_index('
31
111
32 fm = formatter
112 fm = formatter
33
113
34 fm.plain(
114 header_pieces = []
35 b' rev linkrev %s %s %s\n'
115 for column in INDEX_ENTRY_DEBUG_COLUMN:
36 % (
116 size = column.get_size(idlen)
37 b'nodeid'.rjust(idlen),
117 name = column.name
38 b'p1-nodeid'.rjust(idlen),
118 header_pieces.append(name.rjust(size))
39 b'p2-nodeid'.rjust(idlen),
119
40 )
120 fm.plain(b' '.join(header_pieces) + b'\n')
41 )
121
122 index = revlog.index
42
123
43 for rev in revlog:
124 for rev in revlog:
44 node = revlog.node(rev)
125 fm.startitem()
45 parents = revlog.parents(node)
126 entry = index[rev]
127 first = True
128 for column in INDEX_ENTRY_DEBUG_COLUMN:
129 if not first:
130 fm.plain(b' ')
131 first = False
46
132
47 fm.startitem()
133 size = column.get_size(idlen)
48 fm.write(b'rev', b'%6d ', rev)
134 value = column.value_func(index, rev, entry, hexfn)
49 fm.write(b'linkrev', b'%7d ', revlog.linkrev(rev))
135 display = b"%%%ds" % size
50 fm.write(b'node', b'%s ', hexfn(node))
136 fm.write(column.name, display, value)
51 fm.write(b'p1', b'%s ', hexfn(parents[0]))
52 fm.write(b'p2', b'%s', hexfn(parents[1]))
53 fm.plain(b'\n')
137 fm.plain(b'\n')
54
138
55 fm.end()
139 fm.end()
General Comments 0
You need to be logged in to leave comments. Login now