debugindex: introduce a concept of "verbose-only" column
authorPierre-Yves DAVID <pierre-yves.david@octobus.net>
Wed, 01 Jun 2022 00:54:19 +0200
changeset 49269 69983adfed06
parent 49268 a321304269cf
child 49270 251650844331
debugindex: introduce a concept of "verbose-only" column We are about to add a bunch of new column and most of them are probably only relevant to --verbose. We add some more testing of the `--verbose` mode in a sidedata context.
mercurial/revlogutils/debug.py
tests/test-sidedata.t
--- a/mercurial/revlogutils/debug.py	Wed Jun 01 00:59:44 2022 +0200
+++ b/mercurial/revlogutils/debug.py	Wed Jun 01 00:54:19 2022 +0200
@@ -22,12 +22,13 @@
 class _column_base:
     """constains the definition of a revlog column
 
-    name:       the column header,
-    value_func: the function called to get a value,
-    size:       the width of the column.
+    name:         the column header,
+    value_func:   the function called to get a value,
+    size:         the width of the column,
+    verbose_only: only include the column in verbose mode.
     """
 
-    def __init__(self, name, value_func, size=None):
+    def __init__(self, name, value_func, size=None, verbose=False):
         self.name = name
         self.value_func = value_func
         if size is not NODE_SIZE:
@@ -35,6 +36,7 @@
                 size = 8  # arbitrary default
             size = max(len(name), size)
         self._size = size
+        self.verbose_only = verbose
 
     def get_size(self, node_size):
         if self._size is NODE_SIZE:
@@ -43,7 +45,7 @@
             return self._size
 
 
-def debug_column(name, size=None):
+def debug_column(name, size=None, verbose=False):
     """decorated function is registered as a column
 
     name: the name of the column,
@@ -55,6 +57,7 @@
             name=name,
             value_func=func,
             size=size,
+            verbose=verbose,
         )
         INDEX_ENTRY_DEBUG_COLUMN.append(entry)
         return entry
@@ -113,6 +116,8 @@
 
     header_pieces = []
     for column in INDEX_ENTRY_DEBUG_COLUMN:
+        if column.verbose_only and not ui.verbose:
+            continue
         size = column.get_size(idlen)
         name = column.name
         header_pieces.append(name.rjust(size))
@@ -126,6 +131,8 @@
         entry = index[rev]
         first = True
         for column in INDEX_ENTRY_DEBUG_COLUMN:
+            if column.verbose_only and not ui.verbose:
+                continue
             if not first:
                 fm.plain(b' ')
             first = False
--- a/tests/test-sidedata.t	Wed Jun 01 00:59:44 2022 +0200
+++ b/tests/test-sidedata.t	Wed Jun 01 00:54:19 2022 +0200
@@ -40,6 +40,18 @@
    entry-0001 size 4
    entry-0002 size 32
 
+  $ hg debug-revlog-index --verbose -c
+     rev linkrev       nodeid    p1-nodeid    p2-nodeid
+       0       0 7049e48789d7 000000000000 000000000000
+       1       1 2707720c6597 7049e48789d7 000000000000
+       2       2 40f977031323 2707720c6597 000000000000
+
+  $ hg debug-revlog-index --verbose -m
+     rev linkrev       nodeid    p1-nodeid    p2-nodeid
+       0       0 b85d294330e3 000000000000 000000000000
+       1       1 1a0aec305c63 b85d294330e3 000000000000
+       2       2 104258a4f75f 1a0aec305c63 000000000000
+
 Check upgrade behavior
 ======================