Mercurial > evolve
annotate hgext3rd/pullbundle.py @ 4139:2bd652bece97
pullbundle: delay cache file opening
Otherwise we can end-up with a too many file open at the same time.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 25 Sep 2018 12:53:34 +0200 |
parents | cfdc6f55599b |
children | 9b71aa222f8e |
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 |
4134
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
42 Extra Configuration |
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
43 =================== |
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
44 |
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
45 [pullbundle] |
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
46 # By default bundles are stored `.hg/cache/pullbundles/. |
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
47 # This can be changed with the following config: |
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
48 cache-directory=/absolute/path |
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
49 |
4132
afc933d32085
pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4130
diff
changeset
|
50 Implementation status |
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 |
afc933d32085
pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4130
diff
changeset
|
53 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
|
54 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
|
55 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
|
56 |
afc933d32085
pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4130
diff
changeset
|
57 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
|
58 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
|
59 |
afc933d32085
pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4130
diff
changeset
|
60 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
|
61 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
|
62 |
afc933d32085
pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4130
diff
changeset
|
63 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
|
64 ====================================================== |
afc933d32085
pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4130
diff
changeset
|
65 |
afc933d32085
pullbundle: add extension documentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4130
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 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
|
70 """ |
4129
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
71 import errno |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
72 import os |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
73 |
4128
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
74 from mercurial import ( |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
75 changegroup, |
4129
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
76 discovery, |
4128
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
77 exchange, |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
78 narrowspec, |
4129
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
79 node as nodemod, |
4134
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
80 registrar, |
4129
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
81 util, |
4128
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
82 ) |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
83 |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
84 from mercurial.i18n import _ |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
85 |
4135
47f1d7b4305d
pullbundle: add basic extension metadata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4134
diff
changeset
|
86 __version__ = '0.1.0.dev' |
47f1d7b4305d
pullbundle: add basic extension metadata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4134
diff
changeset
|
87 testedwith = '4.7.1' |
47f1d7b4305d
pullbundle: add basic extension metadata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4134
diff
changeset
|
88 # minimumhgversion = '' |
47f1d7b4305d
pullbundle: add basic extension metadata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4134
diff
changeset
|
89 buglink = 'https://bz.mercurial-scm.org/' |
47f1d7b4305d
pullbundle: add basic extension metadata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4134
diff
changeset
|
90 |
4134
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
91 configtable = {} |
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
92 configitem = registrar.configitem(configtable) |
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
93 |
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
94 configitem('pullbundle', 'cache-directory', |
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
95 default=None, |
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
96 ) |
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
97 |
4129
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
98 # generic wrapping |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
99 |
4128
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
100 def uisetup(ui): |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
101 exchange.getbundle2partsmapping['changegroup'] = _getbundlechangegrouppart |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
102 |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
103 def _getbundlechangegrouppart(bundler, repo, source, bundlecaps=None, |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
104 b2caps=None, heads=None, common=None, **kwargs): |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
105 """add a changegroup part to the requested bundle""" |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
106 if not kwargs.get(r'cg', True): |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
107 return |
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 version = '01' |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
110 cgversions = b2caps.get('changegroup') |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
111 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
|
112 cgversions = [v for v in cgversions |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
113 if v in changegroup.supportedoutgoingversions(repo)] |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
114 if not cgversions: |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
115 raise ValueError(_('no common changegroup version')) |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
116 version = max(cgversions) |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
117 |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
118 outgoing = exchange._computeoutgoing(repo, heads, common) |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
119 if not outgoing.missing: |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
120 return |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
121 |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
122 if kwargs.get(r'narrow', False): |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
123 include = sorted(filter(bool, kwargs.get(r'includepats', []))) |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
124 exclude = sorted(filter(bool, kwargs.get(r'excludepats', []))) |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
125 filematcher = narrowspec.match(repo.root, include=include, |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
126 exclude=exclude) |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
127 else: |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
128 filematcher = None |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
129 |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
130 # START OF ALTERED PART |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
131 makeallcgpart(bundler.newpart, repo, outgoing, version, source, bundlecaps, |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
132 filematcher, cgversions) |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
133 # END OF ALTERED PART |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
134 |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
135 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
|
136 narrowspecpart = bundler.newpart('narrow:spec') |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
137 if include: |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
138 narrowspecpart.addparam( |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
139 'include', '\n'.join(include), mandatory=True) |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
140 if exclude: |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
141 narrowspecpart.addparam( |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
142 'exclude', '\n'.join(exclude), mandatory=True) |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
143 |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
144 def makeallcgpart(newpart, repo, outgoing, version, source, |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
145 bundlecaps, filematcher, cgversions): |
4129
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
146 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
147 pullbundle = not filematcher |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
148 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
|
149 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
|
150 pullbundle = False |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
151 if filematcher: |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
152 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
|
153 filematcher, cgversions) |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
154 else: |
4133
1293625d274d
pullbundle: add an output about the time spent slicing the set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4132
diff
changeset
|
155 start = util.timer() |
1293625d274d
pullbundle: add an output about the time spent slicing the set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4132
diff
changeset
|
156 slices = sliceoutgoing(repo, outgoing) |
1293625d274d
pullbundle: add an output about the time spent slicing the set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4132
diff
changeset
|
157 end = util.timer() |
1293625d274d
pullbundle: add an output about the time spent slicing the set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4132
diff
changeset
|
158 msg = _('pullbundle-cache: "missing" set sliced into %d subranges ' |
1293625d274d
pullbundle: add an output about the time spent slicing the set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4132
diff
changeset
|
159 'in %s seconds\n') |
1293625d274d
pullbundle: add an output about the time spent slicing the set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4132
diff
changeset
|
160 repo.ui.write(msg % (len(slices), end - start)) |
1293625d274d
pullbundle: add an output about the time spent slicing the set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4132
diff
changeset
|
161 for sliceid, sliceout in slices: |
4129
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
162 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
|
163 filematcher, cgversions) |
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 # stable range slicing |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
166 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
167 def sliceoutgoing(repo, outgoing): |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
168 cl = repo.changelog |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
169 rev = cl.nodemap.get |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
170 node = cl.node |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
171 revsort = repo.stablesort |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
172 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
173 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
|
174 allslices = [] |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
175 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
|
176 for head in missingheads: |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
177 localslices = [] |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
178 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
|
179 while localmissing: |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
180 slicerevs = [] |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
181 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
|
182 if r not in missingrevs: |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
183 break |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
184 slicerevs.append(r) |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
185 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
|
186 localslices.extend(canonicalslices(repo, slicenodes)) |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
187 missingrevs.difference_update(slicerevs) |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
188 localmissing.difference_update(slicerevs) |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
189 if localmissing: |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
190 head = max(localmissing) |
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 allslices.extend(localslices) |
4136
be3a94d3105f
pullbundle: attempt to save stablerange cache after each computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4135
diff
changeset
|
193 # unknown subrange might had to be computed |
be3a94d3105f
pullbundle: attempt to save stablerange cache after each computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4135
diff
changeset
|
194 repo.stablerange.save(repo) |
4129
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
195 return [(rangeid, outgoingfromnodes(repo, nodes)) |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
196 for rangeid, nodes in allslices] |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
197 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
198 def canonicalslices(repo, nodes): |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
199 depth = repo.depthcache.get |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
200 stablerange = repo.stablerange |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
201 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
|
202 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
|
203 nbrevs = len(nodes) |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
204 headdepth = depth(headrev) |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
205 skipped = headdepth - nbrevs |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
206 rangeid = (headrev, skipped) |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
207 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
208 subranges = canonicalsubranges(repo, stablerange, rangeid) |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
209 idx = 0 |
4130
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
210 slices = [] |
4129
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
211 nodes.reverse() |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
212 for rangeid in subranges: |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
213 size = rangelength(rangeid) |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
214 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
|
215 idx += size |
4138
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
216 ### slow code block to validate ranges content |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
217 # rev = repo.changelog.nodemap.get |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
218 # for ri, ns in slices: |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
219 # a = set(rev(n) for n in ns) |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
220 # b = set(repo.stablerange.revsfromrange(repo, ri)) |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
221 # l = repo.stablerange.rangelength(repo, ri) |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
222 # repo.ui.write('range-length: %d-%d %s %s\n' % (ri[0], ri[1], l, len(a))) |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
223 # if a != b: |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
224 # d = (ri[0], ri[1], b - a, a - b) |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
225 # repo.ui.write("mismatching content: %d-%d -%s +%s\n" % d) |
4129
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
226 return slices |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
227 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
228 def canonicalsubranges(repo, stablerange, rangeid): |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
229 """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
|
230 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
231 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
|
232 range. |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
233 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
234 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
|
235 """ |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
236 headrev, skip = rangeid |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
237 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
|
238 canonicals = [] |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
239 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
240 # 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
|
241 cursor = 1 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
242 while cursor <= rangedepth: |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
243 cursor *= 2 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
244 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
245 # 1. find first cupt |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
246 precut = cut = 0 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
247 while True: |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
248 if skip <= cut: |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
249 break |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
250 if cut + cursor < rangedepth: |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
251 precut = cut |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
252 cut += cursor |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
253 if cursor == 1: |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
254 break |
4130
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
255 cursor //= 2 |
4129
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
256 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
257 # 2. optimise, bottom part |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
258 if skip != cut: |
4138
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
259 currentsize = tailsize = cut - skip |
4129
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
260 assert 0 < tailsize, tailsize |
4138
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
261 |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
262 # we need to take several "standard cut" in the bottom part |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
263 # |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
264 # This is similar to what we will do for the top part, we reusing the |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
265 # existing structure is a bit more complex. |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
266 allcuts = list(reversed(standardcut(tailsize))) |
4129
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
267 prerange = (headrev, precut) |
4138
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
268 ### slow code block to check we operate on the right data |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
269 # rev = repo.changelog.nodemap.get |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
270 # allrevs = [rev(n) for n in nodes] |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
271 # allrevs.reverse() |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
272 # prerevs = repo.stablerange.revsfromrange(repo, prerange) |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
273 # assert allrevs == prerevs[(len(prerevs) - len(allrevs)):] |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
274 # end of check |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
275 sub = list(stablerange.subranges(repo, prerange)[:-1]) |
4129
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
276 |
4138
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
277 bottomranges = [] |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
278 # XXX we might be able to reuse core stable-range logic instead of |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
279 # redoing this manually |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
280 currentrange = sub.pop() |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
281 currentsize = stablerange.rangelength(repo, currentrange) |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
282 currentcut = None |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
283 while allcuts or currentcut is not None: |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
284 # get the next cut if needed |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
285 if currentcut is None: |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
286 currentcut = allcuts.pop() |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
287 # deal attemp a cut |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
288 if currentsize == currentcut: |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
289 bottomranges.append(currentrange) |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
290 currentcut = None |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
291 elif currentsize < currentcut: |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
292 bottomranges.append(currentrange) |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
293 currentcut -= currentsize |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
294 else: # currentsize > currentcut |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
295 newskip = currentrange[1] + (currentsize - currentcut) |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
296 currentsub = stablerange._slicesrangeat(repo, currentrange, newskip) |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
297 bottomranges.append(currentsub.pop()) |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
298 sub.extend(currentsub) |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
299 currentcut = None |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
300 currentrange = sub.pop() |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
301 currentsize = stablerange.rangelength(repo, currentrange) |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
302 bottomranges.reverse() |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
303 canonicals.extend(bottomranges) |
4129
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
304 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
305 # 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
|
306 current = (headrev, cut) |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
307 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
|
308 sub = stablerange.subranges(repo, current) |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
309 canonicals.extend(sub[:-1]) |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
310 current = sub[-1] |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
311 canonicals.append(current) |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
312 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
313 return canonicals |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
314 |
4138
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
315 def standardcut(size): |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
316 assert 0 < size |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
317 # 0. find the first power of 2 higher than this range depth |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
318 cut = 1 |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
319 while cut <= size: |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
320 cut *= 2 |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
321 |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
322 allcuts = [] |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
323 # 1. find all standard expected cut |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
324 while 1 < cut and size: |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
325 cut //= 2 |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
326 if cut <= size: |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
327 allcuts.append(cut) |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
328 size -= cut |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
329 return allcuts |
cfdc6f55599b
pullbundle: improve slicing of the lower part of range
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4136
diff
changeset
|
330 |
4129
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
331 def poweroftwo(num): |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
332 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
|
333 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
334 def outgoingfromnodes(repo, nodes): |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
335 return discovery.outgoing(repo, |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
336 missingroots=nodes, |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
337 missingheads=nodes) |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
338 |
bc4e62a1cb82
pullbundle: slice pull into multiple ranges
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4128
diff
changeset
|
339 # changegroup part construction |
4128
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
340 |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
341 def _changegroupinfo(repo, nodes, source): |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
342 if repo.ui.verbose or source == 'bundle': |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
343 repo.ui.status(_("%d changesets found\n") % len(nodes)) |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
344 |
4130
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
345 def _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): |
4128
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
347 old = changegroup._changegroupinfo |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
348 try: |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
349 changegroup._changegroupinfo = _changegroupinfo |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
350 cgstream = changegroup.makestream(repo, outgoing, version, source, |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
351 bundlecaps=bundlecaps, |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
352 filematcher=filematcher) |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
353 finally: |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
354 changegroup._changegroupinfo = old |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
355 |
4130
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
356 nbchanges = len(outgoing.missing) |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
357 pversion = None |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
358 if cgversions: |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
359 pversion = version |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
360 return (cgstream, nbchanges, pversion) |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
361 |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
362 def _makepartfromstream(newpart, repo, cgstream, nbchanges, version): |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
363 # same as upstream code |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
364 |
4128
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
365 part = newpart('changegroup', data=cgstream) |
4130
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
366 if version: |
4128
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
367 part.addparam('version', version) |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
368 |
4130
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
369 part.addparam('nbchanges', '%d' % nbchanges, |
4128
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
370 mandatory=False) |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
371 |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
372 if 'treemanifest' in repo.requirements: |
4e5ec9ae682e
pullbundle: initial commit
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
373 part.addparam('treemanifest', '1') |
4130
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
374 |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
375 # cache management |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
376 |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
377 def cachedir(repo): |
4134
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
378 cachedir = repo.ui.config('pullbundle', 'cache-directory') |
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
379 if cachedir is not None: |
ab77f37fedf3
pullbundle: add a config option for the cache directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4133
diff
changeset
|
380 return cachedir |
4130
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
381 return repo.cachevfs.join('pullbundles') |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
382 |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
383 def getcache(repo, bundlename): |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
384 cdir = cachedir(repo) |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
385 bundlepath = os.path.join(cdir, bundlename) |
4139
2bd652bece97
pullbundle: delay cache file opening
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4138
diff
changeset
|
386 if not os.path.exists(bundlepath): |
4130
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
387 return None |
4139
2bd652bece97
pullbundle: delay cache file opening
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4138
diff
changeset
|
388 # delay file opening as much as possible this introduce a small race |
2bd652bece97
pullbundle: delay cache file opening
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4138
diff
changeset
|
389 # condition if someone remove the file before we actually use it. However |
2bd652bece97
pullbundle: delay cache file opening
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4138
diff
changeset
|
390 # opening too many file will not work. |
2bd652bece97
pullbundle: delay cache file opening
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4138
diff
changeset
|
391 |
2bd652bece97
pullbundle: delay cache file opening
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4138
diff
changeset
|
392 def data(): |
2bd652bece97
pullbundle: delay cache file opening
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4138
diff
changeset
|
393 with open(bundlepath, 'rb') as fd: |
2bd652bece97
pullbundle: delay cache file opening
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4138
diff
changeset
|
394 for chunk in util.filechunkiter(fd): |
2bd652bece97
pullbundle: delay cache file opening
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4138
diff
changeset
|
395 yield chunk |
2bd652bece97
pullbundle: delay cache file opening
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4138
diff
changeset
|
396 return data() |
4130
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
397 |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
398 def cachewriter(repo, bundlename, stream): |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
399 cdir = cachedir(repo) |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
400 bundlepath = os.path.join(cdir, bundlename) |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
401 try: |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
402 os.makedirs(cdir) |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
403 except OSError as exc: |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
404 if exc.errno == errno.EEXIST: |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
405 pass |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
406 with util.atomictempfile(bundlepath) as cachefile: |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
407 for chunk in stream: |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
408 cachefile.write(chunk) |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
409 yield chunk |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
410 |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
411 BUNDLEMASK = "%s-%s-%010iskip-%010isize.hg" |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
412 |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
413 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
|
414 bundlecaps, filematcher, cgversions): |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
415 bundlename = cachedata = None |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
416 if rangeid is not None: |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
417 nbchanges = repo.stablerange.rangelength(repo, rangeid) |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
418 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
|
419 # 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
|
420 bundlename = BUNDLEMASK % (version, headnode, rangeid[1], nbchanges) |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
421 cachedata = getcache(repo, bundlename) |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
422 if cachedata is None: |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
423 partdata = _makenewstream(newpart, repo, outgoing, version, source, |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
424 bundlecaps, filematcher, cgversions) |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
425 if bundlename is not None: |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
426 cgstream = cachewriter(repo, bundlename, partdata[0]) |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
427 partdata = (cgstream,) + partdata[1:] |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
428 else: |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
429 if repo.ui.verbose or source == 'bundle': |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
430 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
|
431 pversion = None |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
432 if cgversions: |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
433 pversion = version |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
434 partdata = (cachedata, nbchanges, pversion) |
a1f6b8211016
pullbundle: add caching logic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
4129
diff
changeset
|
435 return _makepartfromstream(newpart, repo, *partdata) |