Patchwork [v2] debugindex: respect --debug flag to show full nodeids

login
register
mail settings
Submitter Kyle Lippincott
Date Dec. 13, 2014, 10:11 p.m.
Message ID <0e7a4a3b860e9cc0c76f.1418508673@dragonair.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/7079/
State Accepted
Headers show

Comments

Kyle Lippincott - Dec. 13, 2014, 10:11 p.m.
# HG changeset patch
# User Kyle Lippincott <spectral@google.com>
# Date 1418507765 28800
#      Sat Dec 13 13:56:05 2014 -0800
# Node ID 0e7a4a3b860e9cc0c76f6ac30cb97a4c60824bba
# Parent  e88a634e0195ef2b260f40786505727c80dbdbd5
debugindex: respect --debug flag to show full nodeids
Pierre-Yves David - Dec. 13, 2014, 11:10 p.m.
On 12/13/2014 02:11 PM, Kyle Lippincott wrote:
> # HG changeset patch
> # User Kyle Lippincott <spectral@google.com>
> # Date 1418507765 28800
> #      Sat Dec 13 13:56:05 2014 -0800
> # Node ID 0e7a4a3b860e9cc0c76f6ac30cb97a4c60824bba
> # Parent  e88a634e0195ef2b260f40786505727c80dbdbd5
> debugindex: respect --debug flag to show full nodeids

Pushed to the clowncopter after some fixe.

Patch

diff -r e88a634e0195 -r 0e7a4a3b860e mercurial/commands.py
--- a/mercurial/commands.py	Tue Sep 30 17:13:54 2014 -0700
+++ b/mercurial/commands.py	Sat Dec 13 13:56:05 2014 -0800
@@ -2164,13 +2164,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)
@@ -2185,12 +2196,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_):
diff -r e88a634e0195 -r 0e7a4a3b860e tests/test-debugcommands.t
--- a/tests/test-debugcommands.t	Tue Sep 30 17:13:54 2014 -0700
+++ b/tests/test-debugcommands.t	Sat Dec 13 13:56:05 2014 -0800
@@ -25,6 +25,20 @@ 
   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 internal debugstacktrace command
 
   $ cat > debugstacktrace.py << EOF
@@ -45,3 +59,4 @@ 
    debugstacktrace.py:7 *in * (glob)
    debugstacktrace.py:6 *in g (glob)
    */util.py:* in debugstacktrace (glob)
+