Patchwork [4,of,5] commands: teach debugbundle to print bundle specification

login
register
mail settings
Submitter Gregory Szorc
Date Jan. 15, 2016, 7:01 a.m.
Message ID <7a8ffc23529223ac2de2.1452841312@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/12785/
State Accepted
Headers show

Comments

Gregory Szorc - Jan. 15, 2016, 7:01 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1452841075 28800
#      Thu Jan 14 22:57:55 2016 -0800
# Node ID 7a8ffc23529223ac2de256a66e1b1eb14b7491f1
# Parent  f550f2d4fa1553430185069d3e2954366b8ded13
commands: teach debugbundle to print bundle specification

This seems like the most logical place to put this functionality.

Test coverage over existing known bundle specs has been added.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2008,22 +2008,28 @@  def debugbuilddag(ui, repo, text=None,
 
         if tags:
             repo.vfs.write("localtags", "".join(tags))
     finally:
         ui.progress(_('building'), None)
         release(tr, lock)
 
 @command('debugbundle',
-        [('a', 'all', None, _('show all details'))],
+        [('a', 'all', None, _('show all details')),
+         ('', 'spec', None, _('print the bundlespec of the bundle'))],
         _('FILE'),
         norepo=True)
-def debugbundle(ui, bundlepath, all=None, **opts):
+def debugbundle(ui, bundlepath, all=None, spec=None, **opts):
     """lists the contents of a bundle"""
     with hg.openpath(ui, bundlepath) as f:
+        if spec:
+            spec = exchange.getbundlespec(ui, f)
+            ui.write('%s\n' % spec)
+            return
+
         gen = exchange.readbundle(ui, f, bundlepath)
         if isinstance(gen, bundle2.unbundle20):
             return _debugbundle2(ui, gen, all=all, **opts)
         if all:
             ui.write(("format: id, p1, p2, cset, delta base, len(delta)\n"))
 
             def showchunks(named):
                 ui.write("\n%s\n" % named)
diff --git a/tests/test-bundle-type.t b/tests/test-bundle-type.t
--- a/tests/test-bundle-type.t
+++ b/tests/test-bundle-type.t
@@ -38,70 +38,78 @@  test bundle types
   $ for t in "None" "bzip2" "gzip" "none-v2" "v2" "v1" "gzip-v1"; do
   >   echo % test bundle type $t
   >   hg init t$t
   >   cd t1
   >   hg bundle -t $t ../b$t ../t$t
   >   f -q -B6 -D ../b$t; echo
   >   cd ../t$t
   >   hg debugbundle ../b$t
+  >   hg debugbundle --spec ../b$t
   >   echo
   >   cd ..
   > done
   % test bundle type None
   searching for changes
   1 changesets found
   HG20\x00\x00 (esc)
   Stream params: {}
   changegroup -- "{'version': '02'}"
       c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
+  none-v2
   
   % test bundle type bzip2
   searching for changes
   1 changesets found
   HG20\x00\x00 (esc)
   Stream params: {'Compression': 'BZ'}
   changegroup -- "{'version': '02'}"
       c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
+  bzip2-v2
   
   % test bundle type gzip
   searching for changes
   1 changesets found
   HG20\x00\x00 (esc)
   Stream params: {'Compression': 'GZ'}
   changegroup -- "{'version': '02'}"
       c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
+  gzip-v2
   
   % test bundle type none-v2
   searching for changes
   1 changesets found
   HG20\x00\x00 (esc)
   Stream params: {}
   changegroup -- "{'version': '02'}"
       c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
+  none-v2
   
   % test bundle type v2
   searching for changes
   1 changesets found
   HG20\x00\x00 (esc)
   Stream params: {'Compression': 'BZ'}
   changegroup -- "{'version': '02'}"
       c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
+  bzip2-v2
   
   % test bundle type v1
   searching for changes
   1 changesets found
   HG10BZ
   c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
+  bzip2-v1
   
   % test bundle type gzip-v1
   searching for changes
   1 changesets found
   HG10GZ
   c35a0f9217e65d1fdb90c936ffa7dbe679f83ddf
+  gzip-v1
   
 
 test garbage file
 
   $ echo garbage > bgarbage
   $ hg init tgarbage
   $ cd tgarbage
   $ hg pull ../bgarbage
diff --git a/tests/test-bundle.t b/tests/test-bundle.t
--- a/tests/test-bundle.t
+++ b/tests/test-bundle.t
@@ -271,16 +271,19 @@  packed1 is produced properly
 
   $ f -B 64 --size --sha1 --hexdump packed.hg
   packed.hg: size=2826, sha1=e139f97692a142b19cdcff64a69697d5307ce6d4
   0000: 48 47 53 31 55 4e 00 00 00 00 00 00 00 06 00 00 |HGS1UN..........|
   0010: 00 00 00 00 0a 67 00 16 67 65 6e 65 72 61 6c 64 |.....g..generald|
   0020: 65 6c 74 61 2c 72 65 76 6c 6f 67 76 31 00 64 61 |elta,revlogv1.da|
   0030: 74 61 2f 61 64 69 66 66 65 72 65 6e 74 66 69 6c |ta/adifferentfil|
 
+  $ hg debugbundle --spec packed.hg
+  none-packed1;requirements%3Dgeneraldelta%2Crevlogv1
+
 generaldelta requirement is listed in stream clone bundles
 
   $ hg --config format.generaldelta=true init testgd
   $ cd testgd
   $ touch foo
   $ hg -q commit -A -m initial
   $ cd ..
   $ hg -R testgd debugcreatestreamclonebundle packedgd.hg
@@ -289,16 +292,19 @@  generaldelta requirement is listed in st
 
   $ f -B 64 --size --sha1 --hexdump packedgd.hg
   packedgd.hg: size=396, sha1=981f9e589799335304a5a9a44caa3623a48d2a9f
   0000: 48 47 53 31 55 4e 00 00 00 00 00 00 00 03 00 00 |HGS1UN..........|
   0010: 00 00 00 00 01 2d 00 16 67 65 6e 65 72 61 6c 64 |.....-..generald|
   0020: 65 6c 74 61 2c 72 65 76 6c 6f 67 76 31 00 64 61 |elta,revlogv1.da|
   0030: 74 61 2f 66 6f 6f 2e 69 00 36 34 0a 00 03 00 01 |ta/foo.i.64.....|
 
+  $ hg debugbundle --spec packedgd.hg
+  none-packed1;requirements%3Dgeneraldelta%2Crevlogv1
+
 Unpacking packed1 bundles with "hg unbundle" isn't allowed
 
   $ hg init packed
   $ hg -R packed unbundle packed.hg
   abort: packed bundles cannot be applied with "hg unbundle"
   (use "hg debugapplystreamclonebundle")
   [255]
 
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -231,17 +231,17 @@  Show all commands + options
   branches: active, closed, template
   bundle: force, rev, branch, base, all, type, ssh, remotecmd, insecure
   cat: output, rev, decode, include, exclude
   config: untrusted, edit, local, global
   copy: after, force, include, exclude, dry-run
   debugancestor: 
   debugapplystreamclonebundle: 
   debugbuilddag: mergeable-file, overwritten-file, new-file
-  debugbundle: all
+  debugbundle: all, spec
   debugcheckstate: 
   debugcommands: 
   debugcomplete: options
   debugcreatestreamclonebundle: 
   debugdag: tags, branches, dots, spaces
   debugdata: changelog, manifest, dir
   debugdate: extended
   debugdeltachain: changelog, manifest, dir, template