# HG changeset patch # User Pierre-Yves David # Date 2015-10-02 01:01:24 # Node ID 77c13f3c01cac263958988b1797a2527ebec9b1c # Parent 83d82fbefccb8d60afe84570f00a5cd409a0d9b2 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 an early step, we extract the logic in its own function. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -10,7 +10,7 @@ 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 @@ -3330,3 +3330,20 @@ class dirstateguard(object): % 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 specified 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 @@ -1238,13 +1238,7 @@ def bundle(ui, repo, fname, dest=None, * 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']