changeset 49790:4302db0f54c8

find-delta: move most of the debug-find-delta code in the debug module Lets us that module more. It will help us to keep revlog implementation details close to each other.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 28 Nov 2022 18:58:35 +0100
parents 0fca63953810
children 05db41701ece
files mercurial/debugcommands.py mercurial/revlogutils/debug.py
diffstat 2 files changed, 57 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/debugcommands.py	Mon Nov 07 20:02:32 2022 -0500
+++ b/mercurial/debugcommands.py	Mon Nov 28 18:58:35 2022 +0100
@@ -58,7 +58,6 @@
     localrepo,
     lock as lockmod,
     logcmdutil,
-    mdiff,
     mergestate as mergestatemod,
     metadata,
     obsolete,
@@ -73,7 +72,6 @@
     repoview,
     requirements,
     revlog,
-    revlogutils,
     revset,
     revsetlang,
     scmutil,
@@ -1029,54 +1027,22 @@
     rev = int(rev)
 
     revlog = cmdutil.openrevlog(repo, b'debugdeltachain', file_, opts)
-
-    deltacomputer = deltautil.deltacomputer(
-        revlog,
-        write_debug=ui.write,
-        debug_search=not ui.quiet,
-    )
-
-    node = revlog.node(rev)
     p1r, p2r = revlog.parentrevs(rev)
-    p1 = revlog.node(p1r)
-    p2 = revlog.node(p2r)
-    full_text = revlog.revision(rev)
-    btext = [full_text]
-    textlen = len(btext[0])
-    cachedelta = None
-    flags = revlog.flags(rev)
-
-    if source != b'full':
-        if source == b'storage':
-            base_rev = revlog.deltaparent(rev)
-        elif source == b'p1':
-            base_rev = p1r
-        elif source == b'p2':
-            base_rev = p2r
-        elif source == b'prev':
-            base_rev = rev - 1
-        else:
-            raise error.InputError(b"invalid --source value: %s" % source)
-
-        if base_rev != nullrev:
-            base_text = revlog.revision(base_rev)
-            delta = mdiff.textdiff(base_text, full_text)
-
-            cachedelta = (base_rev, delta)
-            btext = [None]
-
-    revinfo = revlogutils.revisioninfo(
-        node,
-        p1,
-        p2,
-        btext,
-        textlen,
-        cachedelta,
-        flags,
-    )
-
-    fh = revlog._datafp()
-    deltacomputer.finddeltainfo(revinfo, fh, target_rev=rev)
+
+    if source == b'full':
+        base_rev = nullrev
+    elif source == b'storage':
+        base_rev = revlog.deltaparent(rev)
+    elif source == b'p1':
+        base_rev = p1r
+    elif source == b'p2':
+        base_rev = p2r
+    elif source == b'prev':
+        base_rev = rev - 1
+    else:
+        raise error.InputError(b"invalid --source value: %s" % source)
+
+    revlog_debug.debug_delta_find(ui, revlog, rev, base_rev=base_rev)
 
 
 @command(
--- a/mercurial/revlogutils/debug.py	Mon Nov 07 20:02:32 2022 -0500
+++ b/mercurial/revlogutils/debug.py	Mon Nov 28 18:58:35 2022 +0100
@@ -10,12 +10,15 @@
 import string
 
 from .. import (
+    mdiff,
     node as nodemod,
+    revlogutils,
     util,
 )
 
 from . import (
     constants,
+    deltas as deltautil,
 )
 
 INDEX_ENTRY_DEBUG_COLUMN = []
@@ -619,3 +622,42 @@
                 b'deltas against other : '
                 + fmt % pcfmt(numother_nad, numdeltas)
             )
+
+
+def debug_delta_find(ui, revlog, rev, base_rev=nodemod.nullrev):
+    """display the search process for a delta"""
+    deltacomputer = deltautil.deltacomputer(
+        revlog,
+        write_debug=ui.write,
+        debug_search=not ui.quiet,
+    )
+
+    node = revlog.node(rev)
+    p1r, p2r = revlog.parentrevs(rev)
+    p1 = revlog.node(p1r)
+    p2 = revlog.node(p2r)
+    full_text = revlog.revision(rev)
+    btext = [full_text]
+    textlen = len(btext[0])
+    cachedelta = None
+    flags = revlog.flags(rev)
+
+    if base_rev != nodemod.nullrev:
+        base_text = revlog.revision(base_rev)
+        delta = mdiff.textdiff(base_text, full_text)
+
+        cachedelta = (base_rev, delta)
+        btext = [None]
+
+    revinfo = revlogutils.revisioninfo(
+        node,
+        p1,
+        p2,
+        btext,
+        textlen,
+        cachedelta,
+        flags,
+    )
+
+    fh = revlog._datafp()
+    deltacomputer.finddeltainfo(revinfo, fh, target_rev=rev)