Patchwork D2971: bundlespec: introduce an attr-based class for bundlespec

login
register
mail settings
Submitter phabricator
Date March 30, 2018, 5:12 p.m.
Message ID <701ac9c27ec047175bc9a6fc81401428@localhost.localdomain>
Download mbox | patch
Permalink /patch/29962/
State Not Applicable
Headers show

Comments

phabricator - March 30, 2018, 5:12 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGb229fd9adeae: bundlespec: introduce an attr-based class for bundlespec (authored by lothiraldan, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2971?vs=7373&id=7382

REVISION DETAIL
  https://phab.mercurial-scm.org/D2971

AFFECTED FILES
  mercurial/commands.py
  mercurial/exchange.py

CHANGE DETAILS




To: lothiraldan, #hg-reviewers, indygreg
Cc: mercurial-devel

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -17,6 +17,9 @@ 
     hex,
     nullid,
 )
+from .thirdparty import (
+    attr,
+)
 from . import (
     bookmarks as bookmod,
     bundle2,
@@ -52,6 +55,12 @@ 
 # Compression engines allowed in version 1. THIS SHOULD NEVER CHANGE.
 _bundlespecv1compengines = {'gzip', 'bzip2', 'none'}
 
+@attr.s
+class bundlespec(object):
+    compression = attr.ib()
+    version = attr.ib()
+    params = attr.ib()
+
 def parsebundlespec(repo, spec, strict=True, externalnames=False):
     """Parse a bundle string specification into parts.
 
@@ -75,8 +84,9 @@ 
     If ``externalnames`` is False (the default), the human-centric names will
     be converted to their internal representation.
 
-    Returns a 3-tuple of (compression, version, parameters). Compression will
-    be ``None`` if not in strict mode and a compression isn't defined.
+    Returns a bundlespec object of (compression, version, parameters).
+    Compression will be ``None`` if not in strict mode and a compression isn't
+    defined.
 
     An ``InvalidBundleSpecification`` is raised when the specification is
     not syntactically well formed.
@@ -172,7 +182,8 @@ 
         engine = util.compengines.forbundlename(compression)
         compression = engine.bundletype()[1]
         version = _bundlespeccgversions[version]
-    return compression, version, params
+
+    return bundlespec(compression, version, params)
 
 def readbundle(ui, fh, fname, vfs=None):
     header = changegroup.readexactly(fh, 4)
@@ -2140,10 +2151,10 @@ 
             # component of the BUNDLESPEC.
             if key == 'BUNDLESPEC':
                 try:
-                    comp, version, params = parsebundlespec(repo, value,
-                                                            externalnames=True)
-                    attrs['COMPRESSION'] = comp
-                    attrs['VERSION'] = version
+                    bundlespec = parsebundlespec(repo, value,
+                                                 externalnames=True)
+                    attrs['COMPRESSION'] = bundlespec.compression
+                    attrs['VERSION'] = bundlespec.version
                 except error.InvalidBundleSpecification:
                     pass
                 except error.UnsupportedBundleSpecification:
@@ -2168,10 +2179,12 @@ 
         spec = entry.get('BUNDLESPEC')
         if spec:
             try:
-                comp, version, params = parsebundlespec(repo, spec, strict=True)
+                bundlespec = parsebundlespec(repo, spec, strict=True)
 
                 # If a stream clone was requested, filter out non-streamclone
                 # entries.
+                comp = bundlespec.compression
+                version = bundlespec.version
                 if streamclonerequested and (comp != 'UN' or version != 's1'):
                     repo.ui.debug('filtering %s because not a stream clone\n' %
                                   entry['URL'])
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1199,12 +1199,12 @@ 
 
     bundletype = opts.get('type', 'bzip2').lower()
     try:
-        bcompression, cgversion, params = exchange.parsebundlespec(
-                repo, bundletype, strict=False)
+        bundlespec = exchange.parsebundlespec(repo, bundletype, strict=False)
     except error.UnsupportedBundleSpecification as e:
         raise error.Abort(pycompat.bytestr(e),
                           hint=_("see 'hg help bundlespec' for supported "
                                  "values for --type"))
+    cgversion = bundlespec.version
 
     # Packed bundles are a pseudo bundle format for now.
     if cgversion == 's1':
@@ -1246,6 +1246,7 @@ 
         scmutil.nochangesfound(ui, repo, not base and outgoing.excluded)
         return 1
 
+    bcompression = bundlespec.compression
     if cgversion == '01': #bundle1
         if bcompression is None:
             bcompression = 'UN'