Mercurial > public > mercurial-scm > hg
comparison mercurial/exchange.py @ 49334:6d15a8971e30
bundlespec: fix the generation of bundlespec for `cg.version`
If the value is non-default, we display it.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 18 May 2022 12:07:50 +0100 |
parents | 642e31cb55f0 |
children | 04cdb442a892 |
comparison
equal
deleted
inserted
replaced
49333:1fd7520e4961 | 49334:6d15a8971e30 |
---|---|
78 raise error.Abort( | 78 raise error.Abort( |
79 _(b'%s: unknown bundle version %s') % (fname, version) | 79 _(b'%s: unknown bundle version %s') % (fname, version) |
80 ) | 80 ) |
81 | 81 |
82 | 82 |
83 def _format_params(params): | |
84 parts = [] | |
85 for key, value in sorted(params.items()): | |
86 value = urlreq.quote(value) | |
87 parts.append(b"%s=%s" % (key, value)) | |
88 return b';'.join(parts) | |
89 | |
90 | |
83 def getbundlespec(ui, fh): | 91 def getbundlespec(ui, fh): |
84 """Infer the bundlespec from a bundle file handle. | 92 """Infer the bundlespec from a bundle file handle. |
85 | 93 |
86 The input file handle is seeked and the original seek position is not | 94 The input file handle is seeked and the original seek position is not |
87 restored. | 95 restored. |
90 def speccompression(alg): | 98 def speccompression(alg): |
91 try: | 99 try: |
92 return util.compengines.forbundletype(alg).bundletype()[0] | 100 return util.compengines.forbundletype(alg).bundletype()[0] |
93 except KeyError: | 101 except KeyError: |
94 return None | 102 return None |
103 | |
104 params = {} | |
95 | 105 |
96 b = readbundle(ui, fh, None) | 106 b = readbundle(ui, fh, None) |
97 if isinstance(b, changegroup.cg1unpacker): | 107 if isinstance(b, changegroup.cg1unpacker): |
98 alg = b._type | 108 alg = b._type |
99 if alg == b'_truncatedBZ': | 109 if alg == b'_truncatedBZ': |
113 comp = b'none' | 123 comp = b'none' |
114 | 124 |
115 version = None | 125 version = None |
116 for part in b.iterparts(): | 126 for part in b.iterparts(): |
117 if part.type == b'changegroup': | 127 if part.type == b'changegroup': |
118 version = part.params[b'version'] | 128 cgversion = part.params[b'version'] |
119 if version in (b'01', b'02'): | 129 if cgversion in (b'01', b'02'): |
120 version = b'v2' | 130 version = b'v2' |
131 elif cgversion in (b'03',): | |
132 version = b'v2' | |
133 params[b'cg.version'] = cgversion | |
121 else: | 134 else: |
122 raise error.Abort( | 135 raise error.Abort( |
123 _( | 136 _( |
124 b'changegroup version %s does not have ' | 137 b'changegroup version %s does not have ' |
125 b'a known bundlespec' | 138 b'a known bundlespec' |
136 | 149 |
137 if not version: | 150 if not version: |
138 raise error.Abort( | 151 raise error.Abort( |
139 _(b'could not identify changegroup version in bundle') | 152 _(b'could not identify changegroup version in bundle') |
140 ) | 153 ) |
141 | 154 spec = b'%s-%s' % (comp, version) |
142 return b'%s-%s' % (comp, version) | 155 if params: |
156 spec += b';' | |
157 spec += _format_params(params) | |
158 return spec | |
159 | |
143 elif isinstance(b, streamclone.streamcloneapplier): | 160 elif isinstance(b, streamclone.streamcloneapplier): |
144 requirements = streamclone.readbundle1header(fh)[2] | 161 requirements = streamclone.readbundle1header(fh)[2] |
145 formatted = bundle2._formatrequirementsparams(requirements) | 162 formatted = bundle2._formatrequirementsparams(requirements) |
146 return b'none-packed1;%s' % formatted | 163 return b'none-packed1;%s' % formatted |
147 else: | 164 else: |