Patchwork [5,of,6] commands: use revlog._deltachain in debugdeltachain

login
register
mail settings
Submitter Gregory Szorc
Date Dec. 21, 2015, 4:04 a.m.
Message ID <f43c3343c6888d7f1c96.1450670653@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/12199/
State Accepted
Headers show

Comments

Gregory Szorc - Dec. 21, 2015, 4:04 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1450666922 28800
#      Sun Dec 20 19:02:02 2015 -0800
# Node ID f43c3343c6888d7f1c960872091ebd86b3a54d3a
# Parent  db6108f5d52fd9422b0136d30bf93faa06a6b1d0
commands: use revlog._deltachain in debugdeltachain

We have a nice API now. Use it.

This does mean we introduce an extra index lookup for each revision.
Considering this is a debug command, the overhead should be acceptable.
We could add the chain size to revlog._deltachain(). However, that
feels like avoidable overhead.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2537,19 +2537,17 @@  def debugdeltachain(ui, repo, file_=None
        extraratio   extradist divided by chainsize; another representation of
                     how much unrelated data is needed to load this delta chain
     """
     r = cmdutil.openrevlog(repo, 'debugdeltachain', file_, opts)
     index = r.index
     generaldelta = r.version & revlog.REVLOGGENERALDELTA
 
     def revinfo(rev):
-        iterrev = rev
-        e = index[iterrev]
-        chain = []
+        e = index[rev]
         compsize = e[1]
         uncompsize = e[2]
         chainsize = 0
 
         if generaldelta:
             if e[3] == e[5]:
                 deltatype = 'p1'
             elif e[3] == e[6]:
@@ -2561,29 +2559,21 @@  def debugdeltachain(ui, repo, file_=None
             else:
                 deltatype = 'other'
         else:
             if e[3] == rev:
                 deltatype = 'base'
             else:
                 deltatype = 'prev'
 
-        while iterrev != e[3]:
-            chain.append(iterrev)
+        chain = r._deltachain(rev)[0]
+        for iterrev in chain:
+            e = index[iterrev]
             chainsize += e[1]
-            if generaldelta:
-                iterrev = e[3]
-            else:
-                iterrev -= 1
-            e = index[iterrev]
-        else:
-            chainsize += e[1]
-            chain.append(iterrev)
-
-        chain.reverse()
+
         return compsize, uncompsize, deltatype, chain, chainsize
 
     fm = ui.formatter('debugdeltachain', opts)
 
     fm.plain('    rev  chain# chainlen     prev   delta       '
              'size    rawsize  chainsize     ratio   lindist extradist '
              'extraratio\n')