changeset 49659:7c0a383849a8

debug-revlog: move the --dump code in `revlogutils` module We have a module dedicated to debug code, let us use it.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 07 Nov 2022 14:13:59 -0500
parents 523cacdfd324
children bd3b6f363fb9
files mercurial/debugcommands.py mercurial/revlogutils/debug.py
diffstat 2 files changed, 52 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/debugcommands.py	Wed Nov 23 19:08:27 2022 +0100
+++ b/mercurial/debugcommands.py	Mon Nov 07 14:13:59 2022 -0500
@@ -3240,51 +3240,7 @@
     r = cmdutil.openrevlog(repo, b'debugrevlog', file_, opts)
 
     if opts.get(b"dump"):
-        numrevs = len(r)
-        ui.write(
-            (
-                b"# rev p1rev p2rev start   end deltastart base   p1   p2"
-                b" rawsize totalsize compression heads chainlen\n"
-            )
-        )
-        ts = 0
-        heads = set()
-
-        for rev in range(numrevs):
-            dbase = r.deltaparent(rev)
-            if dbase == -1:
-                dbase = rev
-            cbase = r.chainbase(rev)
-            clen = r.chainlen(rev)
-            p1, p2 = r.parentrevs(rev)
-            rs = r.rawsize(rev)
-            ts = ts + rs
-            heads -= set(r.parentrevs(rev))
-            heads.add(rev)
-            try:
-                compression = ts / r.end(rev)
-            except ZeroDivisionError:
-                compression = 0
-            ui.write(
-                b"%5d %5d %5d %5d %5d %10d %4d %4d %4d %7d %9d "
-                b"%11d %5d %8d\n"
-                % (
-                    rev,
-                    p1,
-                    p2,
-                    r.start(rev),
-                    r.end(rev),
-                    r.start(dbase),
-                    r.start(cbase),
-                    r.start(p1),
-                    r.start(p2),
-                    rs,
-                    ts,
-                    compression,
-                    len(heads),
-                    clen,
-                )
-            )
+        revlog_debug.dump(ui, r)
         return 0
 
     format = r._format_version
--- a/mercurial/revlogutils/debug.py	Wed Nov 23 19:08:27 2022 +0100
+++ b/mercurial/revlogutils/debug.py	Mon Nov 07 14:13:59 2022 -0500
@@ -216,3 +216,54 @@
         fm.plain(b'\n')
 
     fm.end()
+
+
+def dump(ui, revlog):
+    """perform the work for `hg debugrevlog --dump"""
+    # XXX seems redundant with debug index ?
+    r = revlog
+    numrevs = len(r)
+    ui.write(
+        (
+            b"# rev p1rev p2rev start   end deltastart base   p1   p2"
+            b" rawsize totalsize compression heads chainlen\n"
+        )
+    )
+    ts = 0
+    heads = set()
+
+    for rev in range(numrevs):
+        dbase = r.deltaparent(rev)
+        if dbase == -1:
+            dbase = rev
+        cbase = r.chainbase(rev)
+        clen = r.chainlen(rev)
+        p1, p2 = r.parentrevs(rev)
+        rs = r.rawsize(rev)
+        ts = ts + rs
+        heads -= set(r.parentrevs(rev))
+        heads.add(rev)
+        try:
+            compression = ts / r.end(rev)
+        except ZeroDivisionError:
+            compression = 0
+        ui.write(
+            b"%5d %5d %5d %5d %5d %10d %4d %4d %4d %7d %9d "
+            b"%11d %5d %8d\n"
+            % (
+                rev,
+                p1,
+                p2,
+                r.start(rev),
+                r.end(rev),
+                r.start(dbase),
+                r.start(cbase),
+                r.start(p1),
+                r.start(p2),
+                rs,
+                ts,
+                compression,
+                len(heads),
+                clen,
+            )
+        )