comparison mercurial/streamclone.py @ 26441:56527b886d1d

streamclone: move applystreamclone() from localrepo.py Upcoming patches will modernize the streaming clone code. Streaming clone data and code kind of lives in its own world. exchange.py is arguably the most appropriate existing location for it. However, over a dozen patches from now it became apparent that there was a lot of code related to streaming clones and that having it contained within its own module would make it easier to comprehend. So, we establish streamclone.py. It's worth noting that streamclone.py existed a long time ago, last seen in the 1.6 release. It was removed in 04f76a954842. The function was renamed as part of the move because its old name was redundant with the new module name. The only other content change was "self" was renamed to "repo" and minor grammar in the docstring was updated.
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 02 Oct 2015 15:51:32 -0700
parents
children ef8d27f53204
comparison
equal deleted inserted replaced
26440:85b992177d2a 26441:56527b886d1d
1 # streamclone.py - producing and consuming streaming repository data
2 #
3 # Copyright 2015 Gregory Szorc <gregory.szorc@gmail.com>
4 #
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
7
8 from __future__ import absolute_import
9
10 from . import (
11 branchmap,
12 exchange,
13 )
14
15 def applyremotedata(repo, remotereqs, remotebranchmap, fp):
16 """Apply stream clone data to a repository.
17
18 "remotereqs" is a set of requirements to handle the incoming data.
19 "remotebranchmap" is the result of a branchmap lookup on the remote. It
20 can be None.
21 "fp" is a file object containing the raw stream data, suitable for
22 feeding into exchange.consumestreamclone.
23 """
24 lock = repo.lock()
25 try:
26 exchange.consumestreamclone(repo, fp)
27
28 # new requirements = old non-format requirements +
29 # new format-related remote requirements
30 # requirements from the streamed-in repository
31 repo.requirements = remotereqs | (
32 repo.requirements - repo.supportedformats)
33 repo._applyopenerreqs()
34 repo._writerequirements()
35
36 if remotebranchmap:
37 rbheads = []
38 closed = []
39 for bheads in remotebranchmap.itervalues():
40 rbheads.extend(bheads)
41 for h in bheads:
42 r = repo.changelog.rev(h)
43 b, c = repo.changelog.branchinfo(r)
44 if c:
45 closed.append(h)
46
47 if rbheads:
48 rtiprev = max((int(repo.changelog.rev(node))
49 for node in rbheads))
50 cache = branchmap.branchcache(remotebranchmap,
51 repo[rtiprev].node(),
52 rtiprev,
53 closednodes=closed)
54 # Try to stick it as low as possible
55 # filter above served are unlikely to be fetch from a clone
56 for candidate in ('base', 'immutable', 'served'):
57 rview = repo.filtered(candidate)
58 if cache.validfor(rview):
59 repo._branchcaches[candidate] = cache
60 cache.write(rview)
61 break
62 repo.invalidate()
63 finally:
64 lock.release()