Mercurial > public > mercurial-scm > hg-stable
diff mercurial/cmdutil.py @ 26531:15ce78517d4b
bundle: extend the format of --type to support version and compression
We had some basic undocumented support for uncompressed bundle2 support. We now
have an official extensible syntax to specify both format type and compression
(eg: bzip2-v2).
In practice, this changeset introduce the 'v1' and 'v2' identifier to make it
possible to combine format and compression. The default format is still 'v1'.
We'll care about picking 'v1' or 'v2' in regard with general delta in the next
changesets.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Thu, 01 Oct 2015 19:16:00 -0700 |
parents | 77c13f3c01ca |
children | 1d1d0914cb76 |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Wed Oct 07 20:19:20 2015 +0100 +++ b/mercurial/cmdutil.py Thu Oct 01 19:16:00 2015 -0700 @@ -10,7 +10,7 @@ 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, changegroup +import repair, graphmod, revset, phases, obsolete, pathutil import changelog import bookmarks import encoding @@ -3331,19 +3331,50 @@ raise util.Abort(msg) self._abort() -def parsebundletype(bundletype): +_bundlecompspecs = {'none': None, + 'bzip2': 'BZ', + 'gzip': 'GZ', + } + +_bundleversionspecs = {'v1': '01', + 'v2': '02', + 'bundle2': '02', #legacy + } + +def parsebundletype(repo, spec): """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'. + + It accept format in the form [compression][-version]|[version] """ - btypes = {'none': 'HG10UN', - 'bzip2': 'HG10BZ', - 'gzip': 'HG10GZ', - 'bundle2': 'HG20'} - bundletype = btypes.get(bundletype) - if bundletype not in changegroup.bundletypes: + comp, version = None, None + + if '-' in spec: + comp, version = spec.split('-', 1) + elif spec in _bundlecompspecs: + comp = spec + elif spec in _bundleversionspecs: + version = spec + else: raise util.Abort(_('unknown bundle type specified with --type')) - return bundletype - + + if comp is None: + comp = 'BZ' + else: + try: + comp = _bundlecompspecs[comp] + except KeyError: + raise util.Abort(_('unknown bundle type specified with --type')) + + if version is None: + version = '01' + else: + try: + version = _bundleversionspecs[version] + except KeyError: + raise util.Abort(_('unknown bundle type specified with --type')) + + return version, comp