changeset 23547:21446f4d5c62

debugindex: respect --debug flag to show full nodeids
author Kyle Lippincott <spectral@google.com>
date Sat, 13 Dec 2014 13:56:05 -0800
parents deabbe7ed54b
children 141baca16059
files mercurial/commands.py tests/test-debugcommands.t
diffstat 2 files changed, 30 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Fri Dec 12 14:06:36 2014 -0800
+++ b/mercurial/commands.py	Sat Dec 13 13:56:05 2014 -0800
@@ -2173,13 +2173,24 @@
     else:
         basehdr = '  base'
 
+    if ui.debugflag:
+        shortfn = hex
+    else:
+        shortfn = short
+
+    # There might not be anything in r, so have a sane default
+    idlen = 12
+    for i in r:
+        idlen = len(shortfn(r.node(i)))
+        break
+
     if format == 0:
         ui.write("   rev    offset  length " + basehdr + " linkrev"
-                 " nodeid       p1           p2\n")
+                 " %s %s p2\n" % ("nodeid".ljust(idlen), "p1".ljust(idlen)))
     elif format == 1:
         ui.write("   rev flag   offset   length"
                  "     size " + basehdr + "   link     p1     p2"
-                 "       nodeid\n")
+                 " %s\n" % "nodeid".rjust(idlen))
 
     for i in r:
         node = r.node(i)
@@ -2194,12 +2205,12 @@
                 pp = [nullid, nullid]
             ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % (
                     i, r.start(i), r.length(i), base, r.linkrev(i),
-                    short(node), short(pp[0]), short(pp[1])))
+                    shortfn(node), shortfn(pp[0]), shortfn(pp[1])))
         elif format == 1:
             pr = r.parentrevs(i)
             ui.write("% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d % 6d %s\n" % (
                     i, r.flags(i), r.start(i), r.length(i), r.rawsize(i),
-                    base, r.linkrev(i), pr[0], pr[1], short(node)))
+                    base, r.linkrev(i), pr[0], pr[1], shortfn(node)))
 
 @command('debugindexdot', [], _('FILE'), optionalrepo=True)
 def debugindexdot(ui, repo, file_):
--- a/tests/test-debugcommands.t	Fri Dec 12 14:06:36 2014 -0800
+++ b/tests/test-debugcommands.t	Sat Dec 13 13:56:05 2014 -0800
@@ -24,6 +24,21 @@
   full revision size (min/max/avg)     : 44 / 44 / 44
   delta size (min/max/avg)             : 0 / 0 / 0
 
+Test debugindex, with and without the --debug flag
+  $ hg debugindex a
+     rev    offset  length   .... linkrev nodeid       p1           p2 (re)
+       0         0       3   ....       0 b789fdd96dc2 000000000000 000000000000 (re)
+  $ hg --debug debugindex a
+     rev    offset  length   .... linkrev nodeid                                   p1                                       p2 (re)
+       0         0       3   ....       0 b789fdd96dc2f3bd229c1dd8eedf0fc60e2b68e3 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 (re)
+  $ hg debugindex -f 1 a
+     rev flag   offset   length     size   ....   link     p1     p2       nodeid (re)
+       0 0000        0        3        2   ....      0     -1     -1 b789fdd96dc2 (re)
+  $ hg --debug debugindex -f 1 a
+     rev flag   offset   length     size   ....   link     p1     p2                                   nodeid (re)
+       0 0000        0        3        2   ....      0     -1     -1 b789fdd96dc2f3bd229c1dd8eedf0fc60e2b68e3 (re)
+
+
 Test max chain len
   $ cat >> $HGRCPATH << EOF
   > [format]