Show More
@@ -1,475 +1,473 b'' | |||||
1 | # bundlerepo.py - repository class for viewing uncompressed bundles |
|
1 | # bundlerepo.py - repository class for viewing uncompressed bundles | |
2 | # |
|
2 | # | |
3 | # Copyright 2006, 2007 Benoit Boissinot <bboissin@gmail.com> |
|
3 | # Copyright 2006, 2007 Benoit Boissinot <bboissin@gmail.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | """Repository class for viewing uncompressed bundles. |
|
8 | """Repository class for viewing uncompressed bundles. | |
9 |
|
9 | |||
10 | This provides a read-only repository interface to bundles as if they |
|
10 | This provides a read-only repository interface to bundles as if they | |
11 | were part of the actual repository. |
|
11 | were part of the actual repository. | |
12 | """ |
|
12 | """ | |
13 |
|
13 | |||
14 | from node import nullid |
|
14 | from node import nullid | |
15 | from i18n import _ |
|
15 | from i18n import _ | |
16 | import os, tempfile, shutil |
|
16 | import os, tempfile, shutil | |
17 | import changegroup, util, mdiff, discovery, cmdutil, scmutil, exchange |
|
17 | import changegroup, util, mdiff, discovery, cmdutil, scmutil, exchange | |
18 | import localrepo, changelog, manifest, filelog, revlog, error, phases, bundle2 |
|
18 | import localrepo, changelog, manifest, filelog, revlog, error, phases, bundle2 | |
19 | import pathutil |
|
19 | import pathutil | |
20 |
|
20 | |||
21 | class bundlerevlog(revlog.revlog): |
|
21 | class bundlerevlog(revlog.revlog): | |
22 | def __init__(self, opener, indexfile, bundle, linkmapper): |
|
22 | def __init__(self, opener, indexfile, bundle, linkmapper): | |
23 | # How it works: |
|
23 | # How it works: | |
24 | # To retrieve a revision, we need to know the offset of the revision in |
|
24 | # To retrieve a revision, we need to know the offset of the revision in | |
25 | # the bundle (an unbundle object). We store this offset in the index |
|
25 | # the bundle (an unbundle object). We store this offset in the index | |
26 | # (start). The base of the delta is stored in the base field. |
|
26 | # (start). The base of the delta is stored in the base field. | |
27 | # |
|
27 | # | |
28 | # To differentiate a rev in the bundle from a rev in the revlog, we |
|
28 | # To differentiate a rev in the bundle from a rev in the revlog, we | |
29 | # check revision against repotiprev. |
|
29 | # check revision against repotiprev. | |
30 | opener = scmutil.readonlyvfs(opener) |
|
30 | opener = scmutil.readonlyvfs(opener) | |
31 | revlog.revlog.__init__(self, opener, indexfile) |
|
31 | revlog.revlog.__init__(self, opener, indexfile) | |
32 | self.bundle = bundle |
|
32 | self.bundle = bundle | |
33 | n = len(self) |
|
33 | n = len(self) | |
34 | self.repotiprev = n - 1 |
|
34 | self.repotiprev = n - 1 | |
35 | chain = None |
|
35 | chain = None | |
36 | self.bundlerevs = set() # used by 'bundle()' revset expression |
|
36 | self.bundlerevs = set() # used by 'bundle()' revset expression | |
37 | while True: |
|
37 | while True: | |
38 | chunkdata = bundle.deltachunk(chain) |
|
38 | chunkdata = bundle.deltachunk(chain) | |
39 | if not chunkdata: |
|
39 | if not chunkdata: | |
40 | break |
|
40 | break | |
41 | node = chunkdata['node'] |
|
41 | node = chunkdata['node'] | |
42 | p1 = chunkdata['p1'] |
|
42 | p1 = chunkdata['p1'] | |
43 | p2 = chunkdata['p2'] |
|
43 | p2 = chunkdata['p2'] | |
44 | cs = chunkdata['cs'] |
|
44 | cs = chunkdata['cs'] | |
45 | deltabase = chunkdata['deltabase'] |
|
45 | deltabase = chunkdata['deltabase'] | |
46 | delta = chunkdata['delta'] |
|
46 | delta = chunkdata['delta'] | |
47 |
|
47 | |||
48 | size = len(delta) |
|
48 | size = len(delta) | |
49 | start = bundle.tell() - size |
|
49 | start = bundle.tell() - size | |
50 |
|
50 | |||
51 | link = linkmapper(cs) |
|
51 | link = linkmapper(cs) | |
52 | if node in self.nodemap: |
|
52 | if node in self.nodemap: | |
53 | # this can happen if two branches make the same change |
|
53 | # this can happen if two branches make the same change | |
54 | chain = node |
|
54 | chain = node | |
55 | self.bundlerevs.add(self.nodemap[node]) |
|
55 | self.bundlerevs.add(self.nodemap[node]) | |
56 | continue |
|
56 | continue | |
57 |
|
57 | |||
58 | for p in (p1, p2): |
|
58 | for p in (p1, p2): | |
59 | if p not in self.nodemap: |
|
59 | if p not in self.nodemap: | |
60 | raise error.LookupError(p, self.indexfile, |
|
60 | raise error.LookupError(p, self.indexfile, | |
61 | _("unknown parent")) |
|
61 | _("unknown parent")) | |
62 |
|
62 | |||
63 | if deltabase not in self.nodemap: |
|
63 | if deltabase not in self.nodemap: | |
64 | raise LookupError(deltabase, self.indexfile, |
|
64 | raise LookupError(deltabase, self.indexfile, | |
65 | _('unknown delta base')) |
|
65 | _('unknown delta base')) | |
66 |
|
66 | |||
67 | baserev = self.rev(deltabase) |
|
67 | baserev = self.rev(deltabase) | |
68 | # start, size, full unc. size, base (unused), link, p1, p2, node |
|
68 | # start, size, full unc. size, base (unused), link, p1, p2, node | |
69 | e = (revlog.offset_type(start, 0), size, -1, baserev, link, |
|
69 | e = (revlog.offset_type(start, 0), size, -1, baserev, link, | |
70 | self.rev(p1), self.rev(p2), node) |
|
70 | self.rev(p1), self.rev(p2), node) | |
71 | self.index.insert(-1, e) |
|
71 | self.index.insert(-1, e) | |
72 | self.nodemap[node] = n |
|
72 | self.nodemap[node] = n | |
73 | self.bundlerevs.add(n) |
|
73 | self.bundlerevs.add(n) | |
74 | chain = node |
|
74 | chain = node | |
75 | n += 1 |
|
75 | n += 1 | |
76 |
|
76 | |||
77 | def _chunk(self, rev): |
|
77 | def _chunk(self, rev): | |
78 | # Warning: in case of bundle, the diff is against what we stored as |
|
78 | # Warning: in case of bundle, the diff is against what we stored as | |
79 | # delta base, not against rev - 1 |
|
79 | # delta base, not against rev - 1 | |
80 | # XXX: could use some caching |
|
80 | # XXX: could use some caching | |
81 | if rev <= self.repotiprev: |
|
81 | if rev <= self.repotiprev: | |
82 | return revlog.revlog._chunk(self, rev) |
|
82 | return revlog.revlog._chunk(self, rev) | |
83 | self.bundle.seek(self.start(rev)) |
|
83 | self.bundle.seek(self.start(rev)) | |
84 | return self.bundle.read(self.length(rev)) |
|
84 | return self.bundle.read(self.length(rev)) | |
85 |
|
85 | |||
86 | def revdiff(self, rev1, rev2): |
|
86 | def revdiff(self, rev1, rev2): | |
87 | """return or calculate a delta between two revisions""" |
|
87 | """return or calculate a delta between two revisions""" | |
88 | if rev1 > self.repotiprev and rev2 > self.repotiprev: |
|
88 | if rev1 > self.repotiprev and rev2 > self.repotiprev: | |
89 | # hot path for bundle |
|
89 | # hot path for bundle | |
90 | revb = self.index[rev2][3] |
|
90 | revb = self.index[rev2][3] | |
91 | if revb == rev1: |
|
91 | if revb == rev1: | |
92 | return self._chunk(rev2) |
|
92 | return self._chunk(rev2) | |
93 | elif rev1 <= self.repotiprev and rev2 <= self.repotiprev: |
|
93 | elif rev1 <= self.repotiprev and rev2 <= self.repotiprev: | |
94 | return revlog.revlog.revdiff(self, rev1, rev2) |
|
94 | return revlog.revlog.revdiff(self, rev1, rev2) | |
95 |
|
95 | |||
96 | return mdiff.textdiff(self.revision(self.node(rev1)), |
|
96 | return mdiff.textdiff(self.revision(self.node(rev1)), | |
97 | self.revision(self.node(rev2))) |
|
97 | self.revision(self.node(rev2))) | |
98 |
|
98 | |||
99 | def revision(self, nodeorrev): |
|
99 | def revision(self, nodeorrev): | |
100 | """return an uncompressed revision of a given node or revision |
|
100 | """return an uncompressed revision of a given node or revision | |
101 | number. |
|
101 | number. | |
102 | """ |
|
102 | """ | |
103 | if isinstance(nodeorrev, int): |
|
103 | if isinstance(nodeorrev, int): | |
104 | rev = nodeorrev |
|
104 | rev = nodeorrev | |
105 | node = self.node(rev) |
|
105 | node = self.node(rev) | |
106 | else: |
|
106 | else: | |
107 | node = nodeorrev |
|
107 | node = nodeorrev | |
108 | rev = self.rev(node) |
|
108 | rev = self.rev(node) | |
109 |
|
109 | |||
110 | if node == nullid: |
|
110 | if node == nullid: | |
111 | return "" |
|
111 | return "" | |
112 |
|
112 | |||
113 | text = None |
|
113 | text = None | |
114 | chain = [] |
|
114 | chain = [] | |
115 | iterrev = rev |
|
115 | iterrev = rev | |
116 | # reconstruct the revision if it is from a changegroup |
|
116 | # reconstruct the revision if it is from a changegroup | |
117 | while iterrev > self.repotiprev: |
|
117 | while iterrev > self.repotiprev: | |
118 | if self._cache and self._cache[1] == iterrev: |
|
118 | if self._cache and self._cache[1] == iterrev: | |
119 | text = self._cache[2] |
|
119 | text = self._cache[2] | |
120 | break |
|
120 | break | |
121 | chain.append(iterrev) |
|
121 | chain.append(iterrev) | |
122 | iterrev = self.index[iterrev][3] |
|
122 | iterrev = self.index[iterrev][3] | |
123 | if text is None: |
|
123 | if text is None: | |
124 | text = self.baserevision(iterrev) |
|
124 | text = self.baserevision(iterrev) | |
125 |
|
125 | |||
126 | while chain: |
|
126 | while chain: | |
127 | delta = self._chunk(chain.pop()) |
|
127 | delta = self._chunk(chain.pop()) | |
128 | text = mdiff.patches(text, [delta]) |
|
128 | text = mdiff.patches(text, [delta]) | |
129 |
|
129 | |||
130 | self._checkhash(text, node, rev) |
|
130 | self._checkhash(text, node, rev) | |
131 | self._cache = (node, rev, text) |
|
131 | self._cache = (node, rev, text) | |
132 | return text |
|
132 | return text | |
133 |
|
133 | |||
134 | def baserevision(self, nodeorrev): |
|
134 | def baserevision(self, nodeorrev): | |
135 | # Revlog subclasses may override 'revision' method to modify format of |
|
135 | # Revlog subclasses may override 'revision' method to modify format of | |
136 | # content retrieved from revlog. To use bundlerevlog with such class one |
|
136 | # content retrieved from revlog. To use bundlerevlog with such class one | |
137 | # needs to override 'baserevision' and make more specific call here. |
|
137 | # needs to override 'baserevision' and make more specific call here. | |
138 | return revlog.revlog.revision(self, nodeorrev) |
|
138 | return revlog.revlog.revision(self, nodeorrev) | |
139 |
|
139 | |||
140 | def addrevision(self, text, transaction, link, p1=None, p2=None, d=None): |
|
140 | def addrevision(self, text, transaction, link, p1=None, p2=None, d=None): | |
141 | raise NotImplementedError |
|
141 | raise NotImplementedError | |
142 | def addgroup(self, revs, linkmapper, transaction): |
|
142 | def addgroup(self, revs, linkmapper, transaction): | |
143 | raise NotImplementedError |
|
143 | raise NotImplementedError | |
144 | def strip(self, rev, minlink): |
|
144 | def strip(self, rev, minlink): | |
145 | raise NotImplementedError |
|
145 | raise NotImplementedError | |
146 | def checksize(self): |
|
146 | def checksize(self): | |
147 | raise NotImplementedError |
|
147 | raise NotImplementedError | |
148 |
|
148 | |||
149 | class bundlechangelog(bundlerevlog, changelog.changelog): |
|
149 | class bundlechangelog(bundlerevlog, changelog.changelog): | |
150 | def __init__(self, opener, bundle): |
|
150 | def __init__(self, opener, bundle): | |
151 | changelog.changelog.__init__(self, opener) |
|
151 | changelog.changelog.__init__(self, opener) | |
152 | linkmapper = lambda x: x |
|
152 | linkmapper = lambda x: x | |
153 | bundlerevlog.__init__(self, opener, self.indexfile, bundle, |
|
153 | bundlerevlog.__init__(self, opener, self.indexfile, bundle, | |
154 | linkmapper) |
|
154 | linkmapper) | |
155 |
|
155 | |||
156 | def baserevision(self, nodeorrev): |
|
156 | def baserevision(self, nodeorrev): | |
157 | # Although changelog doesn't override 'revision' method, some extensions |
|
157 | # Although changelog doesn't override 'revision' method, some extensions | |
158 | # may replace this class with another that does. Same story with |
|
158 | # may replace this class with another that does. Same story with | |
159 | # manifest and filelog classes. |
|
159 | # manifest and filelog classes. | |
160 |
|
160 | |||
161 | # This bypasses filtering on changelog.node() and rev() because we need |
|
161 | # This bypasses filtering on changelog.node() and rev() because we need | |
162 | # revision text of the bundle base even if it is hidden. |
|
162 | # revision text of the bundle base even if it is hidden. | |
163 | oldfilter = self.filteredrevs |
|
163 | oldfilter = self.filteredrevs | |
164 | try: |
|
164 | try: | |
165 | self.filteredrevs = () |
|
165 | self.filteredrevs = () | |
166 | return changelog.changelog.revision(self, nodeorrev) |
|
166 | return changelog.changelog.revision(self, nodeorrev) | |
167 | finally: |
|
167 | finally: | |
168 | self.filteredrevs = oldfilter |
|
168 | self.filteredrevs = oldfilter | |
169 |
|
169 | |||
170 | class bundlemanifest(bundlerevlog, manifest.manifest): |
|
170 | class bundlemanifest(bundlerevlog, manifest.manifest): | |
171 | def __init__(self, opener, bundle, linkmapper): |
|
171 | def __init__(self, opener, bundle, linkmapper): | |
172 | manifest.manifest.__init__(self, opener) |
|
172 | manifest.manifest.__init__(self, opener) | |
173 | bundlerevlog.__init__(self, opener, self.indexfile, bundle, |
|
173 | bundlerevlog.__init__(self, opener, self.indexfile, bundle, | |
174 | linkmapper) |
|
174 | linkmapper) | |
175 |
|
175 | |||
176 | def baserevision(self, nodeorrev): |
|
176 | def baserevision(self, nodeorrev): | |
177 | return manifest.manifest.revision(self, nodeorrev) |
|
177 | return manifest.manifest.revision(self, nodeorrev) | |
178 |
|
178 | |||
179 | class bundlefilelog(bundlerevlog, filelog.filelog): |
|
179 | class bundlefilelog(bundlerevlog, filelog.filelog): | |
180 |
def __init__(self, opener, path, bundle, linkmapper |
|
180 | def __init__(self, opener, path, bundle, linkmapper): | |
181 | filelog.filelog.__init__(self, opener, path) |
|
181 | filelog.filelog.__init__(self, opener, path) | |
182 | bundlerevlog.__init__(self, opener, self.indexfile, bundle, |
|
182 | bundlerevlog.__init__(self, opener, self.indexfile, bundle, | |
183 | linkmapper) |
|
183 | linkmapper) | |
184 | self._repo = repo |
|
|||
185 |
|
184 | |||
186 | def baserevision(self, nodeorrev): |
|
185 | def baserevision(self, nodeorrev): | |
187 | return filelog.filelog.revision(self, nodeorrev) |
|
186 | return filelog.filelog.revision(self, nodeorrev) | |
188 |
|
187 | |||
189 | class bundlepeer(localrepo.localpeer): |
|
188 | class bundlepeer(localrepo.localpeer): | |
190 | def canpush(self): |
|
189 | def canpush(self): | |
191 | return False |
|
190 | return False | |
192 |
|
191 | |||
193 | class bundlephasecache(phases.phasecache): |
|
192 | class bundlephasecache(phases.phasecache): | |
194 | def __init__(self, *args, **kwargs): |
|
193 | def __init__(self, *args, **kwargs): | |
195 | super(bundlephasecache, self).__init__(*args, **kwargs) |
|
194 | super(bundlephasecache, self).__init__(*args, **kwargs) | |
196 | if util.safehasattr(self, 'opener'): |
|
195 | if util.safehasattr(self, 'opener'): | |
197 | self.opener = scmutil.readonlyvfs(self.opener) |
|
196 | self.opener = scmutil.readonlyvfs(self.opener) | |
198 |
|
197 | |||
199 | def write(self): |
|
198 | def write(self): | |
200 | raise NotImplementedError |
|
199 | raise NotImplementedError | |
201 |
|
200 | |||
202 | def _write(self, fp): |
|
201 | def _write(self, fp): | |
203 | raise NotImplementedError |
|
202 | raise NotImplementedError | |
204 |
|
203 | |||
205 | def _updateroots(self, phase, newroots, tr): |
|
204 | def _updateroots(self, phase, newroots, tr): | |
206 | self.phaseroots[phase] = newroots |
|
205 | self.phaseroots[phase] = newroots | |
207 | self.invalidate() |
|
206 | self.invalidate() | |
208 | self.dirty = True |
|
207 | self.dirty = True | |
209 |
|
208 | |||
210 | class bundlerepository(localrepo.localrepository): |
|
209 | class bundlerepository(localrepo.localrepository): | |
211 | def __init__(self, ui, path, bundlename): |
|
210 | def __init__(self, ui, path, bundlename): | |
212 | self._tempparent = None |
|
211 | self._tempparent = None | |
213 | try: |
|
212 | try: | |
214 | localrepo.localrepository.__init__(self, ui, path) |
|
213 | localrepo.localrepository.__init__(self, ui, path) | |
215 | except error.RepoError: |
|
214 | except error.RepoError: | |
216 | self._tempparent = tempfile.mkdtemp() |
|
215 | self._tempparent = tempfile.mkdtemp() | |
217 | localrepo.instance(ui, self._tempparent, 1) |
|
216 | localrepo.instance(ui, self._tempparent, 1) | |
218 | localrepo.localrepository.__init__(self, ui, self._tempparent) |
|
217 | localrepo.localrepository.__init__(self, ui, self._tempparent) | |
219 | self.ui.setconfig('phases', 'publish', False, 'bundlerepo') |
|
218 | self.ui.setconfig('phases', 'publish', False, 'bundlerepo') | |
220 |
|
219 | |||
221 | if path: |
|
220 | if path: | |
222 | self._url = 'bundle:' + util.expandpath(path) + '+' + bundlename |
|
221 | self._url = 'bundle:' + util.expandpath(path) + '+' + bundlename | |
223 | else: |
|
222 | else: | |
224 | self._url = 'bundle:' + bundlename |
|
223 | self._url = 'bundle:' + bundlename | |
225 |
|
224 | |||
226 | self.tempfile = None |
|
225 | self.tempfile = None | |
227 | f = util.posixfile(bundlename, "rb") |
|
226 | f = util.posixfile(bundlename, "rb") | |
228 | self.bundlefile = self.bundle = exchange.readbundle(ui, f, bundlename) |
|
227 | self.bundlefile = self.bundle = exchange.readbundle(ui, f, bundlename) | |
229 | if self.bundle.compressed(): |
|
228 | if self.bundle.compressed(): | |
230 | fdtemp, temp = self.vfs.mkstemp(prefix="hg-bundle-", |
|
229 | fdtemp, temp = self.vfs.mkstemp(prefix="hg-bundle-", | |
231 | suffix=".hg10un") |
|
230 | suffix=".hg10un") | |
232 | self.tempfile = temp |
|
231 | self.tempfile = temp | |
233 | fptemp = os.fdopen(fdtemp, 'wb') |
|
232 | fptemp = os.fdopen(fdtemp, 'wb') | |
234 |
|
233 | |||
235 | try: |
|
234 | try: | |
236 | fptemp.write("HG10UN") |
|
235 | fptemp.write("HG10UN") | |
237 | while True: |
|
236 | while True: | |
238 | chunk = self.bundle.read(2**18) |
|
237 | chunk = self.bundle.read(2**18) | |
239 | if not chunk: |
|
238 | if not chunk: | |
240 | break |
|
239 | break | |
241 | fptemp.write(chunk) |
|
240 | fptemp.write(chunk) | |
242 | finally: |
|
241 | finally: | |
243 | fptemp.close() |
|
242 | fptemp.close() | |
244 |
|
243 | |||
245 | f = self.vfs.open(self.tempfile, mode="rb") |
|
244 | f = self.vfs.open(self.tempfile, mode="rb") | |
246 | self.bundlefile = self.bundle = exchange.readbundle(ui, f, |
|
245 | self.bundlefile = self.bundle = exchange.readbundle(ui, f, | |
247 | bundlename, |
|
246 | bundlename, | |
248 | self.vfs) |
|
247 | self.vfs) | |
249 |
|
248 | |||
250 | if isinstance(self.bundle, bundle2.unbundle20): |
|
249 | if isinstance(self.bundle, bundle2.unbundle20): | |
251 | cgparts = [part for part in self.bundle.iterparts() |
|
250 | cgparts = [part for part in self.bundle.iterparts() | |
252 | if (part.type == 'changegroup') |
|
251 | if (part.type == 'changegroup') | |
253 | and (part.params.get('version', '01') |
|
252 | and (part.params.get('version', '01') | |
254 | in changegroup.packermap)] |
|
253 | in changegroup.packermap)] | |
255 |
|
254 | |||
256 | if not cgparts: |
|
255 | if not cgparts: | |
257 | raise util.Abort('No changegroups found') |
|
256 | raise util.Abort('No changegroups found') | |
258 | version = cgparts[0].params.get('version', '01') |
|
257 | version = cgparts[0].params.get('version', '01') | |
259 | cgparts = [p for p in cgparts |
|
258 | cgparts = [p for p in cgparts | |
260 | if p.params.get('version', '01') == version] |
|
259 | if p.params.get('version', '01') == version] | |
261 | if len(cgparts) > 1: |
|
260 | if len(cgparts) > 1: | |
262 | raise NotImplementedError("Can't process multiple changegroups") |
|
261 | raise NotImplementedError("Can't process multiple changegroups") | |
263 | part = cgparts[0] |
|
262 | part = cgparts[0] | |
264 |
|
263 | |||
265 | part.seek(0) |
|
264 | part.seek(0) | |
266 | self.bundle = changegroup.packermap[version][1](part, 'UN') |
|
265 | self.bundle = changegroup.packermap[version][1](part, 'UN') | |
267 |
|
266 | |||
268 | # dict with the mapping 'filename' -> position in the bundle |
|
267 | # dict with the mapping 'filename' -> position in the bundle | |
269 | self.bundlefilespos = {} |
|
268 | self.bundlefilespos = {} | |
270 |
|
269 | |||
271 | self.firstnewrev = self.changelog.repotiprev + 1 |
|
270 | self.firstnewrev = self.changelog.repotiprev + 1 | |
272 | phases.retractboundary(self, None, phases.draft, |
|
271 | phases.retractboundary(self, None, phases.draft, | |
273 | [ctx.node() for ctx in self[self.firstnewrev:]]) |
|
272 | [ctx.node() for ctx in self[self.firstnewrev:]]) | |
274 |
|
273 | |||
275 | @localrepo.unfilteredpropertycache |
|
274 | @localrepo.unfilteredpropertycache | |
276 | def _phasecache(self): |
|
275 | def _phasecache(self): | |
277 | return bundlephasecache(self, self._phasedefaults) |
|
276 | return bundlephasecache(self, self._phasedefaults) | |
278 |
|
277 | |||
279 | @localrepo.unfilteredpropertycache |
|
278 | @localrepo.unfilteredpropertycache | |
280 | def changelog(self): |
|
279 | def changelog(self): | |
281 | # consume the header if it exists |
|
280 | # consume the header if it exists | |
282 | self.bundle.changelogheader() |
|
281 | self.bundle.changelogheader() | |
283 | c = bundlechangelog(self.svfs, self.bundle) |
|
282 | c = bundlechangelog(self.svfs, self.bundle) | |
284 | self.manstart = self.bundle.tell() |
|
283 | self.manstart = self.bundle.tell() | |
285 | return c |
|
284 | return c | |
286 |
|
285 | |||
287 | @localrepo.unfilteredpropertycache |
|
286 | @localrepo.unfilteredpropertycache | |
288 | def manifest(self): |
|
287 | def manifest(self): | |
289 | self.bundle.seek(self.manstart) |
|
288 | self.bundle.seek(self.manstart) | |
290 | # consume the header if it exists |
|
289 | # consume the header if it exists | |
291 | self.bundle.manifestheader() |
|
290 | self.bundle.manifestheader() | |
292 | m = bundlemanifest(self.svfs, self.bundle, self.changelog.rev) |
|
291 | m = bundlemanifest(self.svfs, self.bundle, self.changelog.rev) | |
293 | self.filestart = self.bundle.tell() |
|
292 | self.filestart = self.bundle.tell() | |
294 | return m |
|
293 | return m | |
295 |
|
294 | |||
296 | @localrepo.unfilteredpropertycache |
|
295 | @localrepo.unfilteredpropertycache | |
297 | def manstart(self): |
|
296 | def manstart(self): | |
298 | self.changelog |
|
297 | self.changelog | |
299 | return self.manstart |
|
298 | return self.manstart | |
300 |
|
299 | |||
301 | @localrepo.unfilteredpropertycache |
|
300 | @localrepo.unfilteredpropertycache | |
302 | def filestart(self): |
|
301 | def filestart(self): | |
303 | self.manifest |
|
302 | self.manifest | |
304 | return self.filestart |
|
303 | return self.filestart | |
305 |
|
304 | |||
306 | def url(self): |
|
305 | def url(self): | |
307 | return self._url |
|
306 | return self._url | |
308 |
|
307 | |||
309 | def file(self, f): |
|
308 | def file(self, f): | |
310 | if not self.bundlefilespos: |
|
309 | if not self.bundlefilespos: | |
311 | self.bundle.seek(self.filestart) |
|
310 | self.bundle.seek(self.filestart) | |
312 | while True: |
|
311 | while True: | |
313 | chunkdata = self.bundle.filelogheader() |
|
312 | chunkdata = self.bundle.filelogheader() | |
314 | if not chunkdata: |
|
313 | if not chunkdata: | |
315 | break |
|
314 | break | |
316 | fname = chunkdata['filename'] |
|
315 | fname = chunkdata['filename'] | |
317 | self.bundlefilespos[fname] = self.bundle.tell() |
|
316 | self.bundlefilespos[fname] = self.bundle.tell() | |
318 | while True: |
|
317 | while True: | |
319 | c = self.bundle.deltachunk(None) |
|
318 | c = self.bundle.deltachunk(None) | |
320 | if not c: |
|
319 | if not c: | |
321 | break |
|
320 | break | |
322 |
|
321 | |||
323 | if f in self.bundlefilespos: |
|
322 | if f in self.bundlefilespos: | |
324 | self.bundle.seek(self.bundlefilespos[f]) |
|
323 | self.bundle.seek(self.bundlefilespos[f]) | |
325 | return bundlefilelog(self.svfs, f, self.bundle, |
|
324 | return bundlefilelog(self.svfs, f, self.bundle, self.changelog.rev) | |
326 | self.changelog.rev, self) |
|
|||
327 | else: |
|
325 | else: | |
328 | return filelog.filelog(self.svfs, f) |
|
326 | return filelog.filelog(self.svfs, f) | |
329 |
|
327 | |||
330 | def close(self): |
|
328 | def close(self): | |
331 | """Close assigned bundle file immediately.""" |
|
329 | """Close assigned bundle file immediately.""" | |
332 | self.bundlefile.close() |
|
330 | self.bundlefile.close() | |
333 | if self.tempfile is not None: |
|
331 | if self.tempfile is not None: | |
334 | self.vfs.unlink(self.tempfile) |
|
332 | self.vfs.unlink(self.tempfile) | |
335 | if self._tempparent: |
|
333 | if self._tempparent: | |
336 | shutil.rmtree(self._tempparent, True) |
|
334 | shutil.rmtree(self._tempparent, True) | |
337 |
|
335 | |||
338 | def cancopy(self): |
|
336 | def cancopy(self): | |
339 | return False |
|
337 | return False | |
340 |
|
338 | |||
341 | def peer(self): |
|
339 | def peer(self): | |
342 | return bundlepeer(self) |
|
340 | return bundlepeer(self) | |
343 |
|
341 | |||
344 | def getcwd(self): |
|
342 | def getcwd(self): | |
345 | return os.getcwd() # always outside the repo |
|
343 | return os.getcwd() # always outside the repo | |
346 |
|
344 | |||
347 |
|
345 | |||
348 | def instance(ui, path, create): |
|
346 | def instance(ui, path, create): | |
349 | if create: |
|
347 | if create: | |
350 | raise util.Abort(_('cannot create new bundle repository')) |
|
348 | raise util.Abort(_('cannot create new bundle repository')) | |
351 | parentpath = ui.config("bundle", "mainreporoot", "") |
|
349 | parentpath = ui.config("bundle", "mainreporoot", "") | |
352 | if not parentpath: |
|
350 | if not parentpath: | |
353 | # try to find the correct path to the working directory repo |
|
351 | # try to find the correct path to the working directory repo | |
354 | parentpath = cmdutil.findrepo(os.getcwd()) |
|
352 | parentpath = cmdutil.findrepo(os.getcwd()) | |
355 | if parentpath is None: |
|
353 | if parentpath is None: | |
356 | parentpath = '' |
|
354 | parentpath = '' | |
357 | if parentpath: |
|
355 | if parentpath: | |
358 | # Try to make the full path relative so we get a nice, short URL. |
|
356 | # Try to make the full path relative so we get a nice, short URL. | |
359 | # In particular, we don't want temp dir names in test outputs. |
|
357 | # In particular, we don't want temp dir names in test outputs. | |
360 | cwd = os.getcwd() |
|
358 | cwd = os.getcwd() | |
361 | if parentpath == cwd: |
|
359 | if parentpath == cwd: | |
362 | parentpath = '' |
|
360 | parentpath = '' | |
363 | else: |
|
361 | else: | |
364 | cwd = pathutil.normasprefix(cwd) |
|
362 | cwd = pathutil.normasprefix(cwd) | |
365 | if parentpath.startswith(cwd): |
|
363 | if parentpath.startswith(cwd): | |
366 | parentpath = parentpath[len(cwd):] |
|
364 | parentpath = parentpath[len(cwd):] | |
367 | u = util.url(path) |
|
365 | u = util.url(path) | |
368 | path = u.localpath() |
|
366 | path = u.localpath() | |
369 | if u.scheme == 'bundle': |
|
367 | if u.scheme == 'bundle': | |
370 | s = path.split("+", 1) |
|
368 | s = path.split("+", 1) | |
371 | if len(s) == 1: |
|
369 | if len(s) == 1: | |
372 | repopath, bundlename = parentpath, s[0] |
|
370 | repopath, bundlename = parentpath, s[0] | |
373 | else: |
|
371 | else: | |
374 | repopath, bundlename = s |
|
372 | repopath, bundlename = s | |
375 | else: |
|
373 | else: | |
376 | repopath, bundlename = parentpath, path |
|
374 | repopath, bundlename = parentpath, path | |
377 | return bundlerepository(ui, repopath, bundlename) |
|
375 | return bundlerepository(ui, repopath, bundlename) | |
378 |
|
376 | |||
379 | class bundletransactionmanager(object): |
|
377 | class bundletransactionmanager(object): | |
380 | def transaction(self): |
|
378 | def transaction(self): | |
381 | return None |
|
379 | return None | |
382 |
|
380 | |||
383 | def close(self): |
|
381 | def close(self): | |
384 | raise NotImplementedError |
|
382 | raise NotImplementedError | |
385 |
|
383 | |||
386 | def release(self): |
|
384 | def release(self): | |
387 | raise NotImplementedError |
|
385 | raise NotImplementedError | |
388 |
|
386 | |||
389 | def getremotechanges(ui, repo, other, onlyheads=None, bundlename=None, |
|
387 | def getremotechanges(ui, repo, other, onlyheads=None, bundlename=None, | |
390 | force=False): |
|
388 | force=False): | |
391 | '''obtains a bundle of changes incoming from other |
|
389 | '''obtains a bundle of changes incoming from other | |
392 |
|
390 | |||
393 | "onlyheads" restricts the returned changes to those reachable from the |
|
391 | "onlyheads" restricts the returned changes to those reachable from the | |
394 | specified heads. |
|
392 | specified heads. | |
395 | "bundlename", if given, stores the bundle to this file path permanently; |
|
393 | "bundlename", if given, stores the bundle to this file path permanently; | |
396 | otherwise it's stored to a temp file and gets deleted again when you call |
|
394 | otherwise it's stored to a temp file and gets deleted again when you call | |
397 | the returned "cleanupfn". |
|
395 | the returned "cleanupfn". | |
398 | "force" indicates whether to proceed on unrelated repos. |
|
396 | "force" indicates whether to proceed on unrelated repos. | |
399 |
|
397 | |||
400 | Returns a tuple (local, csets, cleanupfn): |
|
398 | Returns a tuple (local, csets, cleanupfn): | |
401 |
|
399 | |||
402 | "local" is a local repo from which to obtain the actual incoming |
|
400 | "local" is a local repo from which to obtain the actual incoming | |
403 | changesets; it is a bundlerepo for the obtained bundle when the |
|
401 | changesets; it is a bundlerepo for the obtained bundle when the | |
404 | original "other" is remote. |
|
402 | original "other" is remote. | |
405 | "csets" lists the incoming changeset node ids. |
|
403 | "csets" lists the incoming changeset node ids. | |
406 | "cleanupfn" must be called without arguments when you're done processing |
|
404 | "cleanupfn" must be called without arguments when you're done processing | |
407 | the changes; it closes both the original "other" and the one returned |
|
405 | the changes; it closes both the original "other" and the one returned | |
408 | here. |
|
406 | here. | |
409 | ''' |
|
407 | ''' | |
410 | tmp = discovery.findcommonincoming(repo, other, heads=onlyheads, |
|
408 | tmp = discovery.findcommonincoming(repo, other, heads=onlyheads, | |
411 | force=force) |
|
409 | force=force) | |
412 | common, incoming, rheads = tmp |
|
410 | common, incoming, rheads = tmp | |
413 | if not incoming: |
|
411 | if not incoming: | |
414 | try: |
|
412 | try: | |
415 | if bundlename: |
|
413 | if bundlename: | |
416 | os.unlink(bundlename) |
|
414 | os.unlink(bundlename) | |
417 | except OSError: |
|
415 | except OSError: | |
418 | pass |
|
416 | pass | |
419 | return repo, [], other.close |
|
417 | return repo, [], other.close | |
420 |
|
418 | |||
421 | commonset = set(common) |
|
419 | commonset = set(common) | |
422 | rheads = [x for x in rheads if x not in commonset] |
|
420 | rheads = [x for x in rheads if x not in commonset] | |
423 |
|
421 | |||
424 | bundle = None |
|
422 | bundle = None | |
425 | bundlerepo = None |
|
423 | bundlerepo = None | |
426 | localrepo = other.local() |
|
424 | localrepo = other.local() | |
427 | if bundlename or not localrepo: |
|
425 | if bundlename or not localrepo: | |
428 | # create a bundle (uncompressed if other repo is not local) |
|
426 | # create a bundle (uncompressed if other repo is not local) | |
429 |
|
427 | |||
430 | if other.capable('getbundle'): |
|
428 | if other.capable('getbundle'): | |
431 | cg = other.getbundle('incoming', common=common, heads=rheads) |
|
429 | cg = other.getbundle('incoming', common=common, heads=rheads) | |
432 | elif onlyheads is None and not other.capable('changegroupsubset'): |
|
430 | elif onlyheads is None and not other.capable('changegroupsubset'): | |
433 | # compat with older servers when pulling all remote heads |
|
431 | # compat with older servers when pulling all remote heads | |
434 | cg = other.changegroup(incoming, "incoming") |
|
432 | cg = other.changegroup(incoming, "incoming") | |
435 | rheads = None |
|
433 | rheads = None | |
436 | else: |
|
434 | else: | |
437 | cg = other.changegroupsubset(incoming, rheads, 'incoming') |
|
435 | cg = other.changegroupsubset(incoming, rheads, 'incoming') | |
438 | if localrepo: |
|
436 | if localrepo: | |
439 | bundletype = "HG10BZ" |
|
437 | bundletype = "HG10BZ" | |
440 | else: |
|
438 | else: | |
441 | bundletype = "HG10UN" |
|
439 | bundletype = "HG10UN" | |
442 | fname = bundle = changegroup.writebundle(ui, cg, bundlename, bundletype) |
|
440 | fname = bundle = changegroup.writebundle(ui, cg, bundlename, bundletype) | |
443 | # keep written bundle? |
|
441 | # keep written bundle? | |
444 | if bundlename: |
|
442 | if bundlename: | |
445 | bundle = None |
|
443 | bundle = None | |
446 | if not localrepo: |
|
444 | if not localrepo: | |
447 | # use the created uncompressed bundlerepo |
|
445 | # use the created uncompressed bundlerepo | |
448 | localrepo = bundlerepo = bundlerepository(repo.baseui, repo.root, |
|
446 | localrepo = bundlerepo = bundlerepository(repo.baseui, repo.root, | |
449 | fname) |
|
447 | fname) | |
450 | # this repo contains local and other now, so filter out local again |
|
448 | # this repo contains local and other now, so filter out local again | |
451 | common = repo.heads() |
|
449 | common = repo.heads() | |
452 | if localrepo: |
|
450 | if localrepo: | |
453 | # Part of common may be remotely filtered |
|
451 | # Part of common may be remotely filtered | |
454 | # So use an unfiltered version |
|
452 | # So use an unfiltered version | |
455 | # The discovery process probably need cleanup to avoid that |
|
453 | # The discovery process probably need cleanup to avoid that | |
456 | localrepo = localrepo.unfiltered() |
|
454 | localrepo = localrepo.unfiltered() | |
457 |
|
455 | |||
458 | csets = localrepo.changelog.findmissing(common, rheads) |
|
456 | csets = localrepo.changelog.findmissing(common, rheads) | |
459 |
|
457 | |||
460 | if bundlerepo: |
|
458 | if bundlerepo: | |
461 | reponodes = [ctx.node() for ctx in bundlerepo[bundlerepo.firstnewrev:]] |
|
459 | reponodes = [ctx.node() for ctx in bundlerepo[bundlerepo.firstnewrev:]] | |
462 | remotephases = other.listkeys('phases') |
|
460 | remotephases = other.listkeys('phases') | |
463 |
|
461 | |||
464 | pullop = exchange.pulloperation(bundlerepo, other, heads=reponodes) |
|
462 | pullop = exchange.pulloperation(bundlerepo, other, heads=reponodes) | |
465 | pullop.trmanager = bundletransactionmanager() |
|
463 | pullop.trmanager = bundletransactionmanager() | |
466 | exchange._pullapplyphases(pullop, remotephases) |
|
464 | exchange._pullapplyphases(pullop, remotephases) | |
467 |
|
465 | |||
468 | def cleanup(): |
|
466 | def cleanup(): | |
469 | if bundlerepo: |
|
467 | if bundlerepo: | |
470 | bundlerepo.close() |
|
468 | bundlerepo.close() | |
471 | if bundle: |
|
469 | if bundle: | |
472 | os.unlink(bundle) |
|
470 | os.unlink(bundle) | |
473 | other.close() |
|
471 | other.close() | |
474 |
|
472 | |||
475 | return (localrepo, csets, cleanup) |
|
473 | return (localrepo, csets, cleanup) |
General Comments 0
You need to be logged in to leave comments.
Login now