bundle2: enforce all parameters in a part to be handled
Once we picked a handler, we check that all mandatory parameter keys are
properly supported. If not we raise an exception.
We added a test for this case.
The code now fails for any part with unknown mandatory parameters. We will
ignore such errors for advisory parts in a later changeset.
--- a/mercurial/bundle2.py Wed May 28 11:40:07 2014 -0700
+++ b/mercurial/bundle2.py Tue May 27 12:01:00 2014 -0700
@@ -306,6 +306,12 @@
part.read()
continue
+ unknownparams = part.mandatorykeys - handler.params
+ if unknownparams:
+ unknownparams = list(unknownparams)
+ unknownparams.sort()
+ raise error.BundleValueError(parttype=key, params=unknownparams)
+
# handler is called outside the above try block so that we don't
# risk catching KeyErrors from anything other than the
# parthandlermapping lookup (any KeyError raised by handler()
--- a/tests/test-bundle2.t Wed May 28 11:40:07 2014 -0700
+++ b/tests/test-bundle2.t Tue May 27 12:01:00 2014 -0700
@@ -64,6 +64,7 @@
> @command('bundle2',
> [('', 'param', [], 'stream level parameter'),
> ('', 'unknown', False, 'include an unknown mandatory part in the bundle'),
+ > ('', 'unknownparams', False, 'include an unknown part parameters in the bundle'),
> ('', 'parts', False, 'include some arbitrary parts to the bundle'),
> ('', 'reply', False, 'produce a reply bundle'),
> ('', 'pushrace', False, 'includes a check:head part with unknown nodes'),
@@ -113,6 +114,8 @@
> mathpart.data = '42'
> if opts['unknown']:
> bundler.newpart('test:UNKNOWN', data='some random content')
+ > if opts['unknownparams']:
+ > bundler.newpart('test:SONG', [('randomparams', '')])
> if opts['parts']:
> bundler.newpart('test:ping')
>
@@ -540,6 +543,16 @@
abort: missing support for test:unknown
[255]
+Unbundle with an unknown mandatory part parameters
+(should abort)
+
+ $ hg bundle2 --unknownparams ../unknown.hg2
+
+ $ hg unbundle2 < ../unknown.hg2
+ 0 unread bytes
+ abort: missing support for test:song - randomparams
+ [255]
+
unbundle with a reply
$ hg bundle2 --parts --reply ../parts-reply.hg2