changeset 49335:5d17dd74177d

bundlespec: extract the parseparams closure It has no value being a closure. We extract it before modifying it further.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 18 May 2022 10:06:43 +0100
parents 2f60e2242f03
children 1b04d5213d0f
files mercurial/bundlecaches.py
diffstat 1 files changed, 29 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundlecaches.py	Wed May 25 10:30:11 2022 +0200
+++ b/mercurial/bundlecaches.py	Wed May 18 10:06:43 2022 +0100
@@ -102,6 +102,33 @@
 _bundlespecv1compengines = {b'gzip', b'bzip2', b'none'}
 
 
+def _parseparams(s):
+    """parse bundlespec parameter section
+
+    input: "comp-version;params" string
+
+    return: (spec; {param_key: param_value})
+    """
+    if b';' not in s:
+        return s, {}
+
+    params = {}
+    version, paramstr = s.split(b';', 1)
+
+    err = _(b'invalid bundle specification: missing "=" in parameter: %s')
+    for p in paramstr.split(b';'):
+        if b'=' not in p:
+            msg = err % p
+            raise error.InvalidBundleSpecification(msg)
+
+        key, value = p.split(b'=', 1)
+        key = urlreq.unquote(key)
+        value = urlreq.unquote(value)
+        params[key] = value
+
+    return version, params
+
+
 def parsebundlespec(repo, spec, strict=True):
     """Parse a bundle string specification into parts.
 
@@ -135,31 +162,6 @@
     Note: this function will likely eventually return a more complex data
     structure, including bundle2 part information.
     """
-
-    def parseparams(s):
-        if b';' not in s:
-            return s, {}
-
-        params = {}
-        version, paramstr = s.split(b';', 1)
-
-        for p in paramstr.split(b';'):
-            if b'=' not in p:
-                raise error.InvalidBundleSpecification(
-                    _(
-                        b'invalid bundle specification: '
-                        b'missing "=" in parameter: %s'
-                    )
-                    % p
-                )
-
-            key, value = p.split(b'=', 1)
-            key = urlreq.unquote(key)
-            value = urlreq.unquote(value)
-            params[key] = value
-
-        return version, params
-
     if strict and b'-' not in spec:
         raise error.InvalidBundleSpecification(
             _(
@@ -177,7 +179,7 @@
                 _(b'%s compression is not supported') % compression
             )
 
-        version, params = parseparams(version)
+        version, params = _parseparams(version)
 
         if version not in _bundlespeccontentopts:
             raise error.UnsupportedBundleSpecification(
@@ -188,7 +190,7 @@
         # case some defaults are assumed (but only when not in strict mode).
         assert not strict
 
-        spec, params = parseparams(spec)
+        spec, params = _parseparams(spec)
 
         if spec in util.compengines.supportedbundlenames:
             compression = spec