[PATCH 1 of 5 clonebundles V3] exchange: move bundle specification parsing from cmdutil

Pierre-Yves David pierre-yves.david at ens-lyon.org
Tue Oct 13 23:22:38 CDT 2015



On 10/13/2015 11:54 AM, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1444761801 25200
> #      Tue Oct 13 11:43:21 2015 -0700
> # Node ID e81dbde0649bed83a2260790e1248d38aece6b9d
> # Parent  42f28b5a45bcec4e4b705e1d91288a3eb4c7f68e
> exchange: move bundle specification parsing from cmdutil

That one is pushed to the clowncopter, thanks.

(I've added a blank line after the funtion definition)

>
> 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.
>
> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -3369,57 +3369,4 @@ class dirstateguard(object):
>                   msg = (_("can't release already inactivated backup: %s")
>                          % self._filename)
>                   raise error.Abort(msg)
>               self._abort()
> -
> -_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]
> -
> -    Consensus about extensions of the format for various bundle2 feature
> -    is to prefix any feature with "+". eg "+treemanifest" or "gzip+phases"
> -    """
> -    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 error.Abort(_('unknown bundle type specified with --type'))
> -
> -    if comp is None:
> -        comp = 'BZ'
> -    else:
> -        try:
> -            comp = _bundlecompspecs[comp]
> -        except KeyError:
> -            raise error.Abort(_('unknown bundle type specified with --type'))
> -
> -    if version is None:
> -        version = '01'
> -        if 'generaldelta' in repo.requirements:
> -            version = '02'
> -    else:
> -        try:
> -            version = _bundleversionspecs[version]
> -        except KeyError:
> -            raise error.Abort(_('unknown bundle type specified with --type'))
> -
> -    return version, comp
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -1241,9 +1241,9 @@ def bundle(ui, repo, fname, dest=None, *
>       if 'rev' in opts:
>           revs = scmutil.revrange(repo, opts['rev'])
>
>       bundletype = opts.get('type', 'bzip2').lower()
> -    cgversion, bcompression = cmdutil.parsebundletype(repo, bundletype)
> +    cgversion, bcompression = exchange.parsebundlespec(repo, bundletype)
>
>       if opts.get('all'):
>           base = ['null']
>       else:
> diff --git a/mercurial/exchange.py b/mercurial/exchange.py
> --- a/mercurial/exchange.py
> +++ b/mercurial/exchange.py
> @@ -14,8 +14,60 @@ import lock as lockmod
>   import streamclone
>   import tags
>   import url as urlmod
>
> +_bundlecompspecs = {'none': None,
> +                    'bzip2': 'BZ',
> +                    'gzip': 'GZ',
> +                   }
> +
> +_bundleversionspecs = {'v1': '01',
> +                       'v2': '02',
> +                       'bundle2': '02', #legacy
> +                      }
> +
> +def parsebundlespec(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]
> +
> +    Consensus about extensions of the format for various bundle2 feature
> +    is to prefix any feature with "+". eg "+treemanifest" or "gzip+phases"
> +    """
> +    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 error.Abort(_('unknown bundle type specified with --type'))
> +
> +    if comp is None:
> +        comp = 'BZ'
> +    else:
> +        try:
> +            comp = _bundlecompspecs[comp]
> +        except KeyError:
> +            raise error.Abort(_('unknown bundle type specified with --type'))
> +
> +    if version is None:
> +        version = '01'
> +        if 'generaldelta' in repo.requirements:
> +            version = '02'
> +    else:
> +        try:
> +            version = _bundleversionspecs[version]
> +        except KeyError:
> +            raise error.Abort(_('unknown bundle type specified with --type'))
> +
> +    return version, comp
>   def readbundle(ui, fh, fname, vfs=None):
>       header = changegroup.readexactly(fh, 4)
>
>       alg = None
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
>

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list