debugrevlog: add chainlen column to --dump output
authorSune Foldager <cryo@cyanite.org>
Sat, 30 Aug 2014 11:57:46 +0200
changeset 22311 5038dee5bdd6
parent 22310 aabf367306d5
child 22312 8b980fbbd6dc
debugrevlog: add chainlen column to --dump output
mercurial/commands.py
tests/test-obsolete.t
--- a/mercurial/commands.py	Sat Aug 30 11:56:33 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
--- a/tests/test-obsolete.t	Sat Aug 30 11:56:33 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'}