Mercurial > hg
annotate mercurial/bundlecaches.py @ 51719:7558cee89655
dirstate: stringify a few exception messages
Built in exceptions want str, and ProgrammingError converts bytes to str
internally (because it subclasses RuntimeError).
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 18 Jul 2024 22:46:36 -0400 |
parents | 138ab7c6a6ff |
children | 278af66e6595 |
rev | line source |
---|---|
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 # bundlecaches.py - utility to deal with pre-computed bundle for servers |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
2 # |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
3 # This software may be used and distributed according to the terms of the |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
4 # GNU General Public License version 2 or any later version. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
5 |
49325
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
6 import collections |
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
7 |
49648
9be765b82a90
typing: minor tweaks to allow updating to pytype 2022.11.18
Matt Harbison <matt_harbison@yahoo.com>
parents:
49332
diff
changeset
|
8 from typing import ( |
51574
9b51a4fb0f96
bundlespec: type the _bundlespeccontentopts dictionary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51573
diff
changeset
|
9 Dict, |
9b51a4fb0f96
bundlespec: type the _bundlespeccontentopts dictionary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51573
diff
changeset
|
10 Union, |
49648
9be765b82a90
typing: minor tweaks to allow updating to pytype 2022.11.18
Matt Harbison <matt_harbison@yahoo.com>
parents:
49332
diff
changeset
|
11 cast, |
9be765b82a90
typing: minor tweaks to allow updating to pytype 2022.11.18
Matt Harbison <matt_harbison@yahoo.com>
parents:
49332
diff
changeset
|
12 ) |
9be765b82a90
typing: minor tweaks to allow updating to pytype 2022.11.18
Matt Harbison <matt_harbison@yahoo.com>
parents:
49332
diff
changeset
|
13 |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
14 from .i18n import _ |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 from .thirdparty import attr |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
18 from . import ( |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 error, |
46627
f4c325bf80fc
requirements: also add a generaldelta constant
Raphaël Gomès <rgomes@octobus.net>
parents:
45785
diff
changeset
|
20 requirements as requirementsmod, |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
21 sslutil, |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
22 util, |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
23 ) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
24 from .utils import stringutil |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
25 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
26 urlreq = util.urlreq |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
27 |
50686
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
28 BUNDLE_CACHE_DIR = b'bundle-cache' |
45785
80f32ec8653a
clonebundle: move the manifest filename to a constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45784
diff
changeset
|
29 CB_MANIFEST_FILE = b'clonebundles.manifest' |
50686
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
30 CLONEBUNDLESCHEME = b"peer-bundle-cache://" |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
31 |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
32 |
51672
138ab7c6a6ff
typing: add some trivial type hints to `mercurial/bundlecaches.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51600
diff
changeset
|
33 def get_manifest(repo) -> bytes: |
50686
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
34 """get the bundle manifest to be served to a client from a server""" |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
35 raw_text = repo.vfs.tryread(CB_MANIFEST_FILE) |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
36 entries = [e.split(b' ', 1) for e in raw_text.splitlines()] |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
37 |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
38 new_lines = [] |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
39 for e in entries: |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
40 url = alter_bundle_url(repo, e[0]) |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
41 if len(e) == 1: |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
42 line = url + b'\n' |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
43 else: |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
44 line = b"%s %s\n" % (url, e[1]) |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
45 new_lines.append(line) |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
46 return b''.join(new_lines) |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
47 |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
48 |
51672
138ab7c6a6ff
typing: add some trivial type hints to `mercurial/bundlecaches.py`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51600
diff
changeset
|
49 def alter_bundle_url(repo, url: bytes) -> bytes: |
50686
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
50 """a function that exist to help extension and hosting to alter the url |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
51 |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
52 This will typically be used to inject authentication information in the url |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
53 of cached bundles.""" |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
54 return url |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
55 |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
56 |
50542
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
57 SUPPORTED_CLONEBUNDLE_SCHEMES = [ |
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
58 b"http://", |
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
59 b"https://", |
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
60 b"largefile://", |
50686
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
61 CLONEBUNDLESCHEME, |
50542
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
62 ] |
45785
80f32ec8653a
clonebundle: move the manifest filename to a constant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45784
diff
changeset
|
63 |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
64 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
65 @attr.s |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48601
diff
changeset
|
66 class bundlespec: |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
67 compression = attr.ib() |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
68 wirecompression = attr.ib() |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
69 version = attr.ib() |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
70 wireversion = attr.ib() |
49325
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
71 # parameters explicitly overwritten by the config or the specification |
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
72 _explicit_params = attr.ib() |
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
73 # default parameter for the version |
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
74 # |
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
75 # Keeping it separated is useful to check what was actually overwritten. |
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
76 _default_opts = attr.ib() |
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
77 |
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
78 @property |
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
79 def params(self): |
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
80 return collections.ChainMap(self._explicit_params, self._default_opts) |
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
81 |
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
82 @property |
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
83 def contentopts(self): |
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
84 # kept for Backward Compatibility concerns. |
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
85 return self.params |
bf66f7a1e3f8
bundlespec: merge the contentopts and params dictionnary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49322
diff
changeset
|
86 |
49326
3840d16595cf
bundlespec: add a `overwrite` parameter to set_param
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49325
diff
changeset
|
87 def set_param(self, key, value, overwrite=True): |
3840d16595cf
bundlespec: add a `overwrite` parameter to set_param
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49325
diff
changeset
|
88 """Set a bundle parameter value. |
3840d16595cf
bundlespec: add a `overwrite` parameter to set_param
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49325
diff
changeset
|
89 |
3840d16595cf
bundlespec: add a `overwrite` parameter to set_param
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49325
diff
changeset
|
90 Will only overwrite if overwrite is true""" |
3840d16595cf
bundlespec: add a `overwrite` parameter to set_param
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49325
diff
changeset
|
91 if overwrite or key not in self._explicit_params: |
3840d16595cf
bundlespec: add a `overwrite` parameter to set_param
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49325
diff
changeset
|
92 self._explicit_params[key] = value |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
93 |
50712
0913a49e020c
bundle-spec: add an official method to format a spec into a string
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50686
diff
changeset
|
94 def as_spec(self): |
0913a49e020c
bundle-spec: add an official method to format a spec into a string
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50686
diff
changeset
|
95 parts = [b"%s-%s" % (self.compression, self.version)] |
0913a49e020c
bundle-spec: add an official method to format a spec into a string
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50686
diff
changeset
|
96 for param in sorted(self._explicit_params.items()): |
0913a49e020c
bundle-spec: add an official method to format a spec into a string
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50686
diff
changeset
|
97 parts.append(b'%s=%s' % param) |
0913a49e020c
bundle-spec: add an official method to format a spec into a string
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50686
diff
changeset
|
98 return b';'.join(parts) |
0913a49e020c
bundle-spec: add an official method to format a spec into a string
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50686
diff
changeset
|
99 |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
100 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
101 # Maps bundle version human names to changegroup versions. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
102 _bundlespeccgversions = { |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
103 b'v1': b'01', |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
104 b'v2': b'02', |
50686
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
105 b'v3': b'03', |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
106 b'packed1': b's1', |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
107 b'bundle2': b'02', # legacy |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
108 } |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
109 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
110 # Maps bundle version with content opts to choose which part to bundle |
51574
9b51a4fb0f96
bundlespec: type the _bundlespeccontentopts dictionary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51573
diff
changeset
|
111 _bundlespeccontentopts: Dict[bytes, Dict[bytes, Union[bool, bytes]]] = { |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
112 b'v1': { |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
113 b'changegroup': True, |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
114 b'cg.version': b'01', |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
115 b'obsolescence': False, |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
116 b'phases': False, |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
117 b'tagsfnodescache': False, |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
118 b'revbranchcache': False, |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
119 }, |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
120 b'v2': { |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
121 b'changegroup': True, |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
122 b'cg.version': b'02', |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
123 b'obsolescence': False, |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
124 b'phases': False, |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
125 b'tagsfnodescache': True, |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
126 b'revbranchcache': True, |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
127 }, |
50686
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
128 b'v3': { |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
129 b'changegroup': True, |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
130 b'cg.version': b'03', |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
131 b'obsolescence': False, |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
132 b'phases': True, |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
133 b'tagsfnodescache': True, |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
134 b'revbranchcache': True, |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
135 }, |
49322
d587f09cad98
bundlespec: make the `stream` case less special
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49321
diff
changeset
|
136 b'streamv2': { |
d587f09cad98
bundlespec: make the `stream` case less special
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49321
diff
changeset
|
137 b'changegroup': False, |
d587f09cad98
bundlespec: make the `stream` case less special
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49321
diff
changeset
|
138 b'cg.version': b'02', |
d587f09cad98
bundlespec: make the `stream` case less special
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49321
diff
changeset
|
139 b'obsolescence': False, |
d587f09cad98
bundlespec: make the `stream` case less special
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49321
diff
changeset
|
140 b'phases': False, |
51573
4a9d0898bf16
bundlespec: fix the "streamv2" and "streamv3-exp" variant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51558
diff
changeset
|
141 b"stream": b"v2", |
49322
d587f09cad98
bundlespec: make the `stream` case less special
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49321
diff
changeset
|
142 b'tagsfnodescache': False, |
d587f09cad98
bundlespec: make the `stream` case less special
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49321
diff
changeset
|
143 b'revbranchcache': False, |
d587f09cad98
bundlespec: make the `stream` case less special
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49321
diff
changeset
|
144 }, |
50686
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
145 b'streamv3-exp': { |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
146 b'changegroup': False, |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
147 b'cg.version': b'03', |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
148 b'obsolescence': False, |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
149 b'phases': False, |
51573
4a9d0898bf16
bundlespec: fix the "streamv2" and "streamv3-exp" variant
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51558
diff
changeset
|
150 b"stream": b"v3-exp", |
50686
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
151 b'tagsfnodescache': False, |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
152 b'revbranchcache': False, |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
153 }, |
49321
c12c843f0db7
bundlespec: phase out the `_bundlespeccgversions` mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48946
diff
changeset
|
154 b'packed1': { |
c12c843f0db7
bundlespec: phase out the `_bundlespeccgversions` mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48946
diff
changeset
|
155 b'cg.version': b's1', |
c12c843f0db7
bundlespec: phase out the `_bundlespeccgversions` mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48946
diff
changeset
|
156 }, |
c12c843f0db7
bundlespec: phase out the `_bundlespeccgversions` mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48946
diff
changeset
|
157 b'bundle2': { # legacy |
c12c843f0db7
bundlespec: phase out the `_bundlespeccgversions` mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48946
diff
changeset
|
158 b'cg.version': b'02', |
c12c843f0db7
bundlespec: phase out the `_bundlespeccgversions` mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48946
diff
changeset
|
159 }, |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
160 } |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
161 _bundlespeccontentopts[b'bundle2'] = _bundlespeccontentopts[b'v2'] |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
162 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
163 # Compression engines allowed in version 1. THIS SHOULD NEVER CHANGE. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
164 _bundlespecv1compengines = {b'gzip', b'bzip2', b'none'} |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
165 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
166 |
49331
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
167 def param_bool(key, value): |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
168 """make a boolean out of a parameter value""" |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
169 b = stringutil.parsebool(value) |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
170 if b is None: |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
171 msg = _(b"parameter %s should be a boolean ('%s')") |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
172 msg %= (key, value) |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
173 raise error.InvalidBundleSpecification(msg) |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
174 return b |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
175 |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
176 |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
177 # mapping of known parameter name need their value processed |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
178 bundle_spec_param_processing = { |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
179 b"obsolescence": param_bool, |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
180 b"obsolescence-mandatory": param_bool, |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
181 b"phases": param_bool, |
51562
eac84af0c8cc
bundle-spec: properly parse boolean configuration as boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50712
diff
changeset
|
182 b"changegroup": param_bool, |
eac84af0c8cc
bundle-spec: properly parse boolean configuration as boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50712
diff
changeset
|
183 b"tagsfnodescache": param_bool, |
eac84af0c8cc
bundle-spec: properly parse boolean configuration as boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50712
diff
changeset
|
184 b"revbranchcache": param_bool, |
49331
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
185 } |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
186 |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
187 |
49330
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
188 def _parseparams(s): |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
189 """parse bundlespec parameter section |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
190 |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
191 input: "comp-version;params" string |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
192 |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
193 return: (spec; {param_key: param_value}) |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
194 """ |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
195 if b';' not in s: |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
196 return s, {} |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
197 |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
198 params = {} |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
199 version, paramstr = s.split(b';', 1) |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
200 |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
201 err = _(b'invalid bundle specification: missing "=" in parameter: %s') |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
202 for p in paramstr.split(b';'): |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
203 if b'=' not in p: |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
204 msg = err % p |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
205 raise error.InvalidBundleSpecification(msg) |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
206 |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
207 key, value = p.split(b'=', 1) |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
208 key = urlreq.unquote(key) |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
209 value = urlreq.unquote(value) |
49331
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
210 process = bundle_spec_param_processing.get(key) |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
211 if process is not None: |
1b04d5213d0f
bundlespec: add processing of some parameter value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49330
diff
changeset
|
212 value = process(key, value) |
49330
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
213 params[key] = value |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
214 |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
215 return version, params |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
216 |
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
217 |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
218 def parsebundlespec(repo, spec, strict=True): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
219 """Parse a bundle string specification into parts. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
220 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
221 Bundle specifications denote a well-defined bundle/exchange format. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
222 The content of a given specification should not change over time in |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
223 order to ensure that bundles produced by a newer version of Mercurial are |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
224 readable from an older version. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
225 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
226 The string currently has the form: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
227 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
228 <compression>-<type>[;<parameter0>[;<parameter1>]] |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
229 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
230 Where <compression> is one of the supported compression formats |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
231 and <type> is (currently) a version string. A ";" can follow the type and |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
232 all text afterwards is interpreted as URI encoded, ";" delimited key=value |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
233 pairs. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
234 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
235 If ``strict`` is True (the default) <compression> is required. Otherwise, |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
236 it is optional. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
237 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
238 Returns a bundlespec object of (compression, version, parameters). |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
239 Compression will be ``None`` if not in strict mode and a compression isn't |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
240 defined. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
241 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
242 An ``InvalidBundleSpecification`` is raised when the specification is |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
243 not syntactically well formed. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
244 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
245 An ``UnsupportedBundleSpecification`` is raised when the compression or |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
246 bundle type/version is not recognized. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
247 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
248 Note: this function will likely eventually return a more complex data |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
249 structure, including bundle2 part information. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
250 """ |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
251 if strict and b'-' not in spec: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
252 raise error.InvalidBundleSpecification( |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
253 _( |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
254 b'invalid bundle specification; ' |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
255 b'must be prefixed with compression: %s' |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
256 ) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
257 % spec |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
258 ) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
259 |
49332
d89bfc075289
bundlespec: do not check for `-` in the params portion of the bundlespec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49331
diff
changeset
|
260 pre_args = spec.split(b';', 1)[0] |
d89bfc075289
bundlespec: do not check for `-` in the params portion of the bundlespec
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49331
diff
changeset
|
261 if b'-' in pre_args: |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
262 compression, version = spec.split(b'-', 1) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
263 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
264 if compression not in util.compengines.supportedbundlenames: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
265 raise error.UnsupportedBundleSpecification( |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
266 _(b'%s compression is not supported') % compression |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
267 ) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
268 |
49330
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
269 version, params = _parseparams(version) |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
270 |
49321
c12c843f0db7
bundlespec: phase out the `_bundlespeccgversions` mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48946
diff
changeset
|
271 if version not in _bundlespeccontentopts: |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
272 raise error.UnsupportedBundleSpecification( |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
273 _(b'%s is not a recognized bundle version') % version |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
274 ) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
275 else: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
276 # Value could be just the compression or just the version, in which |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
277 # case some defaults are assumed (but only when not in strict mode). |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
278 assert not strict |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
279 |
49330
5d17dd74177d
bundlespec: extract the parseparams closure
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49326
diff
changeset
|
280 spec, params = _parseparams(spec) |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
281 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
282 if spec in util.compengines.supportedbundlenames: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
283 compression = spec |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
284 version = b'v1' |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
285 # Generaldelta repos require v2. |
46627
f4c325bf80fc
requirements: also add a generaldelta constant
Raphaël Gomès <rgomes@octobus.net>
parents:
45785
diff
changeset
|
286 if requirementsmod.GENERALDELTA_REQUIREMENT in repo.requirements: |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
287 version = b'v2' |
47342
dc3800569157
revlogv2: make sure bundling pick a compatible bundle format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46627
diff
changeset
|
288 elif requirementsmod.REVLOGV2_REQUIREMENT in repo.requirements: |
dc3800569157
revlogv2: make sure bundling pick a compatible bundle format
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46627
diff
changeset
|
289 version = b'v2' |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
290 # Modern compression engines require v2. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
291 if compression not in _bundlespecv1compengines: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
292 version = b'v2' |
49321
c12c843f0db7
bundlespec: phase out the `_bundlespeccgversions` mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48946
diff
changeset
|
293 elif spec in _bundlespeccontentopts: |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
294 if spec == b'packed1': |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
295 compression = b'none' |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
296 else: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
297 compression = b'bzip2' |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
298 version = spec |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
299 else: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
300 raise error.UnsupportedBundleSpecification( |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
301 _(b'%s is not a recognized bundle specification') % spec |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
302 ) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
303 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
304 # Bundle version 1 only supports a known set of compression engines. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
305 if version == b'v1' and compression not in _bundlespecv1compengines: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
306 raise error.UnsupportedBundleSpecification( |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
307 _(b'compression engine %s is not supported on v1 bundles') |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
308 % compression |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
309 ) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
310 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
311 # The specification for packed1 can optionally declare the data formats |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
312 # required to apply it. If we see this metadata, compare against what the |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
313 # repo supports and error if the bundle isn't compatible. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
314 if version == b'packed1' and b'requirements' in params: |
49648
9be765b82a90
typing: minor tweaks to allow updating to pytype 2022.11.18
Matt Harbison <matt_harbison@yahoo.com>
parents:
49332
diff
changeset
|
315 requirements = set(cast(bytes, params[b'requirements']).split(b',')) |
48601
baddab229b86
stream-clone: add a explicit set list requirements relevant to stream clone
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47342
diff
changeset
|
316 missingreqs = requirements - requirementsmod.STREAM_FIXED_REQUIREMENTS |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
317 if missingreqs: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
318 raise error.UnsupportedBundleSpecification( |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
319 _(b'missing support for repository features: %s') |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
320 % b', '.join(sorted(missingreqs)) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
321 ) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
322 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
323 # Compute contentopts based on the version |
50686
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
324 if b"stream" in params: |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
325 # This case is fishy as this mostly derails the version selection |
49322
d587f09cad98
bundlespec: make the `stream` case less special
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49321
diff
changeset
|
326 # mechanism. `stream` bundles are quite specific and used differently |
d587f09cad98
bundlespec: make the `stream` case less special
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49321
diff
changeset
|
327 # as "normal" bundles. |
d587f09cad98
bundlespec: make the `stream` case less special
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49321
diff
changeset
|
328 # |
d587f09cad98
bundlespec: make the `stream` case less special
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49321
diff
changeset
|
329 # (we should probably define a cleaner way to do this and raise a |
50686
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
330 # warning when the old way is encountered) |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
331 if params[b"stream"] == b"v2": |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
332 version = b"streamv2" |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
333 if params[b"stream"] == b"v3-exp": |
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
334 version = b"streamv3-exp" |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
335 contentopts = _bundlespeccontentopts.get(version, {}).copy() |
50686
a41eeb877d07
branching: merge with stable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50542
diff
changeset
|
336 if version == b"streamv2" or version == b"streamv3-exp": |
49322
d587f09cad98
bundlespec: make the `stream` case less special
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49321
diff
changeset
|
337 # streamv2 have been reported as "v2" for a while. |
d587f09cad98
bundlespec: make the `stream` case less special
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49321
diff
changeset
|
338 version = b"v2" |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
339 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
340 engine = util.compengines.forbundlename(compression) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
341 compression, wirecompression = engine.bundletype() |
49321
c12c843f0db7
bundlespec: phase out the `_bundlespeccgversions` mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48946
diff
changeset
|
342 wireversion = _bundlespeccontentopts[version][b'cg.version'] |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
343 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
344 return bundlespec( |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
345 compression, wirecompression, version, wireversion, params, contentopts |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
346 ) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
347 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
348 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
349 def parseclonebundlesmanifest(repo, s): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
350 """Parses the raw text of a clone bundles manifest. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
351 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
352 Returns a list of dicts. The dicts have a ``URL`` key corresponding |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
353 to the URL and other keys are the attributes for the entry. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
354 """ |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
355 m = [] |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
356 for line in s.splitlines(): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
357 fields = line.split() |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
358 if not fields: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
359 continue |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
360 attrs = {b'URL': fields[0]} |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
361 for rawattr in fields[1:]: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
362 key, value = rawattr.split(b'=', 1) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
363 key = util.urlreq.unquote(key) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
364 value = util.urlreq.unquote(value) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
365 attrs[key] = value |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
366 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
367 # Parse BUNDLESPEC into components. This makes client-side |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
368 # preferences easier to specify since you can prefer a single |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
369 # component of the BUNDLESPEC. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
370 if key == b'BUNDLESPEC': |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
371 try: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
372 bundlespec = parsebundlespec(repo, value) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
373 attrs[b'COMPRESSION'] = bundlespec.compression |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
374 attrs[b'VERSION'] = bundlespec.version |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
375 except error.InvalidBundleSpecification: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
376 pass |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
377 except error.UnsupportedBundleSpecification: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
378 pass |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
379 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
380 m.append(attrs) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
381 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
382 return m |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
383 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
384 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
385 def isstreamclonespec(bundlespec): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
386 # Stream clone v1 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
387 if bundlespec.wirecompression == b'UN' and bundlespec.wireversion == b's1': |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
388 return True |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
389 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
390 # Stream clone v2 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
391 if ( |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
392 bundlespec.wirecompression == b'UN' |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
393 and bundlespec.wireversion == b'02' |
51558
c4aab3661f25
bundlespec: rationalize the way we specify stream bundle version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50712
diff
changeset
|
394 and bundlespec.contentopts.get(b'stream', None) in (b"v2", b"v3-exp") |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
395 ): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
396 return True |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
397 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
398 return False |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
399 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
400 |
50542
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
401 def filterclonebundleentries( |
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
402 repo, entries, streamclonerequested=False, pullbundles=False |
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
403 ): |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
404 """Remove incompatible clone bundle manifest entries. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
405 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
406 Accepts a list of entries parsed with ``parseclonebundlesmanifest`` |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
407 and returns a new list consisting of only the entries that this client |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
408 should be able to apply. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
409 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
410 There is no guarantee we'll be able to apply all returned entries because |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
411 the metadata we use to filter on may be missing or wrong. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
412 """ |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
413 newentries = [] |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
414 for entry in entries: |
50542
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
415 url = entry.get(b'URL') |
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
416 if not pullbundles and not any( |
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
417 [url.startswith(scheme) for scheme in SUPPORTED_CLONEBUNDLE_SCHEMES] |
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
418 ): |
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
419 repo.ui.debug( |
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
420 b'filtering %s because not a supported clonebundle scheme\n' |
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
421 % url |
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
422 ) |
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
423 continue |
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
424 |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
425 spec = entry.get(b'BUNDLESPEC') |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
426 if spec: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
427 try: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
428 bundlespec = parsebundlespec(repo, spec, strict=True) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
429 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
430 # If a stream clone was requested, filter out non-streamclone |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
431 # entries. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
432 if streamclonerequested and not isstreamclonespec(bundlespec): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
433 repo.ui.debug( |
50542
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
434 b'filtering %s because not a stream clone\n' % url |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
435 ) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
436 continue |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
437 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
438 except error.InvalidBundleSpecification as e: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
439 repo.ui.debug(stringutil.forcebytestr(e) + b'\n') |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
440 continue |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
441 except error.UnsupportedBundleSpecification as e: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
442 repo.ui.debug( |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
443 b'filtering %s because unsupported bundle ' |
50542
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
444 b'spec: %s\n' % (url, stringutil.forcebytestr(e)) |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
445 ) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
446 continue |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
447 # If we don't have a spec and requested a stream clone, we don't know |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
448 # what the entry is so don't attempt to apply it. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
449 elif streamclonerequested: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
450 repo.ui.debug( |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
451 b'filtering %s because cannot determine if a stream ' |
50542
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
452 b'clone bundle\n' % url |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
453 ) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
454 continue |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
455 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
456 if b'REQUIRESNI' in entry and not sslutil.hassni: |
50542
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
457 repo.ui.debug(b'filtering %s because SNI not supported\n' % url) |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
458 continue |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
459 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
460 if b'REQUIREDRAM' in entry: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
461 try: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
462 requiredram = util.sizetoint(entry[b'REQUIREDRAM']) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
463 except error.ParseError: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
464 repo.ui.debug( |
50542
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
465 b'filtering %s due to a bad REQUIREDRAM attribute\n' % url |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
466 ) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
467 continue |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
468 actualram = repo.ui.estimatememory() |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
469 if actualram is not None and actualram * 0.66 < requiredram: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
470 repo.ui.debug( |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
471 b'filtering %s as it needs more than 2/3 of system memory\n' |
50542
7b723217d368
clonebundles: filter out invalid schemes instead of failing on them
Mathias De Mare <mathias.de_mare@nokia.com>
parents:
49648
diff
changeset
|
472 % url |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
473 ) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
474 continue |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
475 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
476 newentries.append(entry) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
477 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
478 return newentries |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
479 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
480 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48601
diff
changeset
|
481 class clonebundleentry: |
45784
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
482 """Represents an item in a clone bundles manifest. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
483 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
484 This rich class is needed to support sorting since sorted() in Python 3 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
485 doesn't support ``cmp`` and our comparison is complex enough that ``key=`` |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
486 won't work. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
487 """ |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
488 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
489 def __init__(self, value, prefers): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
490 self.value = value |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
491 self.prefers = prefers |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
492 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
493 def _cmp(self, other): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
494 for prefkey, prefvalue in self.prefers: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
495 avalue = self.value.get(prefkey) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
496 bvalue = other.value.get(prefkey) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
497 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
498 # Special case for b missing attribute and a matches exactly. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
499 if avalue is not None and bvalue is None and avalue == prefvalue: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
500 return -1 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
501 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
502 # Special case for a missing attribute and b matches exactly. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
503 if bvalue is not None and avalue is None and bvalue == prefvalue: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
504 return 1 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
505 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
506 # We can't compare unless attribute present on both. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
507 if avalue is None or bvalue is None: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
508 continue |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
509 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
510 # Same values should fall back to next attribute. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
511 if avalue == bvalue: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
512 continue |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
513 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
514 # Exact matches come first. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
515 if avalue == prefvalue: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
516 return -1 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
517 if bvalue == prefvalue: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
518 return 1 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
519 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
520 # Fall back to next attribute. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
521 continue |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
522 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
523 # If we got here we couldn't sort by attributes and prefers. Fall |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
524 # back to index order. |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
525 return 0 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
526 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
527 def __lt__(self, other): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
528 return self._cmp(other) < 0 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
529 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
530 def __gt__(self, other): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
531 return self._cmp(other) > 0 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
532 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
533 def __eq__(self, other): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
534 return self._cmp(other) == 0 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
535 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
536 def __le__(self, other): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
537 return self._cmp(other) <= 0 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
538 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
539 def __ge__(self, other): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
540 return self._cmp(other) >= 0 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
541 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
542 def __ne__(self, other): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
543 return self._cmp(other) != 0 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
544 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
545 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
546 def sortclonebundleentries(ui, entries): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
547 prefers = ui.configlist(b'ui', b'clonebundleprefers') |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
548 if not prefers: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
549 return list(entries) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
550 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
551 def _split(p): |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
552 if b'=' not in p: |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
553 hint = _(b"each comma separated item should be key=value pairs") |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
554 raise error.Abort( |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
555 _(b"invalid ui.clonebundleprefers item: %s") % p, hint=hint |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
556 ) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
557 return p.split(b'=', 1) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
558 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
559 prefers = [_split(p) for p in prefers] |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
560 |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
561 items = sorted(clonebundleentry(v, prefers) for v in entries) |
74271829ddc0
clonebundles: move a bundle of clone bundle related code to a new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
562 return [i.value for i in items] |