changeset 16427:d54d4de56aa7

commands: move bundle type validation earlier Checking the bundle type late in the command's execution can mean that we do work for a long time before complaining about incorrect user input and aborting. Guess how I discovered this.
author Bryan O'Sullivan <bryano@fb.com>
date Fri, 13 Apr 2012 11:01:07 -0700
parents b50fee9a2dad
children 9b26d541e972
files mercurial/commands.py tests/test-bundle-type.t
diffstat 2 files changed, 6 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Fri Apr 13 22:55:46 2012 -0500
+++ b/mercurial/commands.py	Fri Apr 13 11:01:07 2012 -0700
@@ -972,6 +972,12 @@
     if 'rev' in opts:
         revs = scmutil.revrange(repo, opts['rev'])
 
+    bundletype = opts.get('type', 'bzip2').lower()
+    btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'}
+    bundletype = btypes.get(bundletype)
+    if bundletype not in changegroup.bundletypes:
+        raise util.Abort(_('unknown bundle type specified with --type'))
+
     if opts.get('all'):
         base = ['null']
     else:
@@ -998,12 +1004,6 @@
         scmutil.nochangesfound(ui, outgoing and outgoing.excluded)
         return 1
 
-    bundletype = opts.get('type', 'bzip2').lower()
-    btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'}
-    bundletype = btypes.get(bundletype)
-    if bundletype not in changegroup.bundletypes:
-        raise util.Abort(_('unknown bundle type specified with --type'))
-
     changegroup.writebundle(cg, fname, bundletype)
 
 @command('cat',
--- a/tests/test-bundle-type.t	Fri Apr 13 22:55:46 2012 -0500
+++ b/tests/test-bundle-type.t	Fri Apr 13 11:01:07 2012 -0700
@@ -95,7 +95,6 @@
 
   $ cd t1
   $ hg bundle -a -t garbage ../bgarbage
-  1 changesets found
   abort: unknown bundle type specified with --type
   [255]
   $ cd ..