annotate hgext3rd/pullbundle.py @ 4132:afc933d32085

pullbundle: add extension documentation
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 23 Sep 2018 22:45:23 +0200
parents a1f6b8211016
children 1293625d274d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4128
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
1 # Extension to provide automatic caching of bundle server for pull
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
2 #
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
3 # Copyright 2018 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
4 #
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
4132
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
7 """pullbundle: automatic server side bundle caching
4128
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
8
4132
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
9 General principle
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
10 =================
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
11
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
12 This extension provides a means for server to use pre-computed bundle for
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
13 serving arbitrary pulls. If missing, the necessary pre-computed bundle will be
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
14 generated on demand.
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
15
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
16 To maximize usage of existing cached bundle, each pull will be served through
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
17 multiple bundles. The bundle will be created using "standard range" from the
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
18 "stablerange" principle. The "stablerange" concept if already used for
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
19 obsmarkers discovery in the evolve extensions.
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
20
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
21 Using pull Bundle
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
22 =================
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
23
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
24 All configuration is only required server side.
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
25
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
26 The "stablerange" code currently still live in the evolve extensions, so for
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
27 now enabling that extensions is required:
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
28
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
29 You need at minimum the following configuration:
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
30
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
31 [extensions]
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
32 evolve=yes
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
33 pullbundle=yes
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
34 [experimental]
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
35 obshashrange.warm-cache = yes
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
36
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
37 If you do not want to use evolution server side, you should disable obsmarkers exchange:
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
38
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
39 [experimental]
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
40 evolution.exchange=no
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
41
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
42 Implementation status
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
43 =====================
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
44
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
45 Both for stablerange and pullbundle use "simple" initial implementations.
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
46 Theses implemenations focus on testing the algorithms and proving the features
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
47 works. Yet they are already useful and used in production.
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
48
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
49 Performances are expected to greatly improved in the final implementation,
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
50 especially if some of it end up being compiled.
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
51
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
52 This first implementation lacks the ability to server the cached bundle from a
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
53 CDN. We'll want this limitation to be lifted quickly.
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
54
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
55 Why is does this live in the same repository as evolve
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
56 ======================================================
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
57
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
58 There is no fundamental reasons for live in the same repository. However, the
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
59 stablerange data-structure lives in evolve, so it was simpler to put this new
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
60 extensions next to it. As soon as stable range have been upstreamed, we won't
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
61 need the dependency to the evolve extension anymore.
afc933d32085 pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4130
diff changeset
62 """
4129
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
63 import errno
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
64 import os
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
65
4128
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
66 from mercurial import (
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
67 changegroup,
4129
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
68 discovery,
4128
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
69 exchange,
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
70 narrowspec,
4129
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
71 node as nodemod,
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
72 util,
4128
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
73 )
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
74
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
75 from mercurial.i18n import _
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
76
4129
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
77 # generic wrapping
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
78
4128
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
79 def uisetup(ui):
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
80 exchange.getbundle2partsmapping['changegroup'] = _getbundlechangegrouppart
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
81
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
82 def _getbundlechangegrouppart(bundler, repo, source, bundlecaps=None,
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
83 b2caps=None, heads=None, common=None, **kwargs):
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
84 """add a changegroup part to the requested bundle"""
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
85 if not kwargs.get(r'cg', True):
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
86 return
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
87
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
88 version = '01'
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
89 cgversions = b2caps.get('changegroup')
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
90 if cgversions: # 3.1 and 3.2 ship with an empty value
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
91 cgversions = [v for v in cgversions
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
92 if v in changegroup.supportedoutgoingversions(repo)]
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
93 if not cgversions:
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
94 raise ValueError(_('no common changegroup version'))
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
95 version = max(cgversions)
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
96
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
97 outgoing = exchange._computeoutgoing(repo, heads, common)
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
98 if not outgoing.missing:
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
99 return
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
100
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
101 if kwargs.get(r'narrow', False):
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
102 include = sorted(filter(bool, kwargs.get(r'includepats', [])))
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
103 exclude = sorted(filter(bool, kwargs.get(r'excludepats', [])))
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
104 filematcher = narrowspec.match(repo.root, include=include,
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
105 exclude=exclude)
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
106 else:
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
107 filematcher = None
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
108
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
109 # START OF ALTERED PART
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
110 makeallcgpart(bundler.newpart, repo, outgoing, version, source, bundlecaps,
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
111 filematcher, cgversions)
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
112 # END OF ALTERED PART
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
113
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
114 if kwargs.get(r'narrow', False) and (include or exclude):
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
115 narrowspecpart = bundler.newpart('narrow:spec')
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
116 if include:
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
117 narrowspecpart.addparam(
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
118 'include', '\n'.join(include), mandatory=True)
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
119 if exclude:
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
120 narrowspecpart.addparam(
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
121 'exclude', '\n'.join(exclude), mandatory=True)
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
122
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
123 def makeallcgpart(newpart, repo, outgoing, version, source,
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
124 bundlecaps, filematcher, cgversions):
4129
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
125
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
126 pullbundle = not filematcher
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
127 if pullbundle and not util.safehasattr(repo, 'stablerange'):
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
128 repo.ui.warn('pullbundle: required extension "evolve" are missing, skipping pullbundle\n')
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
129 pullbundle = False
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
130 if filematcher:
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
131 makeonecgpart(newpart, repo, None, outgoing, version, source, bundlecaps,
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
132 filematcher, cgversions)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
133 else:
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
134 for sliceid, sliceout in sliceoutgoing(repo, outgoing):
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
135 makeonecgpart(newpart, repo, sliceid, sliceout, version, source, bundlecaps,
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
136 filematcher, cgversions)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
137
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
138 # stable range slicing
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
139
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
140 def sliceoutgoing(repo, outgoing):
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
141 cl = repo.changelog
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
142 rev = cl.nodemap.get
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
143 node = cl.node
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
144 revsort = repo.stablesort
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
145
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
146 missingrevs = set(rev(n) for n in outgoing.missing)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
147 allslices = []
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
148 missingheads = [rev(n) for n in outgoing.missingheads]
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
149 for head in missingheads:
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
150 localslices = []
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
151 localmissing = set(repo.revs('%ld and ::%d', missingrevs, head))
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
152 while localmissing:
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
153 slicerevs = []
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
154 for r in revsort.walkfrom(repo, head):
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
155 if r not in missingrevs:
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
156 break
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
157 slicerevs.append(r)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
158 slicenodes = [node(r) for r in slicerevs]
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
159 localslices.extend(canonicalslices(repo, slicenodes))
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
160 missingrevs.difference_update(slicerevs)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
161 localmissing.difference_update(slicerevs)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
162 if localmissing:
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
163 head = max(localmissing)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
164
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
165 allslices.extend(localslices)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
166 return [(rangeid, outgoingfromnodes(repo, nodes))
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
167 for rangeid, nodes in allslices]
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
168
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
169 def canonicalslices(repo, nodes):
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
170 depth = repo.depthcache.get
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
171 stablerange = repo.stablerange
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
172 rangelength = lambda x: stablerange.rangelength(repo, x)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
173 headrev = repo.changelog.rev(nodes[0])
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
174 nbrevs = len(nodes)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
175 headdepth = depth(headrev)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
176 skipped = headdepth - nbrevs
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
177 rangeid = (headrev, skipped)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
178
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
179 subranges = canonicalsubranges(repo, stablerange, rangeid)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
180 idx = 0
4130
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
181 slices = []
4129
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
182 nodes.reverse()
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
183 for rangeid in subranges:
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
184 size = rangelength(rangeid)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
185 slices.append((rangeid, nodes[idx:idx + size]))
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
186 idx += size
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
187 return slices
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
188
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
189 def canonicalsubranges(repo, stablerange, rangeid):
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
190 """slice a size of nodes into most reusable subranges
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
191
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
192 We try to slice a range into a set of "largest" and "canonical" stable
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
193 range.
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
194
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
195 It might make sense to move this function as a 'stablerange' method.
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
196 """
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
197 headrev, skip = rangeid
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
198 rangedepth = stablerange.depthrev(repo, rangeid[0])
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
199 canonicals = []
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
200
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
201 # 0. find the first power of 2 higher than this range depth
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
202 cursor = 1
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
203 while cursor <= rangedepth:
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
204 cursor *= 2
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
205
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
206 # 1. find first cupt
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
207 precut = cut = 0
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
208 while True:
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
209 if skip <= cut:
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
210 break
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
211 if cut + cursor < rangedepth:
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
212 precut = cut
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
213 cut += cursor
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
214 if cursor == 1:
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
215 break
4130
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
216 cursor //= 2
4129
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
217
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
218 # 2. optimise, bottom part
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
219 if skip != cut:
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
220 tailranges = []
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
221 tailsize = cut - skip
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
222 assert 0 < tailsize, tailsize
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
223 prerange = (headrev, precut)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
224 size = stablerange.rangelength(repo, prerange)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
225 sub = stablerange.subranges(repo, prerange)[:-1]
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
226 while not poweroftwo(tailsize):
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
227 for prerange in reversed(sub):
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
228 if tailsize <= 0:
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
229 break
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
230
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
231 assert stablerange.depthrev(repo, prerange[0]) != prerange[1], prerange
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
232 tailrev, tailskip = prerange
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
233 size = stablerange.rangelength(repo, (tailrev, tailskip))
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
234 if tailsize < size:
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
235 tailskip += size - tailsize
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
236 size = tailsize
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
237 tailranges.append((tailrev, tailskip))
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
238 tailsize -= size
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
239 else:
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
240 # size of the last block
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
241 tailsize = stablerange.rangelength(repo, tailranges[-1])
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
242 if poweroftwo(tailsize):
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
243 continue # exit the loop
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
244 prerange = tailranges.pop()
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
245 sub = stablerange.subranges(repo, prerange)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
246
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
247 tailranges.reverse()
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
248 canonicals.extend(tailranges)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
249
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
250 # 3. take recursive subrange until we get to a power of two size?
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
251 current = (headrev, cut)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
252 while not poweroftwo(stablerange.rangelength(repo, current)):
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
253 sub = stablerange.subranges(repo, current)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
254 canonicals.extend(sub[:-1])
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
255 current = sub[-1]
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
256 canonicals.append(current)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
257
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
258 return canonicals
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
259
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
260 def poweroftwo(num):
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
261 return num and not num & (num - 1)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
262
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
263 def outgoingfromnodes(repo, nodes):
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
264 return discovery.outgoing(repo,
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
265 missingroots=nodes,
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
266 missingheads=nodes)
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
267
bc4e62a1cb82 pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4128
diff changeset
268 # changegroup part construction
4128
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
269
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
270 def _changegroupinfo(repo, nodes, source):
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
271 if repo.ui.verbose or source == 'bundle':
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
272 repo.ui.status(_("%d changesets found\n") % len(nodes))
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
273
4130
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
274 def _makenewstream(newpart, repo, outgoing, version, source,
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
275 bundlecaps, filematcher, cgversions):
4128
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
276 old = changegroup._changegroupinfo
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
277 try:
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
278 changegroup._changegroupinfo = _changegroupinfo
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
279 cgstream = changegroup.makestream(repo, outgoing, version, source,
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
280 bundlecaps=bundlecaps,
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
281 filematcher=filematcher)
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
282 finally:
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
283 changegroup._changegroupinfo = old
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
284
4130
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
285 nbchanges = len(outgoing.missing)
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
286 pversion = None
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
287 if cgversions:
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
288 pversion = version
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
289 return (cgstream, nbchanges, pversion)
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
290
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
291 def _makepartfromstream(newpart, repo, cgstream, nbchanges, version):
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
292 # same as upstream code
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
293
4128
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
294 part = newpart('changegroup', data=cgstream)
4130
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
295 if version:
4128
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
296 part.addparam('version', version)
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
297
4130
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
298 part.addparam('nbchanges', '%d' % nbchanges,
4128
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
299 mandatory=False)
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
300
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
301 if 'treemanifest' in repo.requirements:
4e5ec9ae682e pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
302 part.addparam('treemanifest', '1')
4130
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
303
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
304 # cache management
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
305
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
306 def cachedir(repo):
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
307 return repo.cachevfs.join('pullbundles')
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
308
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
309 def getcache(repo, bundlename):
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
310 cdir = cachedir(repo)
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
311 bundlepath = os.path.join(cdir, bundlename)
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
312 try:
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
313 fd = open(bundlepath, 'rb')
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
314 return util.filechunkiter(fd)
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
315 except IOError as exc:
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
316 if exc.errno != errno.ENOENT:
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
317 raise
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
318 return None
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
319
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
320 def cachewriter(repo, bundlename, stream):
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
321 cdir = cachedir(repo)
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
322 bundlepath = os.path.join(cdir, bundlename)
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
323 try:
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
324 os.makedirs(cdir)
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
325 except OSError as exc:
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
326 if exc.errno == errno.EEXIST:
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
327 pass
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
328 with util.atomictempfile(bundlepath) as cachefile:
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
329 for chunk in stream:
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
330 cachefile.write(chunk)
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
331 yield chunk
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
332
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
333 BUNDLEMASK = "%s-%s-%010iskip-%010isize.hg"
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
334
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
335 def makeonecgpart(newpart, repo, rangeid, outgoing, version, source,
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
336 bundlecaps, filematcher, cgversions):
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
337 bundlename = cachedata = None
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
338 if rangeid is not None:
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
339 nbchanges = repo.stablerange.rangelength(repo, rangeid)
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
340 headnode = nodemod.hex(repo.changelog.node(rangeid[0]))
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
341 # XXX do we need to use cgversion in there?
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
342 bundlename = BUNDLEMASK % (version, headnode, rangeid[1], nbchanges)
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
343 cachedata = getcache(repo, bundlename)
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
344 if cachedata is None:
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
345 partdata = _makenewstream(newpart, repo, outgoing, version, source,
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
346 bundlecaps, filematcher, cgversions)
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
347 if bundlename is not None:
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
348 cgstream = cachewriter(repo, bundlename, partdata[0])
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
349 partdata = (cgstream,) + partdata[1:]
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
350 else:
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
351 if repo.ui.verbose or source == 'bundle':
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
352 repo.ui.status(_("%d changesets found in caches\n") % nbchanges)
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
353 pversion = None
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
354 if cgversions:
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
355 pversion = version
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
356 partdata = (cachedata, nbchanges, pversion)
a1f6b8211016 pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4129
diff changeset
357 return _makepartfromstream(newpart, repo, *partdata)