Mercurial > public > mercurial-scm > hg
comparison mercurial/bundlerepo.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 5ba8c328a895 |
children | 687b865b95ad |
comparison
equal
deleted
inserted
replaced
43075:57875cf423c9 | 43076:2372284d9457 |
---|---|
15 | 15 |
16 import os | 16 import os |
17 import shutil | 17 import shutil |
18 | 18 |
19 from .i18n import _ | 19 from .i18n import _ |
20 from .node import ( | 20 from .node import nullid, nullrev |
21 nullid, | |
22 nullrev | |
23 ) | |
24 | 21 |
25 from . import ( | 22 from . import ( |
26 bundle2, | 23 bundle2, |
27 changegroup, | 24 changegroup, |
28 changelog, | 25 changelog, |
42 revlog, | 39 revlog, |
43 util, | 40 util, |
44 vfs as vfsmod, | 41 vfs as vfsmod, |
45 ) | 42 ) |
46 | 43 |
44 | |
47 class bundlerevlog(revlog.revlog): | 45 class bundlerevlog(revlog.revlog): |
48 def __init__(self, opener, indexfile, cgunpacker, linkmapper): | 46 def __init__(self, opener, indexfile, cgunpacker, linkmapper): |
49 # How it works: | 47 # How it works: |
50 # To retrieve a revision, we need to know the offset of the revision in | 48 # To retrieve a revision, we need to know the offset of the revision in |
51 # the bundle (an unbundle object). We store this offset in the index | 49 # the bundle (an unbundle object). We store this offset in the index |
56 opener = vfsmod.readonlyvfs(opener) | 54 opener = vfsmod.readonlyvfs(opener) |
57 revlog.revlog.__init__(self, opener, indexfile) | 55 revlog.revlog.__init__(self, opener, indexfile) |
58 self.bundle = cgunpacker | 56 self.bundle = cgunpacker |
59 n = len(self) | 57 n = len(self) |
60 self.repotiprev = n - 1 | 58 self.repotiprev = n - 1 |
61 self.bundlerevs = set() # used by 'bundle()' revset expression | 59 self.bundlerevs = set() # used by 'bundle()' revset expression |
62 for deltadata in cgunpacker.deltaiter(): | 60 for deltadata in cgunpacker.deltaiter(): |
63 node, p1, p2, cs, deltabase, delta, flags = deltadata | 61 node, p1, p2, cs, deltabase, delta, flags = deltadata |
64 | 62 |
65 size = len(delta) | 63 size = len(delta) |
66 start = cgunpacker.tell() - size | 64 start = cgunpacker.tell() - size |
71 self.bundlerevs.add(self.nodemap[node]) | 69 self.bundlerevs.add(self.nodemap[node]) |
72 continue | 70 continue |
73 | 71 |
74 for p in (p1, p2): | 72 for p in (p1, p2): |
75 if p not in self.nodemap: | 73 if p not in self.nodemap: |
76 raise error.LookupError(p, self.indexfile, | 74 raise error.LookupError( |
77 _("unknown parent")) | 75 p, self.indexfile, _("unknown parent") |
76 ) | |
78 | 77 |
79 if deltabase not in self.nodemap: | 78 if deltabase not in self.nodemap: |
80 raise LookupError(deltabase, self.indexfile, | 79 raise LookupError( |
81 _('unknown delta base')) | 80 deltabase, self.indexfile, _('unknown delta base') |
81 ) | |
82 | 82 |
83 baserev = self.rev(deltabase) | 83 baserev = self.rev(deltabase) |
84 # start, size, full unc. size, base (unused), link, p1, p2, node | 84 # start, size, full unc. size, base (unused), link, p1, p2, node |
85 e = (revlog.offset_type(start, flags), size, -1, baserev, link, | 85 e = ( |
86 self.rev(p1), self.rev(p2), node) | 86 revlog.offset_type(start, flags), |
87 size, | |
88 -1, | |
89 baserev, | |
90 link, | |
91 self.rev(p1), | |
92 self.rev(p2), | |
93 node, | |
94 ) | |
87 self.index.append(e) | 95 self.index.append(e) |
88 self.nodemap[node] = n | 96 self.nodemap[node] = n |
89 self.bundlerevs.add(n) | 97 self.bundlerevs.add(n) |
90 n += 1 | 98 n += 1 |
91 | 99 |
106 if revb == rev1: | 114 if revb == rev1: |
107 return self._chunk(rev2) | 115 return self._chunk(rev2) |
108 elif rev1 <= self.repotiprev and rev2 <= self.repotiprev: | 116 elif rev1 <= self.repotiprev and rev2 <= self.repotiprev: |
109 return revlog.revlog.revdiff(self, rev1, rev2) | 117 return revlog.revlog.revdiff(self, rev1, rev2) |
110 | 118 |
111 return mdiff.textdiff(self.rawdata(rev1), | 119 return mdiff.textdiff(self.rawdata(rev1), self.rawdata(rev2)) |
112 self.rawdata(rev2)) | |
113 | 120 |
114 def _rawtext(self, node, rev, _df=None): | 121 def _rawtext(self, node, rev, _df=None): |
115 if rev is None: | 122 if rev is None: |
116 rev = self.rev(node) | 123 rev = self.rev(node) |
117 validated = False | 124 validated = False |
126 chain.append(iterrev) | 133 chain.append(iterrev) |
127 iterrev = self.index[iterrev][3] | 134 iterrev = self.index[iterrev][3] |
128 if iterrev == nullrev: | 135 if iterrev == nullrev: |
129 rawtext = '' | 136 rawtext = '' |
130 elif rawtext is None: | 137 elif rawtext is None: |
131 r = super(bundlerevlog, self)._rawtext(self.node(iterrev), | 138 r = super(bundlerevlog, self)._rawtext( |
132 iterrev, | 139 self.node(iterrev), iterrev, _df=_df |
133 _df=_df) | 140 ) |
134 __, rawtext, validated = r | 141 __, rawtext, validated = r |
135 if chain: | 142 if chain: |
136 validated = False | 143 validated = False |
137 while chain: | 144 while chain: |
138 delta = self._chunk(chain.pop()) | 145 delta = self._chunk(chain.pop()) |
149 raise NotImplementedError | 156 raise NotImplementedError |
150 | 157 |
151 def checksize(self): | 158 def checksize(self): |
152 raise NotImplementedError | 159 raise NotImplementedError |
153 | 160 |
161 | |
154 class bundlechangelog(bundlerevlog, changelog.changelog): | 162 class bundlechangelog(bundlerevlog, changelog.changelog): |
155 def __init__(self, opener, cgunpacker): | 163 def __init__(self, opener, cgunpacker): |
156 changelog.changelog.__init__(self, opener) | 164 changelog.changelog.__init__(self, opener) |
157 linkmapper = lambda x: x | 165 linkmapper = lambda x: x |
158 bundlerevlog.__init__(self, opener, self.indexfile, cgunpacker, | 166 bundlerevlog.__init__( |
159 linkmapper) | 167 self, opener, self.indexfile, cgunpacker, linkmapper |
168 ) | |
169 | |
160 | 170 |
161 class bundlemanifest(bundlerevlog, manifest.manifestrevlog): | 171 class bundlemanifest(bundlerevlog, manifest.manifestrevlog): |
162 def __init__(self, opener, cgunpacker, linkmapper, dirlogstarts=None, | 172 def __init__( |
163 dir=''): | 173 self, opener, cgunpacker, linkmapper, dirlogstarts=None, dir='' |
174 ): | |
164 manifest.manifestrevlog.__init__(self, opener, tree=dir) | 175 manifest.manifestrevlog.__init__(self, opener, tree=dir) |
165 bundlerevlog.__init__(self, opener, self.indexfile, cgunpacker, | 176 bundlerevlog.__init__( |
166 linkmapper) | 177 self, opener, self.indexfile, cgunpacker, linkmapper |
178 ) | |
167 if dirlogstarts is None: | 179 if dirlogstarts is None: |
168 dirlogstarts = {} | 180 dirlogstarts = {} |
169 if self.bundle.version == "03": | 181 if self.bundle.version == "03": |
170 dirlogstarts = _getfilestarts(self.bundle) | 182 dirlogstarts = _getfilestarts(self.bundle) |
171 self._dirlogstarts = dirlogstarts | 183 self._dirlogstarts = dirlogstarts |
173 | 185 |
174 def dirlog(self, d): | 186 def dirlog(self, d): |
175 if d in self._dirlogstarts: | 187 if d in self._dirlogstarts: |
176 self.bundle.seek(self._dirlogstarts[d]) | 188 self.bundle.seek(self._dirlogstarts[d]) |
177 return bundlemanifest( | 189 return bundlemanifest( |
178 self.opener, self.bundle, self._linkmapper, | 190 self.opener, |
179 self._dirlogstarts, dir=d) | 191 self.bundle, |
192 self._linkmapper, | |
193 self._dirlogstarts, | |
194 dir=d, | |
195 ) | |
180 return super(bundlemanifest, self).dirlog(d) | 196 return super(bundlemanifest, self).dirlog(d) |
197 | |
181 | 198 |
182 class bundlefilelog(filelog.filelog): | 199 class bundlefilelog(filelog.filelog): |
183 def __init__(self, opener, path, cgunpacker, linkmapper): | 200 def __init__(self, opener, path, cgunpacker, linkmapper): |
184 filelog.filelog.__init__(self, opener, path) | 201 filelog.filelog.__init__(self, opener, path) |
185 self._revlog = bundlerevlog(opener, self.indexfile, | 202 self._revlog = bundlerevlog( |
186 cgunpacker, linkmapper) | 203 opener, self.indexfile, cgunpacker, linkmapper |
204 ) | |
205 | |
187 | 206 |
188 class bundlepeer(localrepo.localpeer): | 207 class bundlepeer(localrepo.localpeer): |
189 def canpush(self): | 208 def canpush(self): |
190 return False | 209 return False |
210 | |
191 | 211 |
192 class bundlephasecache(phases.phasecache): | 212 class bundlephasecache(phases.phasecache): |
193 def __init__(self, *args, **kwargs): | 213 def __init__(self, *args, **kwargs): |
194 super(bundlephasecache, self).__init__(*args, **kwargs) | 214 super(bundlephasecache, self).__init__(*args, **kwargs) |
195 if util.safehasattr(self, 'opener'): | 215 if util.safehasattr(self, 'opener'): |
203 | 223 |
204 def _updateroots(self, phase, newroots, tr): | 224 def _updateroots(self, phase, newroots, tr): |
205 self.phaseroots[phase] = newroots | 225 self.phaseroots[phase] = newroots |
206 self.invalidate() | 226 self.invalidate() |
207 self.dirty = True | 227 self.dirty = True |
228 | |
208 | 229 |
209 def _getfilestarts(cgunpacker): | 230 def _getfilestarts(cgunpacker): |
210 filespos = {} | 231 filespos = {} |
211 for chunkdata in iter(cgunpacker.filelogheader, {}): | 232 for chunkdata in iter(cgunpacker.filelogheader, {}): |
212 fname = chunkdata['filename'] | 233 fname = chunkdata['filename'] |
213 filespos[fname] = cgunpacker.tell() | 234 filespos[fname] = cgunpacker.tell() |
214 for chunk in iter(lambda: cgunpacker.deltachunk(None), {}): | 235 for chunk in iter(lambda: cgunpacker.deltachunk(None), {}): |
215 pass | 236 pass |
216 return filespos | 237 return filespos |
217 | 238 |
239 | |
218 class bundlerepository(object): | 240 class bundlerepository(object): |
219 """A repository instance that is a union of a local repo and a bundle. | 241 """A repository instance that is a union of a local repo and a bundle. |
220 | 242 |
221 Instances represent a read-only repository composed of a local repository | 243 Instances represent a read-only repository composed of a local repository |
222 with the contents of a bundle file applied. The repository instance is | 244 with the contents of a bundle file applied. The repository instance is |
225 applied to the actual base repository. | 247 applied to the actual base repository. |
226 | 248 |
227 Instances constructed directly are not usable as repository objects. | 249 Instances constructed directly are not usable as repository objects. |
228 Use instance() or makebundlerepository() to create instances. | 250 Use instance() or makebundlerepository() to create instances. |
229 """ | 251 """ |
252 | |
230 def __init__(self, bundlepath, url, tempparent): | 253 def __init__(self, bundlepath, url, tempparent): |
231 self._tempparent = tempparent | 254 self._tempparent = tempparent |
232 self._url = url | 255 self._url = url |
233 | 256 |
234 self.ui.setconfig('phases', 'publish', False, 'bundlerepo') | 257 self.ui.setconfig('phases', 'publish', False, 'bundlerepo') |
243 | 266 |
244 cgpart = None | 267 cgpart = None |
245 for part in bundle.iterparts(seekable=True): | 268 for part in bundle.iterparts(seekable=True): |
246 if part.type == 'changegroup': | 269 if part.type == 'changegroup': |
247 if cgpart: | 270 if cgpart: |
248 raise NotImplementedError("can't process " | 271 raise NotImplementedError( |
249 "multiple changegroups") | 272 "can't process " "multiple changegroups" |
273 ) | |
250 cgpart = part | 274 cgpart = part |
251 | 275 |
252 self._handlebundle2part(bundle, part) | 276 self._handlebundle2part(bundle, part) |
253 | 277 |
254 if not cgpart: | 278 if not cgpart: |
261 # generator returns control to iterparts(). | 285 # generator returns control to iterparts(). |
262 cgpart.seek(0, os.SEEK_SET) | 286 cgpart.seek(0, os.SEEK_SET) |
263 | 287 |
264 elif isinstance(bundle, changegroup.cg1unpacker): | 288 elif isinstance(bundle, changegroup.cg1unpacker): |
265 if bundle.compressed(): | 289 if bundle.compressed(): |
266 f = self._writetempbundle(bundle.read, '.hg10un', | 290 f = self._writetempbundle( |
267 header='HG10UN') | 291 bundle.read, '.hg10un', header='HG10UN' |
292 ) | |
268 bundle = exchange.readbundle(self.ui, f, bundlepath, self.vfs) | 293 bundle = exchange.readbundle(self.ui, f, bundlepath, self.vfs) |
269 | 294 |
270 self._bundlefile = bundle | 295 self._bundlefile = bundle |
271 self._cgunpacker = bundle | 296 self._cgunpacker = bundle |
272 else: | 297 else: |
273 raise error.Abort(_('bundle type %s cannot be read') % | 298 raise error.Abort(_('bundle type %s cannot be read') % type(bundle)) |
274 type(bundle)) | |
275 | 299 |
276 # dict with the mapping 'filename' -> position in the changegroup. | 300 # dict with the mapping 'filename' -> position in the changegroup. |
277 self._cgfilespos = {} | 301 self._cgfilespos = {} |
278 | 302 |
279 self.firstnewrev = self.changelog.repotiprev + 1 | 303 self.firstnewrev = self.changelog.repotiprev + 1 |
280 phases.retractboundary(self, None, phases.draft, | 304 phases.retractboundary( |
281 [ctx.node() for ctx in self[self.firstnewrev:]]) | 305 self, |
306 None, | |
307 phases.draft, | |
308 [ctx.node() for ctx in self[self.firstnewrev :]], | |
309 ) | |
282 | 310 |
283 def _handlebundle2part(self, bundle, part): | 311 def _handlebundle2part(self, bundle, part): |
284 if part.type != 'changegroup': | 312 if part.type != 'changegroup': |
285 return | 313 return |
286 | 314 |
296 self._cgunpacker = changegroup.getunbundler(version, cgstream, 'UN') | 324 self._cgunpacker = changegroup.getunbundler(version, cgstream, 'UN') |
297 | 325 |
298 def _writetempbundle(self, readfn, suffix, header=''): | 326 def _writetempbundle(self, readfn, suffix, header=''): |
299 """Write a temporary file to disk | 327 """Write a temporary file to disk |
300 """ | 328 """ |
301 fdtemp, temp = self.vfs.mkstemp(prefix="hg-bundle-", | 329 fdtemp, temp = self.vfs.mkstemp(prefix="hg-bundle-", suffix=suffix) |
302 suffix=suffix) | |
303 self.tempfile = temp | 330 self.tempfile = temp |
304 | 331 |
305 with os.fdopen(fdtemp, r'wb') as fptemp: | 332 with os.fdopen(fdtemp, r'wb') as fptemp: |
306 fptemp.write(header) | 333 fptemp.write(header) |
307 while True: | 334 while True: |
308 chunk = readfn(2**18) | 335 chunk = readfn(2 ** 18) |
309 if not chunk: | 336 if not chunk: |
310 break | 337 break |
311 fptemp.write(chunk) | 338 fptemp.write(chunk) |
312 | 339 |
313 return self.vfs.open(self.tempfile, mode="rb") | 340 return self.vfs.open(self.tempfile, mode="rb") |
336 self._cgunpacker.manifestheader() | 363 self._cgunpacker.manifestheader() |
337 linkmapper = self.unfiltered().changelog.rev | 364 linkmapper = self.unfiltered().changelog.rev |
338 rootstore = bundlemanifest(self.svfs, self._cgunpacker, linkmapper) | 365 rootstore = bundlemanifest(self.svfs, self._cgunpacker, linkmapper) |
339 self.filestart = self._cgunpacker.tell() | 366 self.filestart = self._cgunpacker.tell() |
340 | 367 |
341 return manifest.manifestlog(self.svfs, self, rootstore, | 368 return manifest.manifestlog( |
342 self.narrowmatch()) | 369 self.svfs, self, rootstore, self.narrowmatch() |
370 ) | |
343 | 371 |
344 def _consumemanifest(self): | 372 def _consumemanifest(self): |
345 """Consumes the manifest portion of the bundle, setting filestart so the | 373 """Consumes the manifest portion of the bundle, setting filestart so the |
346 file portion can be read.""" | 374 file portion can be read.""" |
347 self._cgunpacker.seek(self.manstart) | 375 self._cgunpacker.seek(self.manstart) |
396 | 424 |
397 def peer(self): | 425 def peer(self): |
398 return bundlepeer(self) | 426 return bundlepeer(self) |
399 | 427 |
400 def getcwd(self): | 428 def getcwd(self): |
401 return encoding.getcwd() # always outside the repo | 429 return encoding.getcwd() # always outside the repo |
402 | 430 |
403 # Check if parents exist in localrepo before setting | 431 # Check if parents exist in localrepo before setting |
404 def setparents(self, p1, p2=nullid): | 432 def setparents(self, p1, p2=nullid): |
405 p1rev = self.changelog.rev(p1) | 433 p1rev = self.changelog.rev(p1) |
406 p2rev = self.changelog.rev(p2) | 434 p2rev = self.changelog.rev(p2) |
408 if self.changelog.repotiprev < p1rev: | 436 if self.changelog.repotiprev < p1rev: |
409 self.ui.warn(msg % nodemod.hex(p1)) | 437 self.ui.warn(msg % nodemod.hex(p1)) |
410 if self.changelog.repotiprev < p2rev: | 438 if self.changelog.repotiprev < p2rev: |
411 self.ui.warn(msg % nodemod.hex(p2)) | 439 self.ui.warn(msg % nodemod.hex(p2)) |
412 return super(bundlerepository, self).setparents(p1, p2) | 440 return super(bundlerepository, self).setparents(p1, p2) |
441 | |
413 | 442 |
414 def instance(ui, path, create, intents=None, createopts=None): | 443 def instance(ui, path, create, intents=None, createopts=None): |
415 if create: | 444 if create: |
416 raise error.Abort(_('cannot create new bundle repository')) | 445 raise error.Abort(_('cannot create new bundle repository')) |
417 # internal config: bundle.mainreporoot | 446 # internal config: bundle.mainreporoot |
428 if parentpath == cwd: | 457 if parentpath == cwd: |
429 parentpath = '' | 458 parentpath = '' |
430 else: | 459 else: |
431 cwd = pathutil.normasprefix(cwd) | 460 cwd = pathutil.normasprefix(cwd) |
432 if parentpath.startswith(cwd): | 461 if parentpath.startswith(cwd): |
433 parentpath = parentpath[len(cwd):] | 462 parentpath = parentpath[len(cwd) :] |
434 u = util.url(path) | 463 u = util.url(path) |
435 path = u.localpath() | 464 path = u.localpath() |
436 if u.scheme == 'bundle': | 465 if u.scheme == 'bundle': |
437 s = path.split("+", 1) | 466 s = path.split("+", 1) |
438 if len(s) == 1: | 467 if len(s) == 1: |
442 else: | 471 else: |
443 repopath, bundlename = parentpath, path | 472 repopath, bundlename = parentpath, path |
444 | 473 |
445 return makebundlerepository(ui, repopath, bundlename) | 474 return makebundlerepository(ui, repopath, bundlename) |
446 | 475 |
476 | |
447 def makebundlerepository(ui, repopath, bundlepath): | 477 def makebundlerepository(ui, repopath, bundlepath): |
448 """Make a bundle repository object based on repo and bundle paths.""" | 478 """Make a bundle repository object based on repo and bundle paths.""" |
449 if repopath: | 479 if repopath: |
450 url = 'bundle:%s+%s' % (util.expandpath(repopath), bundlepath) | 480 url = 'bundle:%s+%s' % (util.expandpath(repopath), bundlepath) |
451 else: | 481 else: |
479 repo.__class__ = derivedbundlerepository | 509 repo.__class__ = derivedbundlerepository |
480 bundlerepository.__init__(repo, bundlepath, url, tempparent) | 510 bundlerepository.__init__(repo, bundlepath, url, tempparent) |
481 | 511 |
482 return repo | 512 return repo |
483 | 513 |
514 | |
484 class bundletransactionmanager(object): | 515 class bundletransactionmanager(object): |
485 def transaction(self): | 516 def transaction(self): |
486 return None | 517 return None |
487 | 518 |
488 def close(self): | 519 def close(self): |
489 raise NotImplementedError | 520 raise NotImplementedError |
490 | 521 |
491 def release(self): | 522 def release(self): |
492 raise NotImplementedError | 523 raise NotImplementedError |
493 | 524 |
494 def getremotechanges(ui, repo, peer, onlyheads=None, bundlename=None, | 525 |
495 force=False): | 526 def getremotechanges( |
527 ui, repo, peer, onlyheads=None, bundlename=None, force=False | |
528 ): | |
496 '''obtains a bundle of changes incoming from peer | 529 '''obtains a bundle of changes incoming from peer |
497 | 530 |
498 "onlyheads" restricts the returned changes to those reachable from the | 531 "onlyheads" restricts the returned changes to those reachable from the |
499 specified heads. | 532 specified heads. |
500 "bundlename", if given, stores the bundle to this file path permanently; | 533 "bundlename", if given, stores the bundle to this file path permanently; |
510 "csets" lists the incoming changeset node ids. | 543 "csets" lists the incoming changeset node ids. |
511 "cleanupfn" must be called without arguments when you're done processing | 544 "cleanupfn" must be called without arguments when you're done processing |
512 the changes; it closes both the original "peer" and the one returned | 545 the changes; it closes both the original "peer" and the one returned |
513 here. | 546 here. |
514 ''' | 547 ''' |
515 tmp = discovery.findcommonincoming(repo, peer, heads=onlyheads, | 548 tmp = discovery.findcommonincoming(repo, peer, heads=onlyheads, force=force) |
516 force=force) | |
517 common, incoming, rheads = tmp | 549 common, incoming, rheads = tmp |
518 if not incoming: | 550 if not incoming: |
519 try: | 551 try: |
520 if bundlename: | 552 if bundlename: |
521 os.unlink(bundlename) | 553 os.unlink(bundlename) |
533 # create a bundle (uncompressed if peer repo is not local) | 565 # create a bundle (uncompressed if peer repo is not local) |
534 | 566 |
535 # developer config: devel.legacy.exchange | 567 # developer config: devel.legacy.exchange |
536 legexc = ui.configlist('devel', 'legacy.exchange') | 568 legexc = ui.configlist('devel', 'legacy.exchange') |
537 forcebundle1 = 'bundle2' not in legexc and 'bundle1' in legexc | 569 forcebundle1 = 'bundle2' not in legexc and 'bundle1' in legexc |
538 canbundle2 = (not forcebundle1 | 570 canbundle2 = ( |
539 and peer.capable('getbundle') | 571 not forcebundle1 |
540 and peer.capable('bundle2')) | 572 and peer.capable('getbundle') |
573 and peer.capable('bundle2') | |
574 ) | |
541 if canbundle2: | 575 if canbundle2: |
542 with peer.commandexecutor() as e: | 576 with peer.commandexecutor() as e: |
543 b2 = e.callcommand('getbundle', { | 577 b2 = e.callcommand( |
544 'source': 'incoming', | 578 'getbundle', |
545 'common': common, | 579 { |
546 'heads': rheads, | 580 'source': 'incoming', |
547 'bundlecaps': exchange.caps20to10(repo, role='client'), | 581 'common': common, |
548 'cg': True, | 582 'heads': rheads, |
549 }).result() | 583 'bundlecaps': exchange.caps20to10(repo, role='client'), |
550 | 584 'cg': True, |
551 fname = bundle = changegroup.writechunks(ui, | 585 }, |
552 b2._forwardchunks(), | 586 ).result() |
553 bundlename) | 587 |
588 fname = bundle = changegroup.writechunks( | |
589 ui, b2._forwardchunks(), bundlename | |
590 ) | |
554 else: | 591 else: |
555 if peer.capable('getbundle'): | 592 if peer.capable('getbundle'): |
556 with peer.commandexecutor() as e: | 593 with peer.commandexecutor() as e: |
557 cg = e.callcommand('getbundle', { | 594 cg = e.callcommand( |
558 'source': 'incoming', | 595 'getbundle', |
559 'common': common, | 596 { |
560 'heads': rheads, | 597 'source': 'incoming', |
561 }).result() | 598 'common': common, |
599 'heads': rheads, | |
600 }, | |
601 ).result() | |
562 elif onlyheads is None and not peer.capable('changegroupsubset'): | 602 elif onlyheads is None and not peer.capable('changegroupsubset'): |
563 # compat with older servers when pulling all remote heads | 603 # compat with older servers when pulling all remote heads |
564 | 604 |
565 with peer.commandexecutor() as e: | 605 with peer.commandexecutor() as e: |
566 cg = e.callcommand('changegroup', { | 606 cg = e.callcommand( |
567 'nodes': incoming, | 607 'changegroup', |
568 'source': 'incoming', | 608 {'nodes': incoming, 'source': 'incoming',}, |
569 }).result() | 609 ).result() |
570 | 610 |
571 rheads = None | 611 rheads = None |
572 else: | 612 else: |
573 with peer.commandexecutor() as e: | 613 with peer.commandexecutor() as e: |
574 cg = e.callcommand('changegroupsubset', { | 614 cg = e.callcommand( |
575 'bases': incoming, | 615 'changegroupsubset', |
576 'heads': rheads, | 616 { |
577 'source': 'incoming', | 617 'bases': incoming, |
578 }).result() | 618 'heads': rheads, |
619 'source': 'incoming', | |
620 }, | |
621 ).result() | |
579 | 622 |
580 if localrepo: | 623 if localrepo: |
581 bundletype = "HG10BZ" | 624 bundletype = "HG10BZ" |
582 else: | 625 else: |
583 bundletype = "HG10UN" | 626 bundletype = "HG10UN" |
584 fname = bundle = bundle2.writebundle(ui, cg, bundlename, | 627 fname = bundle = bundle2.writebundle(ui, cg, bundlename, bundletype) |
585 bundletype) | |
586 # keep written bundle? | 628 # keep written bundle? |
587 if bundlename: | 629 if bundlename: |
588 bundle = None | 630 bundle = None |
589 if not localrepo: | 631 if not localrepo: |
590 # use the created uncompressed bundlerepo | 632 # use the created uncompressed bundlerepo |
591 localrepo = bundlerepo = makebundlerepository(repo. baseui, | 633 localrepo = bundlerepo = makebundlerepository( |
592 repo.root, | 634 repo.baseui, repo.root, fname |
593 fname) | 635 ) |
594 | 636 |
595 # this repo contains local and peer now, so filter out local again | 637 # this repo contains local and peer now, so filter out local again |
596 common = repo.heads() | 638 common = repo.heads() |
597 if localrepo: | 639 if localrepo: |
598 # Part of common may be remotely filtered | 640 # Part of common may be remotely filtered |
601 localrepo = localrepo.unfiltered() | 643 localrepo = localrepo.unfiltered() |
602 | 644 |
603 csets = localrepo.changelog.findmissing(common, rheads) | 645 csets = localrepo.changelog.findmissing(common, rheads) |
604 | 646 |
605 if bundlerepo: | 647 if bundlerepo: |
606 reponodes = [ctx.node() for ctx in bundlerepo[bundlerepo.firstnewrev:]] | 648 reponodes = [ctx.node() for ctx in bundlerepo[bundlerepo.firstnewrev :]] |
607 | 649 |
608 with peer.commandexecutor() as e: | 650 with peer.commandexecutor() as e: |
609 remotephases = e.callcommand('listkeys', { | 651 remotephases = e.callcommand( |
610 'namespace': 'phases', | 652 'listkeys', {'namespace': 'phases',} |
611 }).result() | 653 ).result() |
612 | 654 |
613 pullop = exchange.pulloperation(bundlerepo, peer, heads=reponodes) | 655 pullop = exchange.pulloperation(bundlerepo, peer, heads=reponodes) |
614 pullop.trmanager = bundletransactionmanager() | 656 pullop.trmanager = bundletransactionmanager() |
615 exchange._pullapplyphases(pullop, remotephases) | 657 exchange._pullapplyphases(pullop, remotephases) |
616 | 658 |