[PATCH 2 of 6] debugformat: add a 'debugformat' command

Boris Feld boris.feld at octobus.net
Fri Dec 8 05:58:01 EST 2017


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1512659986 -3600
#      Thu Dec 07 16:19:46 2017 +0100
# Node ID 98baa863b15b6168076dc8d1ae87f22f7cac6746
# Parent  88ae8b7114e294c3bc641611324f1a7b023a1f5e
# EXP-Topic upgrade
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 98baa863b15b
debugformat: add a 'debugformat' command

The command displays basic data about all format variants registered for repo
upgrades. This gives a quick way to peek into a repository format.

The 'fm.write()' calls are very independent because more data will be added in
later changeset. Having more separate call make the later patch clearer.

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -859,6 +859,38 @@ def debugfileset(ui, repo, expr, **opts)
     for f in ctx.getfileset(expr):
         ui.write("%s\n" % f)
 
+ at command('debugformat',
+         [] + cmdutil.formatteropts,
+        _(''))
+def debugformat(ui, repo, **opts):
+    """display format information about the current repository"""
+    maxvariantlength = max(len(fv.name) for fv in upgrade.allformatvariant)
+    maxvariantlength = max(len('format-variant'), maxvariantlength)
+
+    def makeformatname(name):
+        return '%s:' + (' ' * (maxvariantlength - len(name)))
+
+    def formatvalue(value):
+        if value:
+            return 'yes'
+        else:
+            return 'no'
+
+    fm = ui.formatter('debugformat', opts)
+    fm.plain('format-variant')
+    fm.plain(' ' * (maxvariantlength - len('format-variant')))
+    fm.plain(' repo')
+    fm.plain('\n')
+    fm.startitem()
+    for fv in upgrade.allformatvariant:
+        repovalue = fv.fromrepo(repo)
+
+        fm.write('name', makeformatname(fv.name), fv.name,
+                 label='formatvariant.name')
+        fm.write('repo', ' %3s', formatvalue(repovalue),
+                 label='formatvariant.repo')
+        fm.plain('\n')
+
 @command('debugfsinfo', [], _('[PATH]'), norepo=True)
 def debugfsinfo(ui, path="."):
     """show information detected about current filesystem"""
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -87,6 +87,7 @@ Show debug commands if there are no othe
   debugdiscovery
   debugextensions
   debugfileset
+  debugformat
   debugfsinfo
   debuggetbundle
   debugignore
@@ -264,6 +265,7 @@ Show all commands + options
   debugdiscovery: old, nonheads, rev, ssh, remotecmd, insecure
   debugextensions: template
   debugfileset: rev
+  debugformat: template
   debugfsinfo: 
   debuggetbundle: head, common, type
   debugignore: 
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -922,6 +922,7 @@ Test list of internal help commands
    debugextensions
                  show information about active extensions
    debugfileset  parse and apply a fileset specification
+   debugformat   display format information about the current repository
    debugfsinfo   show information detected about current filesystem
    debuggetbundle
                  retrieves a bundle from a repo
diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
--- a/tests/test-upgrade-repo.t
+++ b/tests/test-upgrade-repo.t
@@ -54,6 +54,12 @@ An upgrade of a repository created with 
 
   $ hg init empty
   $ cd empty
+  $ hg debugformat
+  format-variant repo
+  fncache:        yes
+  dotencode:      yes
+  generaldelta:   yes
+  plain-cl-delta: yes
   $ hg debugupgraderepo
   (no feature deficiencies found in existing repository)
   performing an upgrade with "--run" will make the following changes:
@@ -101,6 +107,12 @@ Various sub-optimal detections work
   > store
   > EOF
 
+  $ hg debugformat
+  format-variant repo
+  fncache:         no
+  dotencode:       no
+  generaldelta:    no
+  plain-cl-delta: yes
   $ hg debugupgraderepo
   repository lacks features recommended by current config options:
   


More information about the Mercurial-devel mailing list