Patchwork [3,of,4] bundle: extract the parsing of the bundle type in a function

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 2, 2015, 3:32 a.m.
Message ID <0eaf6a1eb27092cde9a1.1443756749@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/10733/
State Accepted
Headers show

Comments

Pierre-Yves David - Oct. 2, 2015, 3:32 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1443747684 25200
#      Thu Oct 01 18:01:24 2015 -0700
# Node ID 0eaf6a1eb27092cde9a168ba915b8e1b739123fa
# Parent  5ae2e2fc8c3e833358725fc1305829d9c1570c25
bundle: extract the parsing of the bundle type in a function

We are going to introduce significant extensions of the bundle parsing code to
support creation of bundle2 through the bundle command. As a prior step, we
extract the logic in its own function.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -8,11 +8,11 @@ 
 from node import hex, bin, nullid, nullrev, short
 from i18n import _
 import os, sys, errno, re, tempfile, cStringIO, shutil
 import util, scmutil, templater, patch, error, templatekw, revlog, copies
 import match as matchmod
-import repair, graphmod, revset, phases, obsolete, pathutil
+import repair, graphmod, revset, phases, obsolete, pathutil, changegroup
 import changelog
 import bookmarks
 import encoding
 import formatter
 import crecord as crecordmod
@@ -3360,5 +3360,22 @@  class dirstateguard(object):
             if not self._active: # already inactivated
                 msg = (_("can't release already inactivated backup: %s")
                        % self._filename)
                 raise util.Abort(msg)
             self._abort()
+
+def parsebundletype(bundletype):
+    """return the internal bundle type to use from a user input
+
+    This is parsing user specify bundle type as accepted in:
+
+        'hg bundle --type TYPE'.
+    """
+    btypes = {'none': 'HG10UN',
+              'bzip2': 'HG10BZ',
+              'gzip': 'HG10GZ',
+              'bundle2': 'HG20'}
+    bundletype = btypes.get(bundletype)
+    if bundletype not in changegroup.bundletypes:
+        raise util.Abort(_('unknown bundle type specified with --type'))
+    return bundletype
+
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1233,17 +1233,11 @@  def bundle(ui, repo, fname, dest=None, *
     revs = None
     if 'rev' in opts:
         revs = scmutil.revrange(repo, opts['rev'])
 
     bundletype = opts.get('type', 'bzip2').lower()
-    btypes = {'none': 'HG10UN',
-              'bzip2': 'HG10BZ',
-              'gzip': 'HG10GZ',
-              'bundle2': 'HG20'}
-    bundletype = btypes.get(bundletype)
-    if bundletype not in changegroup.bundletypes:
-        raise util.Abort(_('unknown bundle type specified with --type'))
+    bundletype = cmdutil.parsebundletype(bundletype)
 
     if opts.get('all'):
         base = ['null']
     else:
         base = scmutil.revrange(repo, opts.get('base'))