[PATCH] commands: move bundle type validation earlier

Bryan O'Sullivan bos at serpentine.com
Fri Apr 13 12:59:35 CDT 2012


# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1334339969 25200
# Node ID f30bfc4b97040f30620cdbc78ab61c6731243aa1
# Parent  0b29e73127720e495aaa207e84aaec5c6307c848
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.

diff -r 0b29e7312772 -r f30bfc4b9704 mercurial/commands.py
--- a/mercurial/commands.py	Fri Apr 13 09:26:26 2012 -0700
+++ b/mercurial/commands.py	Fri Apr 13 10:59:29 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',


More information about the Mercurial-devel mailing list