Patchwork debugrevlog: add chainlen column to --dump output

login
register
mail settings
Submitter Sune Foldager
Date Aug. 30, 2014, 10:39 a.m.
Message ID <409d94bbb1cfb81bdad6.1409395185@firefly.edlund.dk>
Download mbox | patch
Permalink /patch/5629/
State Accepted
Headers show

Comments

Sune Foldager - Aug. 30, 2014, 10:39 a.m.
# HG changeset patch
# User Sune Foldager <cryo@cyanite.org>
# Date 1409392666 -7200
#      Sat Aug 30 11:57:46 2014 +0200
# Node ID 409d94bbb1cfb81bdad6480e35fde32a8f928c17
# Parent  bdc0e04df243d3995c7266bf7d138fddd0449ba6
debugrevlog: add chainlen column to --dump output
Matt Mackall - Aug. 30, 2014, 12:57 p.m.
On Sat, 2014-08-30 at 12:39 +0200, Sune Foldager wrote:
> # HG changeset patch
> # User Sune Foldager <cryo@cyanite.org>
> # Date 1409392666 -7200
> #      Sat Aug 30 11:57:46 2014 +0200
> # Node ID 409d94bbb1cfb81bdad6480e35fde32a8f928c17
> # Parent  bdc0e04df243d3995c7266bf7d138fddd0449ba6
> debugrevlog: add chainlen column to --dump output

Queued for default, thanks.

Patch

diff -r bdc0e04df243 -r 409d94bbb1cf mercurial/commands.py
--- a/mercurial/commands.py	Wed Aug 27 18:35:34 2014 +0200
+++ b/mercurial/commands.py	Sat Aug 30 11:57:46 2014 +0200
@@ -2536,24 +2536,36 @@ 
     if opts.get("dump"):
         numrevs = len(r)
         ui.write("# rev p1rev p2rev start   end deltastart base   p1   p2"
-                 " rawsize totalsize compression heads\n")
+                 " rawsize totalsize compression heads chainlen\n")
         ts = 0
         heads = set()
+        rindex = r.index
+
+        def chainbaseandlen(rev):
+            clen = 0
+            base = rindex[rev][3]
+            while base != rev:
+                clen += 1
+                rev = base
+                base = rindex[rev][3]
+            return base, clen
+
         for rev in xrange(numrevs):
             dbase = r.deltaparent(rev)
             if dbase == -1:
                 dbase = rev
-            cbase = r.chainbase(rev)
+            cbase, clen = chainbaseandlen(rev)
             p1, p2 = r.parentrevs(rev)
             rs = r.rawsize(rev)
             ts = ts + rs
             heads -= set(r.parentrevs(rev))
             heads.add(rev)
-            ui.write("%5d %5d %5d %5d %5d %10d %4d %4d %4d %7d %9d %11d %5d\n" %
+            ui.write("%5d %5d %5d %5d %5d %10d %4d %4d %4d %7d %9d "
+                     "%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, ts / r.end(rev), len(heads)))
+                      rs, ts, ts / r.end(rev), len(heads), clen))
         return 0
 
     v = r.version
diff -r bdc0e04df243 -r 409d94bbb1cf tests/test-obsolete.t
--- a/tests/test-obsolete.t	Wed Aug 27 18:35:34 2014 +0200
+++ b/tests/test-obsolete.t	Sat Aug 30 11:57:46 2014 +0200
@@ -88,11 +88,11 @@ 
   $ hg log -r 'hidden()' --template '{rev}:{node|short} {desc}\n' --hidden
   2:245bde4270cd add original_c
   $ hg debugrevlog -cd
-  # rev p1rev p2rev start   end deltastart base   p1   p2 rawsize totalsize compression heads
-      0    -1    -1     0    59          0    0    0    0      58        58           0     1
-      1     0    -1    59   118         59   59    0    0      58       116           0     1
-      2     1    -1   118   204         59   59   59    0      76       192           0     1
-      3     1    -1   204   271        204  204   59    0      66       258           0     2
+  # rev p1rev p2rev start   end deltastart base   p1   p2 rawsize totalsize compression heads chainlen
+      0    -1    -1     0    59          0    0    0    0      58        58           0     1        0
+      1     0    -1    59   118         59   59    0    0      58       116           0     1        0
+      2     1    -1   118   204         59   59   59    0      76       192           0     1        1
+      3     1    -1   204   271        204  204   59    0      66       258           0     2        0
   $ hg debugobsolete
   245bde4270cd1072a27757984f9cda8ba26f08ca cdbce2fbb16313928851e97e0d85413f3f7eb77f C (Thu Jan 01 00:00:44 1970 -0000) {'user': 'test'}