Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/cmdutil.py @ 26639:92d67e5729b9
exchange: move bundle specification parsing from cmdutil
Clone bundles require a well-defined string to specify the type of
bundle that is listed so clients can filter compatible file types. The
`hg bundle` command and cmdutil.parsebundletype() already establish the
beginnings of a bundle specification format.
As part of formalizing this format specification so it can be used by
clone bundles, we move the specification parsing bits verbatim to
exchange.py, which is a more suitable place than cmdutil.py. A
subsequent patch will refactor this code to make it more appropriate as
a general API.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 13 Oct 2015 11:43:21 -0700 |
parents | 59b5e8844eb0 |
children | bec1a579ebc4 |
comparison
equal
deleted
inserted
replaced
26638:7afaf2566e25 | 26639:92d67e5729b9 |
---|---|
3364 msg = (_("can't release already inactivated backup:" | 3364 msg = (_("can't release already inactivated backup:" |
3365 " dirstate%s") | 3365 " dirstate%s") |
3366 % self._suffix) | 3366 % self._suffix) |
3367 raise error.Abort(msg) | 3367 raise error.Abort(msg) |
3368 self._abort() | 3368 self._abort() |
3369 | |
3370 _bundlecompspecs = {'none': None, | |
3371 'bzip2': 'BZ', | |
3372 'gzip': 'GZ', | |
3373 } | |
3374 | |
3375 _bundleversionspecs = {'v1': '01', | |
3376 'v2': '02', | |
3377 'bundle2': '02', #legacy | |
3378 } | |
3379 | |
3380 def parsebundletype(repo, spec): | |
3381 """return the internal bundle type to use from a user input | |
3382 | |
3383 This is parsing user specified bundle type as accepted in: | |
3384 | |
3385 'hg bundle --type TYPE'. | |
3386 | |
3387 It accept format in the form [compression][-version]|[version] | |
3388 | |
3389 Consensus about extensions of the format for various bundle2 feature | |
3390 is to prefix any feature with "+". eg "+treemanifest" or "gzip+phases" | |
3391 """ | |
3392 comp, version = None, None | |
3393 | |
3394 if '-' in spec: | |
3395 comp, version = spec.split('-', 1) | |
3396 elif spec in _bundlecompspecs: | |
3397 comp = spec | |
3398 elif spec in _bundleversionspecs: | |
3399 version = spec | |
3400 else: | |
3401 raise error.Abort(_('unknown bundle type specified with --type')) | |
3402 | |
3403 if comp is None: | |
3404 comp = 'BZ' | |
3405 else: | |
3406 try: | |
3407 comp = _bundlecompspecs[comp] | |
3408 except KeyError: | |
3409 raise error.Abort(_('unknown bundle type specified with --type')) | |
3410 | |
3411 if version is None: | |
3412 version = '01' | |
3413 if 'generaldelta' in repo.requirements: | |
3414 version = '02' | |
3415 else: | |
3416 try: | |
3417 version = _bundleversionspecs[version] | |
3418 except KeyError: | |
3419 raise error.Abort(_('unknown bundle type specified with --type')) | |
3420 | |
3421 return version, comp |