Show More
@@ -1,1406 +1,1406 b'' | |||||
1 | # changegroup.py - Mercurial changegroup manipulation functions |
|
1 | # changegroup.py - Mercurial changegroup manipulation functions | |
2 | # |
|
2 | # | |
3 | # Copyright 2006 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2006 Matt Mackall <mpm@selenic.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 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
10 | import os |
|
10 | import os | |
11 | import struct |
|
11 | import struct | |
12 | import weakref |
|
12 | import weakref | |
13 |
|
13 | |||
14 | from .i18n import _ |
|
14 | from .i18n import _ | |
15 | from .node import ( |
|
15 | from .node import ( | |
16 | hex, |
|
16 | hex, | |
17 | nullid, |
|
17 | nullid, | |
18 | nullrev, |
|
18 | nullrev, | |
19 | short, |
|
19 | short, | |
20 | ) |
|
20 | ) | |
21 |
|
21 | |||
22 | from .thirdparty import ( |
|
22 | from .thirdparty import ( | |
23 | attr, |
|
23 | attr, | |
24 | ) |
|
24 | ) | |
25 |
|
25 | |||
26 | from . import ( |
|
26 | from . import ( | |
27 | dagutil, |
|
27 | dagutil, | |
28 | error, |
|
28 | error, | |
29 | manifest, |
|
29 | manifest, | |
30 | match as matchmod, |
|
30 | match as matchmod, | |
31 | mdiff, |
|
31 | mdiff, | |
32 | phases, |
|
32 | phases, | |
33 | pycompat, |
|
33 | pycompat, | |
34 | repository, |
|
34 | repository, | |
35 | revlog, |
|
35 | revlog, | |
36 | util, |
|
36 | util, | |
37 | ) |
|
37 | ) | |
38 |
|
38 | |||
39 | from .utils import ( |
|
39 | from .utils import ( | |
40 | stringutil, |
|
40 | stringutil, | |
41 | ) |
|
41 | ) | |
42 |
|
42 | |||
43 | _CHANGEGROUPV1_DELTA_HEADER = struct.Struct("20s20s20s20s") |
|
43 | _CHANGEGROUPV1_DELTA_HEADER = struct.Struct("20s20s20s20s") | |
44 | _CHANGEGROUPV2_DELTA_HEADER = struct.Struct("20s20s20s20s20s") |
|
44 | _CHANGEGROUPV2_DELTA_HEADER = struct.Struct("20s20s20s20s20s") | |
45 | _CHANGEGROUPV3_DELTA_HEADER = struct.Struct(">20s20s20s20s20sH") |
|
45 | _CHANGEGROUPV3_DELTA_HEADER = struct.Struct(">20s20s20s20s20sH") | |
46 |
|
46 | |||
47 | LFS_REQUIREMENT = 'lfs' |
|
47 | LFS_REQUIREMENT = 'lfs' | |
48 |
|
48 | |||
49 | readexactly = util.readexactly |
|
49 | readexactly = util.readexactly | |
50 |
|
50 | |||
51 | def getchunk(stream): |
|
51 | def getchunk(stream): | |
52 | """return the next chunk from stream as a string""" |
|
52 | """return the next chunk from stream as a string""" | |
53 | d = readexactly(stream, 4) |
|
53 | d = readexactly(stream, 4) | |
54 | l = struct.unpack(">l", d)[0] |
|
54 | l = struct.unpack(">l", d)[0] | |
55 | if l <= 4: |
|
55 | if l <= 4: | |
56 | if l: |
|
56 | if l: | |
57 | raise error.Abort(_("invalid chunk length %d") % l) |
|
57 | raise error.Abort(_("invalid chunk length %d") % l) | |
58 | return "" |
|
58 | return "" | |
59 | return readexactly(stream, l - 4) |
|
59 | return readexactly(stream, l - 4) | |
60 |
|
60 | |||
61 | def chunkheader(length): |
|
61 | def chunkheader(length): | |
62 | """return a changegroup chunk header (string)""" |
|
62 | """return a changegroup chunk header (string)""" | |
63 | return struct.pack(">l", length + 4) |
|
63 | return struct.pack(">l", length + 4) | |
64 |
|
64 | |||
65 | def closechunk(): |
|
65 | def closechunk(): | |
66 | """return a changegroup chunk header (string) for a zero-length chunk""" |
|
66 | """return a changegroup chunk header (string) for a zero-length chunk""" | |
67 | return struct.pack(">l", 0) |
|
67 | return struct.pack(">l", 0) | |
68 |
|
68 | |||
69 | def writechunks(ui, chunks, filename, vfs=None): |
|
69 | def writechunks(ui, chunks, filename, vfs=None): | |
70 | """Write chunks to a file and return its filename. |
|
70 | """Write chunks to a file and return its filename. | |
71 |
|
71 | |||
72 | The stream is assumed to be a bundle file. |
|
72 | The stream is assumed to be a bundle file. | |
73 | Existing files will not be overwritten. |
|
73 | Existing files will not be overwritten. | |
74 | If no filename is specified, a temporary file is created. |
|
74 | If no filename is specified, a temporary file is created. | |
75 | """ |
|
75 | """ | |
76 | fh = None |
|
76 | fh = None | |
77 | cleanup = None |
|
77 | cleanup = None | |
78 | try: |
|
78 | try: | |
79 | if filename: |
|
79 | if filename: | |
80 | if vfs: |
|
80 | if vfs: | |
81 | fh = vfs.open(filename, "wb") |
|
81 | fh = vfs.open(filename, "wb") | |
82 | else: |
|
82 | else: | |
83 | # Increase default buffer size because default is usually |
|
83 | # Increase default buffer size because default is usually | |
84 | # small (4k is common on Linux). |
|
84 | # small (4k is common on Linux). | |
85 | fh = open(filename, "wb", 131072) |
|
85 | fh = open(filename, "wb", 131072) | |
86 | else: |
|
86 | else: | |
87 | fd, filename = pycompat.mkstemp(prefix="hg-bundle-", suffix=".hg") |
|
87 | fd, filename = pycompat.mkstemp(prefix="hg-bundle-", suffix=".hg") | |
88 | fh = os.fdopen(fd, r"wb") |
|
88 | fh = os.fdopen(fd, r"wb") | |
89 | cleanup = filename |
|
89 | cleanup = filename | |
90 | for c in chunks: |
|
90 | for c in chunks: | |
91 | fh.write(c) |
|
91 | fh.write(c) | |
92 | cleanup = None |
|
92 | cleanup = None | |
93 | return filename |
|
93 | return filename | |
94 | finally: |
|
94 | finally: | |
95 | if fh is not None: |
|
95 | if fh is not None: | |
96 | fh.close() |
|
96 | fh.close() | |
97 | if cleanup is not None: |
|
97 | if cleanup is not None: | |
98 | if filename and vfs: |
|
98 | if filename and vfs: | |
99 | vfs.unlink(cleanup) |
|
99 | vfs.unlink(cleanup) | |
100 | else: |
|
100 | else: | |
101 | os.unlink(cleanup) |
|
101 | os.unlink(cleanup) | |
102 |
|
102 | |||
103 | class cg1unpacker(object): |
|
103 | class cg1unpacker(object): | |
104 | """Unpacker for cg1 changegroup streams. |
|
104 | """Unpacker for cg1 changegroup streams. | |
105 |
|
105 | |||
106 | A changegroup unpacker handles the framing of the revision data in |
|
106 | A changegroup unpacker handles the framing of the revision data in | |
107 | the wire format. Most consumers will want to use the apply() |
|
107 | the wire format. Most consumers will want to use the apply() | |
108 | method to add the changes from the changegroup to a repository. |
|
108 | method to add the changes from the changegroup to a repository. | |
109 |
|
109 | |||
110 | If you're forwarding a changegroup unmodified to another consumer, |
|
110 | If you're forwarding a changegroup unmodified to another consumer, | |
111 | use getchunks(), which returns an iterator of changegroup |
|
111 | use getchunks(), which returns an iterator of changegroup | |
112 | chunks. This is mostly useful for cases where you need to know the |
|
112 | chunks. This is mostly useful for cases where you need to know the | |
113 | data stream has ended by observing the end of the changegroup. |
|
113 | data stream has ended by observing the end of the changegroup. | |
114 |
|
114 | |||
115 | deltachunk() is useful only if you're applying delta data. Most |
|
115 | deltachunk() is useful only if you're applying delta data. Most | |
116 | consumers should prefer apply() instead. |
|
116 | consumers should prefer apply() instead. | |
117 |
|
117 | |||
118 | A few other public methods exist. Those are used only for |
|
118 | A few other public methods exist. Those are used only for | |
119 | bundlerepo and some debug commands - their use is discouraged. |
|
119 | bundlerepo and some debug commands - their use is discouraged. | |
120 | """ |
|
120 | """ | |
121 | deltaheader = _CHANGEGROUPV1_DELTA_HEADER |
|
121 | deltaheader = _CHANGEGROUPV1_DELTA_HEADER | |
122 | deltaheadersize = deltaheader.size |
|
122 | deltaheadersize = deltaheader.size | |
123 | version = '01' |
|
123 | version = '01' | |
124 | _grouplistcount = 1 # One list of files after the manifests |
|
124 | _grouplistcount = 1 # One list of files after the manifests | |
125 |
|
125 | |||
126 | def __init__(self, fh, alg, extras=None): |
|
126 | def __init__(self, fh, alg, extras=None): | |
127 | if alg is None: |
|
127 | if alg is None: | |
128 | alg = 'UN' |
|
128 | alg = 'UN' | |
129 | if alg not in util.compengines.supportedbundletypes: |
|
129 | if alg not in util.compengines.supportedbundletypes: | |
130 | raise error.Abort(_('unknown stream compression type: %s') |
|
130 | raise error.Abort(_('unknown stream compression type: %s') | |
131 | % alg) |
|
131 | % alg) | |
132 | if alg == 'BZ': |
|
132 | if alg == 'BZ': | |
133 | alg = '_truncatedBZ' |
|
133 | alg = '_truncatedBZ' | |
134 |
|
134 | |||
135 | compengine = util.compengines.forbundletype(alg) |
|
135 | compengine = util.compengines.forbundletype(alg) | |
136 | self._stream = compengine.decompressorreader(fh) |
|
136 | self._stream = compengine.decompressorreader(fh) | |
137 | self._type = alg |
|
137 | self._type = alg | |
138 | self.extras = extras or {} |
|
138 | self.extras = extras or {} | |
139 | self.callback = None |
|
139 | self.callback = None | |
140 |
|
140 | |||
141 | # These methods (compressed, read, seek, tell) all appear to only |
|
141 | # These methods (compressed, read, seek, tell) all appear to only | |
142 | # be used by bundlerepo, but it's a little hard to tell. |
|
142 | # be used by bundlerepo, but it's a little hard to tell. | |
143 | def compressed(self): |
|
143 | def compressed(self): | |
144 | return self._type is not None and self._type != 'UN' |
|
144 | return self._type is not None and self._type != 'UN' | |
145 | def read(self, l): |
|
145 | def read(self, l): | |
146 | return self._stream.read(l) |
|
146 | return self._stream.read(l) | |
147 | def seek(self, pos): |
|
147 | def seek(self, pos): | |
148 | return self._stream.seek(pos) |
|
148 | return self._stream.seek(pos) | |
149 | def tell(self): |
|
149 | def tell(self): | |
150 | return self._stream.tell() |
|
150 | return self._stream.tell() | |
151 | def close(self): |
|
151 | def close(self): | |
152 | return self._stream.close() |
|
152 | return self._stream.close() | |
153 |
|
153 | |||
154 | def _chunklength(self): |
|
154 | def _chunklength(self): | |
155 | d = readexactly(self._stream, 4) |
|
155 | d = readexactly(self._stream, 4) | |
156 | l = struct.unpack(">l", d)[0] |
|
156 | l = struct.unpack(">l", d)[0] | |
157 | if l <= 4: |
|
157 | if l <= 4: | |
158 | if l: |
|
158 | if l: | |
159 | raise error.Abort(_("invalid chunk length %d") % l) |
|
159 | raise error.Abort(_("invalid chunk length %d") % l) | |
160 | return 0 |
|
160 | return 0 | |
161 | if self.callback: |
|
161 | if self.callback: | |
162 | self.callback() |
|
162 | self.callback() | |
163 | return l - 4 |
|
163 | return l - 4 | |
164 |
|
164 | |||
165 | def changelogheader(self): |
|
165 | def changelogheader(self): | |
166 | """v10 does not have a changelog header chunk""" |
|
166 | """v10 does not have a changelog header chunk""" | |
167 | return {} |
|
167 | return {} | |
168 |
|
168 | |||
169 | def manifestheader(self): |
|
169 | def manifestheader(self): | |
170 | """v10 does not have a manifest header chunk""" |
|
170 | """v10 does not have a manifest header chunk""" | |
171 | return {} |
|
171 | return {} | |
172 |
|
172 | |||
173 | def filelogheader(self): |
|
173 | def filelogheader(self): | |
174 | """return the header of the filelogs chunk, v10 only has the filename""" |
|
174 | """return the header of the filelogs chunk, v10 only has the filename""" | |
175 | l = self._chunklength() |
|
175 | l = self._chunklength() | |
176 | if not l: |
|
176 | if not l: | |
177 | return {} |
|
177 | return {} | |
178 | fname = readexactly(self._stream, l) |
|
178 | fname = readexactly(self._stream, l) | |
179 | return {'filename': fname} |
|
179 | return {'filename': fname} | |
180 |
|
180 | |||
181 | def _deltaheader(self, headertuple, prevnode): |
|
181 | def _deltaheader(self, headertuple, prevnode): | |
182 | node, p1, p2, cs = headertuple |
|
182 | node, p1, p2, cs = headertuple | |
183 | if prevnode is None: |
|
183 | if prevnode is None: | |
184 | deltabase = p1 |
|
184 | deltabase = p1 | |
185 | else: |
|
185 | else: | |
186 | deltabase = prevnode |
|
186 | deltabase = prevnode | |
187 | flags = 0 |
|
187 | flags = 0 | |
188 | return node, p1, p2, deltabase, cs, flags |
|
188 | return node, p1, p2, deltabase, cs, flags | |
189 |
|
189 | |||
190 | def deltachunk(self, prevnode): |
|
190 | def deltachunk(self, prevnode): | |
191 | l = self._chunklength() |
|
191 | l = self._chunklength() | |
192 | if not l: |
|
192 | if not l: | |
193 | return {} |
|
193 | return {} | |
194 | headerdata = readexactly(self._stream, self.deltaheadersize) |
|
194 | headerdata = readexactly(self._stream, self.deltaheadersize) | |
195 | header = self.deltaheader.unpack(headerdata) |
|
195 | header = self.deltaheader.unpack(headerdata) | |
196 | delta = readexactly(self._stream, l - self.deltaheadersize) |
|
196 | delta = readexactly(self._stream, l - self.deltaheadersize) | |
197 | node, p1, p2, deltabase, cs, flags = self._deltaheader(header, prevnode) |
|
197 | node, p1, p2, deltabase, cs, flags = self._deltaheader(header, prevnode) | |
198 | return (node, p1, p2, cs, deltabase, delta, flags) |
|
198 | return (node, p1, p2, cs, deltabase, delta, flags) | |
199 |
|
199 | |||
200 | def getchunks(self): |
|
200 | def getchunks(self): | |
201 | """returns all the chunks contains in the bundle |
|
201 | """returns all the chunks contains in the bundle | |
202 |
|
202 | |||
203 | Used when you need to forward the binary stream to a file or another |
|
203 | Used when you need to forward the binary stream to a file or another | |
204 | network API. To do so, it parse the changegroup data, otherwise it will |
|
204 | network API. To do so, it parse the changegroup data, otherwise it will | |
205 | block in case of sshrepo because it don't know the end of the stream. |
|
205 | block in case of sshrepo because it don't know the end of the stream. | |
206 | """ |
|
206 | """ | |
207 | # For changegroup 1 and 2, we expect 3 parts: changelog, manifestlog, |
|
207 | # For changegroup 1 and 2, we expect 3 parts: changelog, manifestlog, | |
208 | # and a list of filelogs. For changegroup 3, we expect 4 parts: |
|
208 | # and a list of filelogs. For changegroup 3, we expect 4 parts: | |
209 | # changelog, manifestlog, a list of tree manifestlogs, and a list of |
|
209 | # changelog, manifestlog, a list of tree manifestlogs, and a list of | |
210 | # filelogs. |
|
210 | # filelogs. | |
211 | # |
|
211 | # | |
212 | # Changelog and manifestlog parts are terminated with empty chunks. The |
|
212 | # Changelog and manifestlog parts are terminated with empty chunks. The | |
213 | # tree and file parts are a list of entry sections. Each entry section |
|
213 | # tree and file parts are a list of entry sections. Each entry section | |
214 | # is a series of chunks terminating in an empty chunk. The list of these |
|
214 | # is a series of chunks terminating in an empty chunk. The list of these | |
215 | # entry sections is terminated in yet another empty chunk, so we know |
|
215 | # entry sections is terminated in yet another empty chunk, so we know | |
216 | # we've reached the end of the tree/file list when we reach an empty |
|
216 | # we've reached the end of the tree/file list when we reach an empty | |
217 | # chunk that was proceeded by no non-empty chunks. |
|
217 | # chunk that was proceeded by no non-empty chunks. | |
218 |
|
218 | |||
219 | parts = 0 |
|
219 | parts = 0 | |
220 | while parts < 2 + self._grouplistcount: |
|
220 | while parts < 2 + self._grouplistcount: | |
221 | noentries = True |
|
221 | noentries = True | |
222 | while True: |
|
222 | while True: | |
223 | chunk = getchunk(self) |
|
223 | chunk = getchunk(self) | |
224 | if not chunk: |
|
224 | if not chunk: | |
225 | # The first two empty chunks represent the end of the |
|
225 | # The first two empty chunks represent the end of the | |
226 | # changelog and the manifestlog portions. The remaining |
|
226 | # changelog and the manifestlog portions. The remaining | |
227 | # empty chunks represent either A) the end of individual |
|
227 | # empty chunks represent either A) the end of individual | |
228 | # tree or file entries in the file list, or B) the end of |
|
228 | # tree or file entries in the file list, or B) the end of | |
229 | # the entire list. It's the end of the entire list if there |
|
229 | # the entire list. It's the end of the entire list if there | |
230 | # were no entries (i.e. noentries is True). |
|
230 | # were no entries (i.e. noentries is True). | |
231 | if parts < 2: |
|
231 | if parts < 2: | |
232 | parts += 1 |
|
232 | parts += 1 | |
233 | elif noentries: |
|
233 | elif noentries: | |
234 | parts += 1 |
|
234 | parts += 1 | |
235 | break |
|
235 | break | |
236 | noentries = False |
|
236 | noentries = False | |
237 | yield chunkheader(len(chunk)) |
|
237 | yield chunkheader(len(chunk)) | |
238 | pos = 0 |
|
238 | pos = 0 | |
239 | while pos < len(chunk): |
|
239 | while pos < len(chunk): | |
240 | next = pos + 2**20 |
|
240 | next = pos + 2**20 | |
241 | yield chunk[pos:next] |
|
241 | yield chunk[pos:next] | |
242 | pos = next |
|
242 | pos = next | |
243 | yield closechunk() |
|
243 | yield closechunk() | |
244 |
|
244 | |||
245 | def _unpackmanifests(self, repo, revmap, trp, prog): |
|
245 | def _unpackmanifests(self, repo, revmap, trp, prog): | |
246 | self.callback = prog.increment |
|
246 | self.callback = prog.increment | |
247 | # no need to check for empty manifest group here: |
|
247 | # no need to check for empty manifest group here: | |
248 | # if the result of the merge of 1 and 2 is the same in 3 and 4, |
|
248 | # if the result of the merge of 1 and 2 is the same in 3 and 4, | |
249 | # no new manifest will be created and the manifest group will |
|
249 | # no new manifest will be created and the manifest group will | |
250 | # be empty during the pull |
|
250 | # be empty during the pull | |
251 | self.manifestheader() |
|
251 | self.manifestheader() | |
252 | deltas = self.deltaiter() |
|
252 | deltas = self.deltaiter() | |
253 | repo.manifestlog.addgroup(deltas, revmap, trp) |
|
253 | repo.manifestlog.addgroup(deltas, revmap, trp) | |
254 | prog.complete() |
|
254 | prog.complete() | |
255 | self.callback = None |
|
255 | self.callback = None | |
256 |
|
256 | |||
257 | def apply(self, repo, tr, srctype, url, targetphase=phases.draft, |
|
257 | def apply(self, repo, tr, srctype, url, targetphase=phases.draft, | |
258 | expectedtotal=None): |
|
258 | expectedtotal=None): | |
259 | """Add the changegroup returned by source.read() to this repo. |
|
259 | """Add the changegroup returned by source.read() to this repo. | |
260 | srctype is a string like 'push', 'pull', or 'unbundle'. url is |
|
260 | srctype is a string like 'push', 'pull', or 'unbundle'. url is | |
261 | the URL of the repo where this changegroup is coming from. |
|
261 | the URL of the repo where this changegroup is coming from. | |
262 |
|
262 | |||
263 | Return an integer summarizing the change to this repo: |
|
263 | Return an integer summarizing the change to this repo: | |
264 | - nothing changed or no source: 0 |
|
264 | - nothing changed or no source: 0 | |
265 | - more heads than before: 1+added heads (2..n) |
|
265 | - more heads than before: 1+added heads (2..n) | |
266 | - fewer heads than before: -1-removed heads (-2..-n) |
|
266 | - fewer heads than before: -1-removed heads (-2..-n) | |
267 | - number of heads stays the same: 1 |
|
267 | - number of heads stays the same: 1 | |
268 | """ |
|
268 | """ | |
269 | repo = repo.unfiltered() |
|
269 | repo = repo.unfiltered() | |
270 | def csmap(x): |
|
270 | def csmap(x): | |
271 | repo.ui.debug("add changeset %s\n" % short(x)) |
|
271 | repo.ui.debug("add changeset %s\n" % short(x)) | |
272 | return len(cl) |
|
272 | return len(cl) | |
273 |
|
273 | |||
274 | def revmap(x): |
|
274 | def revmap(x): | |
275 | return cl.rev(x) |
|
275 | return cl.rev(x) | |
276 |
|
276 | |||
277 | changesets = files = revisions = 0 |
|
277 | changesets = files = revisions = 0 | |
278 |
|
278 | |||
279 | try: |
|
279 | try: | |
280 | # The transaction may already carry source information. In this |
|
280 | # The transaction may already carry source information. In this | |
281 | # case we use the top level data. We overwrite the argument |
|
281 | # case we use the top level data. We overwrite the argument | |
282 | # because we need to use the top level value (if they exist) |
|
282 | # because we need to use the top level value (if they exist) | |
283 | # in this function. |
|
283 | # in this function. | |
284 | srctype = tr.hookargs.setdefault('source', srctype) |
|
284 | srctype = tr.hookargs.setdefault('source', srctype) | |
285 | url = tr.hookargs.setdefault('url', url) |
|
285 | url = tr.hookargs.setdefault('url', url) | |
286 | repo.hook('prechangegroup', |
|
286 | repo.hook('prechangegroup', | |
287 | throw=True, **pycompat.strkwargs(tr.hookargs)) |
|
287 | throw=True, **pycompat.strkwargs(tr.hookargs)) | |
288 |
|
288 | |||
289 | # write changelog data to temp files so concurrent readers |
|
289 | # write changelog data to temp files so concurrent readers | |
290 | # will not see an inconsistent view |
|
290 | # will not see an inconsistent view | |
291 | cl = repo.changelog |
|
291 | cl = repo.changelog | |
292 | cl.delayupdate(tr) |
|
292 | cl.delayupdate(tr) | |
293 | oldheads = set(cl.heads()) |
|
293 | oldheads = set(cl.heads()) | |
294 |
|
294 | |||
295 | trp = weakref.proxy(tr) |
|
295 | trp = weakref.proxy(tr) | |
296 | # pull off the changeset group |
|
296 | # pull off the changeset group | |
297 | repo.ui.status(_("adding changesets\n")) |
|
297 | repo.ui.status(_("adding changesets\n")) | |
298 | clstart = len(cl) |
|
298 | clstart = len(cl) | |
299 | progress = repo.ui.makeprogress(_('changesets'), unit=_('chunks'), |
|
299 | progress = repo.ui.makeprogress(_('changesets'), unit=_('chunks'), | |
300 | total=expectedtotal) |
|
300 | total=expectedtotal) | |
301 | self.callback = progress.increment |
|
301 | self.callback = progress.increment | |
302 |
|
302 | |||
303 | efiles = set() |
|
303 | efiles = set() | |
304 | def onchangelog(cl, node): |
|
304 | def onchangelog(cl, node): | |
305 | efiles.update(cl.readfiles(node)) |
|
305 | efiles.update(cl.readfiles(node)) | |
306 |
|
306 | |||
307 | self.changelogheader() |
|
307 | self.changelogheader() | |
308 | deltas = self.deltaiter() |
|
308 | deltas = self.deltaiter() | |
309 | cgnodes = cl.addgroup(deltas, csmap, trp, addrevisioncb=onchangelog) |
|
309 | cgnodes = cl.addgroup(deltas, csmap, trp, addrevisioncb=onchangelog) | |
310 | efiles = len(efiles) |
|
310 | efiles = len(efiles) | |
311 |
|
311 | |||
312 | if not cgnodes: |
|
312 | if not cgnodes: | |
313 | repo.ui.develwarn('applied empty changegroup', |
|
313 | repo.ui.develwarn('applied empty changegroup', | |
314 | config='warn-empty-changegroup') |
|
314 | config='warn-empty-changegroup') | |
315 | clend = len(cl) |
|
315 | clend = len(cl) | |
316 | changesets = clend - clstart |
|
316 | changesets = clend - clstart | |
317 | progress.complete() |
|
317 | progress.complete() | |
318 | self.callback = None |
|
318 | self.callback = None | |
319 |
|
319 | |||
320 | # pull off the manifest group |
|
320 | # pull off the manifest group | |
321 | repo.ui.status(_("adding manifests\n")) |
|
321 | repo.ui.status(_("adding manifests\n")) | |
322 | # We know that we'll never have more manifests than we had |
|
322 | # We know that we'll never have more manifests than we had | |
323 | # changesets. |
|
323 | # changesets. | |
324 | progress = repo.ui.makeprogress(_('manifests'), unit=_('chunks'), |
|
324 | progress = repo.ui.makeprogress(_('manifests'), unit=_('chunks'), | |
325 | total=changesets) |
|
325 | total=changesets) | |
326 | self._unpackmanifests(repo, revmap, trp, progress) |
|
326 | self._unpackmanifests(repo, revmap, trp, progress) | |
327 |
|
327 | |||
328 | needfiles = {} |
|
328 | needfiles = {} | |
329 | if repo.ui.configbool('server', 'validate'): |
|
329 | if repo.ui.configbool('server', 'validate'): | |
330 | cl = repo.changelog |
|
330 | cl = repo.changelog | |
331 | ml = repo.manifestlog |
|
331 | ml = repo.manifestlog | |
332 | # validate incoming csets have their manifests |
|
332 | # validate incoming csets have their manifests | |
333 | for cset in pycompat.xrange(clstart, clend): |
|
333 | for cset in pycompat.xrange(clstart, clend): | |
334 | mfnode = cl.changelogrevision(cset).manifest |
|
334 | mfnode = cl.changelogrevision(cset).manifest | |
335 | mfest = ml[mfnode].readdelta() |
|
335 | mfest = ml[mfnode].readdelta() | |
336 | # store file cgnodes we must see |
|
336 | # store file cgnodes we must see | |
337 | for f, n in mfest.iteritems(): |
|
337 | for f, n in mfest.iteritems(): | |
338 | needfiles.setdefault(f, set()).add(n) |
|
338 | needfiles.setdefault(f, set()).add(n) | |
339 |
|
339 | |||
340 | # process the files |
|
340 | # process the files | |
341 | repo.ui.status(_("adding file changes\n")) |
|
341 | repo.ui.status(_("adding file changes\n")) | |
342 | newrevs, newfiles = _addchangegroupfiles( |
|
342 | newrevs, newfiles = _addchangegroupfiles( | |
343 | repo, self, revmap, trp, efiles, needfiles) |
|
343 | repo, self, revmap, trp, efiles, needfiles) | |
344 | revisions += newrevs |
|
344 | revisions += newrevs | |
345 | files += newfiles |
|
345 | files += newfiles | |
346 |
|
346 | |||
347 | deltaheads = 0 |
|
347 | deltaheads = 0 | |
348 | if oldheads: |
|
348 | if oldheads: | |
349 | heads = cl.heads() |
|
349 | heads = cl.heads() | |
350 | deltaheads = len(heads) - len(oldheads) |
|
350 | deltaheads = len(heads) - len(oldheads) | |
351 | for h in heads: |
|
351 | for h in heads: | |
352 | if h not in oldheads and repo[h].closesbranch(): |
|
352 | if h not in oldheads and repo[h].closesbranch(): | |
353 | deltaheads -= 1 |
|
353 | deltaheads -= 1 | |
354 | htext = "" |
|
354 | htext = "" | |
355 | if deltaheads: |
|
355 | if deltaheads: | |
356 | htext = _(" (%+d heads)") % deltaheads |
|
356 | htext = _(" (%+d heads)") % deltaheads | |
357 |
|
357 | |||
358 | repo.ui.status(_("added %d changesets" |
|
358 | repo.ui.status(_("added %d changesets" | |
359 | " with %d changes to %d files%s\n") |
|
359 | " with %d changes to %d files%s\n") | |
360 | % (changesets, revisions, files, htext)) |
|
360 | % (changesets, revisions, files, htext)) | |
361 | repo.invalidatevolatilesets() |
|
361 | repo.invalidatevolatilesets() | |
362 |
|
362 | |||
363 | if changesets > 0: |
|
363 | if changesets > 0: | |
364 | if 'node' not in tr.hookargs: |
|
364 | if 'node' not in tr.hookargs: | |
365 | tr.hookargs['node'] = hex(cl.node(clstart)) |
|
365 | tr.hookargs['node'] = hex(cl.node(clstart)) | |
366 | tr.hookargs['node_last'] = hex(cl.node(clend - 1)) |
|
366 | tr.hookargs['node_last'] = hex(cl.node(clend - 1)) | |
367 | hookargs = dict(tr.hookargs) |
|
367 | hookargs = dict(tr.hookargs) | |
368 | else: |
|
368 | else: | |
369 | hookargs = dict(tr.hookargs) |
|
369 | hookargs = dict(tr.hookargs) | |
370 | hookargs['node'] = hex(cl.node(clstart)) |
|
370 | hookargs['node'] = hex(cl.node(clstart)) | |
371 | hookargs['node_last'] = hex(cl.node(clend - 1)) |
|
371 | hookargs['node_last'] = hex(cl.node(clend - 1)) | |
372 | repo.hook('pretxnchangegroup', |
|
372 | repo.hook('pretxnchangegroup', | |
373 | throw=True, **pycompat.strkwargs(hookargs)) |
|
373 | throw=True, **pycompat.strkwargs(hookargs)) | |
374 |
|
374 | |||
375 | added = [cl.node(r) for r in pycompat.xrange(clstart, clend)] |
|
375 | added = [cl.node(r) for r in pycompat.xrange(clstart, clend)] | |
376 | phaseall = None |
|
376 | phaseall = None | |
377 | if srctype in ('push', 'serve'): |
|
377 | if srctype in ('push', 'serve'): | |
378 | # Old servers can not push the boundary themselves. |
|
378 | # Old servers can not push the boundary themselves. | |
379 | # New servers won't push the boundary if changeset already |
|
379 | # New servers won't push the boundary if changeset already | |
380 | # exists locally as secret |
|
380 | # exists locally as secret | |
381 | # |
|
381 | # | |
382 | # We should not use added here but the list of all change in |
|
382 | # We should not use added here but the list of all change in | |
383 | # the bundle |
|
383 | # the bundle | |
384 | if repo.publishing(): |
|
384 | if repo.publishing(): | |
385 | targetphase = phaseall = phases.public |
|
385 | targetphase = phaseall = phases.public | |
386 | else: |
|
386 | else: | |
387 | # closer target phase computation |
|
387 | # closer target phase computation | |
388 |
|
388 | |||
389 | # Those changesets have been pushed from the |
|
389 | # Those changesets have been pushed from the | |
390 | # outside, their phases are going to be pushed |
|
390 | # outside, their phases are going to be pushed | |
391 | # alongside. Therefor `targetphase` is |
|
391 | # alongside. Therefor `targetphase` is | |
392 | # ignored. |
|
392 | # ignored. | |
393 | targetphase = phaseall = phases.draft |
|
393 | targetphase = phaseall = phases.draft | |
394 | if added: |
|
394 | if added: | |
395 | phases.registernew(repo, tr, targetphase, added) |
|
395 | phases.registernew(repo, tr, targetphase, added) | |
396 | if phaseall is not None: |
|
396 | if phaseall is not None: | |
397 | phases.advanceboundary(repo, tr, phaseall, cgnodes) |
|
397 | phases.advanceboundary(repo, tr, phaseall, cgnodes) | |
398 |
|
398 | |||
399 | if changesets > 0: |
|
399 | if changesets > 0: | |
400 |
|
400 | |||
401 | def runhooks(): |
|
401 | def runhooks(): | |
402 | # These hooks run when the lock releases, not when the |
|
402 | # These hooks run when the lock releases, not when the | |
403 | # transaction closes. So it's possible for the changelog |
|
403 | # transaction closes. So it's possible for the changelog | |
404 | # to have changed since we last saw it. |
|
404 | # to have changed since we last saw it. | |
405 | if clstart >= len(repo): |
|
405 | if clstart >= len(repo): | |
406 | return |
|
406 | return | |
407 |
|
407 | |||
408 | repo.hook("changegroup", **pycompat.strkwargs(hookargs)) |
|
408 | repo.hook("changegroup", **pycompat.strkwargs(hookargs)) | |
409 |
|
409 | |||
410 | for n in added: |
|
410 | for n in added: | |
411 | args = hookargs.copy() |
|
411 | args = hookargs.copy() | |
412 | args['node'] = hex(n) |
|
412 | args['node'] = hex(n) | |
413 | del args['node_last'] |
|
413 | del args['node_last'] | |
414 | repo.hook("incoming", **pycompat.strkwargs(args)) |
|
414 | repo.hook("incoming", **pycompat.strkwargs(args)) | |
415 |
|
415 | |||
416 | newheads = [h for h in repo.heads() |
|
416 | newheads = [h for h in repo.heads() | |
417 | if h not in oldheads] |
|
417 | if h not in oldheads] | |
418 | repo.ui.log("incoming", |
|
418 | repo.ui.log("incoming", | |
419 | "%d incoming changes - new heads: %s\n", |
|
419 | "%d incoming changes - new heads: %s\n", | |
420 | len(added), |
|
420 | len(added), | |
421 | ', '.join([hex(c[:6]) for c in newheads])) |
|
421 | ', '.join([hex(c[:6]) for c in newheads])) | |
422 |
|
422 | |||
423 | tr.addpostclose('changegroup-runhooks-%020i' % clstart, |
|
423 | tr.addpostclose('changegroup-runhooks-%020i' % clstart, | |
424 | lambda tr: repo._afterlock(runhooks)) |
|
424 | lambda tr: repo._afterlock(runhooks)) | |
425 | finally: |
|
425 | finally: | |
426 | repo.ui.flush() |
|
426 | repo.ui.flush() | |
427 | # never return 0 here: |
|
427 | # never return 0 here: | |
428 | if deltaheads < 0: |
|
428 | if deltaheads < 0: | |
429 | ret = deltaheads - 1 |
|
429 | ret = deltaheads - 1 | |
430 | else: |
|
430 | else: | |
431 | ret = deltaheads + 1 |
|
431 | ret = deltaheads + 1 | |
432 | return ret |
|
432 | return ret | |
433 |
|
433 | |||
434 | def deltaiter(self): |
|
434 | def deltaiter(self): | |
435 | """ |
|
435 | """ | |
436 | returns an iterator of the deltas in this changegroup |
|
436 | returns an iterator of the deltas in this changegroup | |
437 |
|
437 | |||
438 | Useful for passing to the underlying storage system to be stored. |
|
438 | Useful for passing to the underlying storage system to be stored. | |
439 | """ |
|
439 | """ | |
440 | chain = None |
|
440 | chain = None | |
441 | for chunkdata in iter(lambda: self.deltachunk(chain), {}): |
|
441 | for chunkdata in iter(lambda: self.deltachunk(chain), {}): | |
442 | # Chunkdata: (node, p1, p2, cs, deltabase, delta, flags) |
|
442 | # Chunkdata: (node, p1, p2, cs, deltabase, delta, flags) | |
443 | yield chunkdata |
|
443 | yield chunkdata | |
444 | chain = chunkdata[0] |
|
444 | chain = chunkdata[0] | |
445 |
|
445 | |||
446 | class cg2unpacker(cg1unpacker): |
|
446 | class cg2unpacker(cg1unpacker): | |
447 | """Unpacker for cg2 streams. |
|
447 | """Unpacker for cg2 streams. | |
448 |
|
448 | |||
449 | cg2 streams add support for generaldelta, so the delta header |
|
449 | cg2 streams add support for generaldelta, so the delta header | |
450 | format is slightly different. All other features about the data |
|
450 | format is slightly different. All other features about the data | |
451 | remain the same. |
|
451 | remain the same. | |
452 | """ |
|
452 | """ | |
453 | deltaheader = _CHANGEGROUPV2_DELTA_HEADER |
|
453 | deltaheader = _CHANGEGROUPV2_DELTA_HEADER | |
454 | deltaheadersize = deltaheader.size |
|
454 | deltaheadersize = deltaheader.size | |
455 | version = '02' |
|
455 | version = '02' | |
456 |
|
456 | |||
457 | def _deltaheader(self, headertuple, prevnode): |
|
457 | def _deltaheader(self, headertuple, prevnode): | |
458 | node, p1, p2, deltabase, cs = headertuple |
|
458 | node, p1, p2, deltabase, cs = headertuple | |
459 | flags = 0 |
|
459 | flags = 0 | |
460 | return node, p1, p2, deltabase, cs, flags |
|
460 | return node, p1, p2, deltabase, cs, flags | |
461 |
|
461 | |||
462 | class cg3unpacker(cg2unpacker): |
|
462 | class cg3unpacker(cg2unpacker): | |
463 | """Unpacker for cg3 streams. |
|
463 | """Unpacker for cg3 streams. | |
464 |
|
464 | |||
465 | cg3 streams add support for exchanging treemanifests and revlog |
|
465 | cg3 streams add support for exchanging treemanifests and revlog | |
466 | flags. It adds the revlog flags to the delta header and an empty chunk |
|
466 | flags. It adds the revlog flags to the delta header and an empty chunk | |
467 | separating manifests and files. |
|
467 | separating manifests and files. | |
468 | """ |
|
468 | """ | |
469 | deltaheader = _CHANGEGROUPV3_DELTA_HEADER |
|
469 | deltaheader = _CHANGEGROUPV3_DELTA_HEADER | |
470 | deltaheadersize = deltaheader.size |
|
470 | deltaheadersize = deltaheader.size | |
471 | version = '03' |
|
471 | version = '03' | |
472 | _grouplistcount = 2 # One list of manifests and one list of files |
|
472 | _grouplistcount = 2 # One list of manifests and one list of files | |
473 |
|
473 | |||
474 | def _deltaheader(self, headertuple, prevnode): |
|
474 | def _deltaheader(self, headertuple, prevnode): | |
475 | node, p1, p2, deltabase, cs, flags = headertuple |
|
475 | node, p1, p2, deltabase, cs, flags = headertuple | |
476 | return node, p1, p2, deltabase, cs, flags |
|
476 | return node, p1, p2, deltabase, cs, flags | |
477 |
|
477 | |||
478 | def _unpackmanifests(self, repo, revmap, trp, prog): |
|
478 | def _unpackmanifests(self, repo, revmap, trp, prog): | |
479 | super(cg3unpacker, self)._unpackmanifests(repo, revmap, trp, prog) |
|
479 | super(cg3unpacker, self)._unpackmanifests(repo, revmap, trp, prog) | |
480 | for chunkdata in iter(self.filelogheader, {}): |
|
480 | for chunkdata in iter(self.filelogheader, {}): | |
481 | # If we get here, there are directory manifests in the changegroup |
|
481 | # If we get here, there are directory manifests in the changegroup | |
482 | d = chunkdata["filename"] |
|
482 | d = chunkdata["filename"] | |
483 | repo.ui.debug("adding %s revisions\n" % d) |
|
483 | repo.ui.debug("adding %s revisions\n" % d) | |
484 | dirlog = repo.manifestlog._revlog.dirlog(d) |
|
484 | dirlog = repo.manifestlog._revlog.dirlog(d) | |
485 | deltas = self.deltaiter() |
|
485 | deltas = self.deltaiter() | |
486 | if not dirlog.addgroup(deltas, revmap, trp): |
|
486 | if not dirlog.addgroup(deltas, revmap, trp): | |
487 | raise error.Abort(_("received dir revlog group is empty")) |
|
487 | raise error.Abort(_("received dir revlog group is empty")) | |
488 |
|
488 | |||
489 | class headerlessfixup(object): |
|
489 | class headerlessfixup(object): | |
490 | def __init__(self, fh, h): |
|
490 | def __init__(self, fh, h): | |
491 | self._h = h |
|
491 | self._h = h | |
492 | self._fh = fh |
|
492 | self._fh = fh | |
493 | def read(self, n): |
|
493 | def read(self, n): | |
494 | if self._h: |
|
494 | if self._h: | |
495 | d, self._h = self._h[:n], self._h[n:] |
|
495 | d, self._h = self._h[:n], self._h[n:] | |
496 | if len(d) < n: |
|
496 | if len(d) < n: | |
497 | d += readexactly(self._fh, n - len(d)) |
|
497 | d += readexactly(self._fh, n - len(d)) | |
498 | return d |
|
498 | return d | |
499 | return readexactly(self._fh, n) |
|
499 | return readexactly(self._fh, n) | |
500 |
|
500 | |||
501 | @attr.s(slots=True, frozen=True) |
|
501 | @attr.s(slots=True, frozen=True) | |
502 | class revisiondelta(object): |
|
502 | class revisiondelta(object): | |
503 | """Describes a delta entry in a changegroup. |
|
503 | """Describes a delta entry in a changegroup. | |
504 |
|
504 | |||
505 | Captured data is sufficient to serialize the delta into multiple |
|
505 | Captured data is sufficient to serialize the delta into multiple | |
506 | formats. |
|
506 | formats. | |
507 | """ |
|
507 | """ | |
508 | # 20 byte node of this revision. |
|
508 | # 20 byte node of this revision. | |
509 | node = attr.ib() |
|
509 | node = attr.ib() | |
510 | # 20 byte nodes of parent revisions. |
|
510 | # 20 byte nodes of parent revisions. | |
511 | p1node = attr.ib() |
|
511 | p1node = attr.ib() | |
512 | p2node = attr.ib() |
|
512 | p2node = attr.ib() | |
513 | # 20 byte node of node this delta is against. |
|
513 | # 20 byte node of node this delta is against. | |
514 | basenode = attr.ib() |
|
514 | basenode = attr.ib() | |
515 | # 20 byte node of changeset revision this delta is associated with. |
|
515 | # 20 byte node of changeset revision this delta is associated with. | |
516 | linknode = attr.ib() |
|
516 | linknode = attr.ib() | |
517 | # 2 bytes of flags to apply to revision data. |
|
517 | # 2 bytes of flags to apply to revision data. | |
518 | flags = attr.ib() |
|
518 | flags = attr.ib() | |
519 | # Iterable of chunks holding raw delta data. |
|
519 | # Iterable of chunks holding raw delta data. | |
520 | deltachunks = attr.ib() |
|
520 | deltachunks = attr.ib() | |
521 |
|
521 | |||
522 | class cgpacker(object): |
|
522 | class cgpacker(object): | |
523 | def __init__(self, repo, filematcher, version, allowreorder, |
|
523 | def __init__(self, repo, filematcher, version, allowreorder, | |
524 | useprevdelta, builddeltaheader, manifestsend, |
|
524 | useprevdelta, builddeltaheader, manifestsend, | |
525 | bundlecaps=None, ellipses=False, |
|
525 | bundlecaps=None, ellipses=False, | |
526 | shallow=False, ellipsisroots=None, fullnodes=None): |
|
526 | shallow=False, ellipsisroots=None, fullnodes=None): | |
527 | """Given a source repo, construct a bundler. |
|
527 | """Given a source repo, construct a bundler. | |
528 |
|
528 | |||
529 | filematcher is a matcher that matches on files to include in the |
|
529 | filematcher is a matcher that matches on files to include in the | |
530 | changegroup. Used to facilitate sparse changegroups. |
|
530 | changegroup. Used to facilitate sparse changegroups. | |
531 |
|
531 | |||
532 | allowreorder controls whether reordering of revisions is allowed. |
|
532 | allowreorder controls whether reordering of revisions is allowed. | |
533 | This value is used when ``bundle.reorder`` is ``auto`` or isn't |
|
533 | This value is used when ``bundle.reorder`` is ``auto`` or isn't | |
534 | set. |
|
534 | set. | |
535 |
|
535 | |||
536 | useprevdelta controls whether revisions should always delta against |
|
536 | useprevdelta controls whether revisions should always delta against | |
537 | the previous revision in the changegroup. |
|
537 | the previous revision in the changegroup. | |
538 |
|
538 | |||
539 | builddeltaheader is a callable that constructs the header for a group |
|
539 | builddeltaheader is a callable that constructs the header for a group | |
540 | delta. |
|
540 | delta. | |
541 |
|
541 | |||
542 | manifestsend is a chunk to send after manifests have been fully emitted. |
|
542 | manifestsend is a chunk to send after manifests have been fully emitted. | |
543 |
|
543 | |||
544 | ellipses indicates whether ellipsis serving mode is enabled. |
|
544 | ellipses indicates whether ellipsis serving mode is enabled. | |
545 |
|
545 | |||
546 | bundlecaps is optional and can be used to specify the set of |
|
546 | bundlecaps is optional and can be used to specify the set of | |
547 | capabilities which can be used to build the bundle. While bundlecaps is |
|
547 | capabilities which can be used to build the bundle. While bundlecaps is | |
548 | unused in core Mercurial, extensions rely on this feature to communicate |
|
548 | unused in core Mercurial, extensions rely on this feature to communicate | |
549 | capabilities to customize the changegroup packer. |
|
549 | capabilities to customize the changegroup packer. | |
550 |
|
550 | |||
551 | shallow indicates whether shallow data might be sent. The packer may |
|
551 | shallow indicates whether shallow data might be sent. The packer may | |
552 | need to pack file contents not introduced by the changes being packed. |
|
552 | need to pack file contents not introduced by the changes being packed. | |
553 |
|
553 | |||
554 | fullnodes is the list of nodes which should not be ellipsis nodes. We |
|
554 | fullnodes is the list of nodes which should not be ellipsis nodes. We | |
555 | store this rather than the set of nodes that should be ellipsis because |
|
555 | store this rather than the set of nodes that should be ellipsis because | |
556 | for very large histories we expect this to be significantly smaller. |
|
556 | for very large histories we expect this to be significantly smaller. | |
557 | """ |
|
557 | """ | |
558 | assert filematcher |
|
558 | assert filematcher | |
559 | self._filematcher = filematcher |
|
559 | self._filematcher = filematcher | |
560 |
|
560 | |||
561 | self.version = version |
|
561 | self.version = version | |
562 | self._useprevdelta = useprevdelta |
|
562 | self._useprevdelta = useprevdelta | |
563 | self._builddeltaheader = builddeltaheader |
|
563 | self._builddeltaheader = builddeltaheader | |
564 | self._manifestsend = manifestsend |
|
564 | self._manifestsend = manifestsend | |
565 | self._ellipses = ellipses |
|
565 | self._ellipses = ellipses | |
566 |
|
566 | |||
567 | # Set of capabilities we can use to build the bundle. |
|
567 | # Set of capabilities we can use to build the bundle. | |
568 | if bundlecaps is None: |
|
568 | if bundlecaps is None: | |
569 | bundlecaps = set() |
|
569 | bundlecaps = set() | |
570 | self._bundlecaps = bundlecaps |
|
570 | self._bundlecaps = bundlecaps | |
571 | self._isshallow = shallow |
|
571 | self._isshallow = shallow | |
572 | self._fullnodes = fullnodes |
|
572 | self._fullnodes = fullnodes | |
573 |
|
573 | |||
574 | # Maps ellipsis revs to their roots at the changelog level. |
|
574 | # Maps ellipsis revs to their roots at the changelog level. | |
575 | self._precomputedellipsis = ellipsisroots |
|
575 | self._precomputedellipsis = ellipsisroots | |
576 |
|
576 | |||
577 | # experimental config: bundle.reorder |
|
577 | # experimental config: bundle.reorder | |
578 | reorder = repo.ui.config('bundle', 'reorder') |
|
578 | reorder = repo.ui.config('bundle', 'reorder') | |
579 | if reorder == 'auto': |
|
579 | if reorder == 'auto': | |
580 | self._reorder = allowreorder |
|
580 | self._reorder = allowreorder | |
581 | else: |
|
581 | else: | |
582 | self._reorder = stringutil.parsebool(reorder) |
|
582 | self._reorder = stringutil.parsebool(reorder) | |
583 |
|
583 | |||
584 | self._repo = repo |
|
584 | self._repo = repo | |
585 |
|
585 | |||
586 | if self._repo.ui.verbose and not self._repo.ui.debugflag: |
|
586 | if self._repo.ui.verbose and not self._repo.ui.debugflag: | |
587 | self._verbosenote = self._repo.ui.note |
|
587 | self._verbosenote = self._repo.ui.note | |
588 | else: |
|
588 | else: | |
589 | self._verbosenote = lambda s: None |
|
589 | self._verbosenote = lambda s: None | |
590 |
|
590 | |||
591 | # TODO the functionality keyed off of this should probably be |
|
591 | # TODO the functionality keyed off of this should probably be | |
592 | # controlled via arguments to group() that influence behavior. |
|
592 | # controlled via arguments to group() that influence behavior. | |
593 | self._changelogdone = False |
|
593 | self._changelogdone = False | |
594 |
|
594 | |||
595 | # Maps CL revs to per-revlog revisions. Cleared in close() at |
|
595 | # Maps CL revs to per-revlog revisions. Cleared in close() at | |
596 | # the end of each group. |
|
596 | # the end of each group. | |
597 | self._clrevtolocalrev = {} |
|
597 | self._clrevtolocalrev = {} | |
598 | self._nextclrevtolocalrev = {} |
|
598 | self._nextclrevtolocalrev = {} | |
599 |
|
599 | |||
600 | # Maps changelog nodes to changelog revs. Filled in once |
|
600 | # Maps changelog nodes to changelog revs. Filled in once | |
601 | # during changelog stage and then left unmodified. |
|
601 | # during changelog stage and then left unmodified. | |
602 | self._clnodetorev = {} |
|
602 | self._clnodetorev = {} | |
603 |
|
603 | |||
604 | def _close(self): |
|
604 | def _close(self): | |
605 | # Ellipses serving mode. |
|
605 | # Ellipses serving mode. | |
606 | self._clrevtolocalrev.clear() |
|
606 | self._clrevtolocalrev.clear() | |
607 | if self._nextclrevtolocalrev: |
|
607 | if self._nextclrevtolocalrev: | |
608 | self.clrevtolocalrev = self._nextclrevtolocalrev |
|
608 | self._clrevtolocalrev = self._nextclrevtolocalrev | |
609 | self._nextclrevtolocalrev.clear() |
|
609 | self._nextclrevtolocalrev.clear() | |
610 | self._changelogdone = True |
|
610 | self._changelogdone = True | |
611 |
|
611 | |||
612 | return closechunk() |
|
612 | return closechunk() | |
613 |
|
613 | |||
614 | def _fileheader(self, fname): |
|
614 | def _fileheader(self, fname): | |
615 | return chunkheader(len(fname)) + fname |
|
615 | return chunkheader(len(fname)) + fname | |
616 |
|
616 | |||
617 | # Extracted both for clarity and for overriding in extensions. |
|
617 | # Extracted both for clarity and for overriding in extensions. | |
618 | def _sortgroup(self, store, nodelist, lookup): |
|
618 | def _sortgroup(self, store, nodelist, lookup): | |
619 | """Sort nodes for change group and turn them into revnums.""" |
|
619 | """Sort nodes for change group and turn them into revnums.""" | |
620 | # Ellipses serving mode. |
|
620 | # Ellipses serving mode. | |
621 | # |
|
621 | # | |
622 | # In a perfect world, we'd generate better ellipsis-ified graphs |
|
622 | # In a perfect world, we'd generate better ellipsis-ified graphs | |
623 | # for non-changelog revlogs. In practice, we haven't started doing |
|
623 | # for non-changelog revlogs. In practice, we haven't started doing | |
624 | # that yet, so the resulting DAGs for the manifestlog and filelogs |
|
624 | # that yet, so the resulting DAGs for the manifestlog and filelogs | |
625 | # are actually full of bogus parentage on all the ellipsis |
|
625 | # are actually full of bogus parentage on all the ellipsis | |
626 | # nodes. This has the side effect that, while the contents are |
|
626 | # nodes. This has the side effect that, while the contents are | |
627 | # correct, the individual DAGs might be completely out of whack in |
|
627 | # correct, the individual DAGs might be completely out of whack in | |
628 | # a case like 882681bc3166 and its ancestors (back about 10 |
|
628 | # a case like 882681bc3166 and its ancestors (back about 10 | |
629 | # revisions or so) in the main hg repo. |
|
629 | # revisions or so) in the main hg repo. | |
630 | # |
|
630 | # | |
631 | # The one invariant we *know* holds is that the new (potentially |
|
631 | # The one invariant we *know* holds is that the new (potentially | |
632 | # bogus) DAG shape will be valid if we order the nodes in the |
|
632 | # bogus) DAG shape will be valid if we order the nodes in the | |
633 | # order that they're introduced in dramatis personae by the |
|
633 | # order that they're introduced in dramatis personae by the | |
634 | # changelog, so what we do is we sort the non-changelog histories |
|
634 | # changelog, so what we do is we sort the non-changelog histories | |
635 | # by the order in which they are used by the changelog. |
|
635 | # by the order in which they are used by the changelog. | |
636 | if self._ellipses and self._clnodetorev: |
|
636 | if self._ellipses and self._clnodetorev: | |
637 | key = lambda n: self._clnodetorev[lookup(n)] |
|
637 | key = lambda n: self._clnodetorev[lookup(n)] | |
638 | return [store.rev(n) for n in sorted(nodelist, key=key)] |
|
638 | return [store.rev(n) for n in sorted(nodelist, key=key)] | |
639 |
|
639 | |||
640 | # for generaldelta revlogs, we linearize the revs; this will both be |
|
640 | # for generaldelta revlogs, we linearize the revs; this will both be | |
641 | # much quicker and generate a much smaller bundle |
|
641 | # much quicker and generate a much smaller bundle | |
642 | if (store._generaldelta and self._reorder is None) or self._reorder: |
|
642 | if (store._generaldelta and self._reorder is None) or self._reorder: | |
643 | dag = dagutil.revlogdag(store) |
|
643 | dag = dagutil.revlogdag(store) | |
644 | return dag.linearize(set(store.rev(n) for n in nodelist)) |
|
644 | return dag.linearize(set(store.rev(n) for n in nodelist)) | |
645 | else: |
|
645 | else: | |
646 | return sorted([store.rev(n) for n in nodelist]) |
|
646 | return sorted([store.rev(n) for n in nodelist]) | |
647 |
|
647 | |||
648 | def group(self, nodelist, store, lookup, units=None): |
|
648 | def group(self, nodelist, store, lookup, units=None): | |
649 | """Calculate a delta group, yielding a sequence of changegroup chunks |
|
649 | """Calculate a delta group, yielding a sequence of changegroup chunks | |
650 | (strings). |
|
650 | (strings). | |
651 |
|
651 | |||
652 | Given a list of changeset revs, return a set of deltas and |
|
652 | Given a list of changeset revs, return a set of deltas and | |
653 | metadata corresponding to nodes. The first delta is |
|
653 | metadata corresponding to nodes. The first delta is | |
654 | first parent(nodelist[0]) -> nodelist[0], the receiver is |
|
654 | first parent(nodelist[0]) -> nodelist[0], the receiver is | |
655 | guaranteed to have this parent as it has all history before |
|
655 | guaranteed to have this parent as it has all history before | |
656 | these changesets. In the case firstparent is nullrev the |
|
656 | these changesets. In the case firstparent is nullrev the | |
657 | changegroup starts with a full revision. |
|
657 | changegroup starts with a full revision. | |
658 |
|
658 | |||
659 | If units is not None, progress detail will be generated, units specifies |
|
659 | If units is not None, progress detail will be generated, units specifies | |
660 | the type of revlog that is touched (changelog, manifest, etc.). |
|
660 | the type of revlog that is touched (changelog, manifest, etc.). | |
661 | """ |
|
661 | """ | |
662 | # if we don't have any revisions touched by these changesets, bail |
|
662 | # if we don't have any revisions touched by these changesets, bail | |
663 | if len(nodelist) == 0: |
|
663 | if len(nodelist) == 0: | |
664 | yield self._close() |
|
664 | yield self._close() | |
665 | return |
|
665 | return | |
666 |
|
666 | |||
667 | revs = self._sortgroup(store, nodelist, lookup) |
|
667 | revs = self._sortgroup(store, nodelist, lookup) | |
668 |
|
668 | |||
669 | # add the parent of the first rev |
|
669 | # add the parent of the first rev | |
670 | p = store.parentrevs(revs[0])[0] |
|
670 | p = store.parentrevs(revs[0])[0] | |
671 | revs.insert(0, p) |
|
671 | revs.insert(0, p) | |
672 |
|
672 | |||
673 | # build deltas |
|
673 | # build deltas | |
674 | progress = None |
|
674 | progress = None | |
675 | if units is not None: |
|
675 | if units is not None: | |
676 | progress = self._repo.ui.makeprogress(_('bundling'), unit=units, |
|
676 | progress = self._repo.ui.makeprogress(_('bundling'), unit=units, | |
677 | total=(len(revs) - 1)) |
|
677 | total=(len(revs) - 1)) | |
678 | for r in pycompat.xrange(len(revs) - 1): |
|
678 | for r in pycompat.xrange(len(revs) - 1): | |
679 | if progress: |
|
679 | if progress: | |
680 | progress.update(r + 1) |
|
680 | progress.update(r + 1) | |
681 | prev, curr = revs[r], revs[r + 1] |
|
681 | prev, curr = revs[r], revs[r + 1] | |
682 | linknode = lookup(store.node(curr)) |
|
682 | linknode = lookup(store.node(curr)) | |
683 | for c in self._revchunk(store, curr, prev, linknode): |
|
683 | for c in self._revchunk(store, curr, prev, linknode): | |
684 | yield c |
|
684 | yield c | |
685 |
|
685 | |||
686 | if progress: |
|
686 | if progress: | |
687 | progress.complete() |
|
687 | progress.complete() | |
688 | yield self._close() |
|
688 | yield self._close() | |
689 |
|
689 | |||
690 | # filter any nodes that claim to be part of the known set |
|
690 | # filter any nodes that claim to be part of the known set | |
691 | def _prune(self, store, missing, commonrevs): |
|
691 | def _prune(self, store, missing, commonrevs): | |
692 | # TODO this violates storage abstraction for manifests. |
|
692 | # TODO this violates storage abstraction for manifests. | |
693 | if isinstance(store, manifest.manifestrevlog): |
|
693 | if isinstance(store, manifest.manifestrevlog): | |
694 | if not self._filematcher.visitdir(store._dir[:-1] or '.'): |
|
694 | if not self._filematcher.visitdir(store._dir[:-1] or '.'): | |
695 | return [] |
|
695 | return [] | |
696 |
|
696 | |||
697 | rr, rl = store.rev, store.linkrev |
|
697 | rr, rl = store.rev, store.linkrev | |
698 | return [n for n in missing if rl(rr(n)) not in commonrevs] |
|
698 | return [n for n in missing if rl(rr(n)) not in commonrevs] | |
699 |
|
699 | |||
700 | def _packmanifests(self, dir, mfnodes, lookuplinknode): |
|
700 | def _packmanifests(self, dir, mfnodes, lookuplinknode): | |
701 | """Pack manifests into a changegroup stream. |
|
701 | """Pack manifests into a changegroup stream. | |
702 |
|
702 | |||
703 | Encodes the directory name in the output so multiple manifests |
|
703 | Encodes the directory name in the output so multiple manifests | |
704 | can be sent. Multiple manifests is not supported by cg1 and cg2. |
|
704 | can be sent. Multiple manifests is not supported by cg1 and cg2. | |
705 | """ |
|
705 | """ | |
706 |
|
706 | |||
707 | if dir: |
|
707 | if dir: | |
708 | assert self.version == b'03' |
|
708 | assert self.version == b'03' | |
709 | yield self._fileheader(dir) |
|
709 | yield self._fileheader(dir) | |
710 |
|
710 | |||
711 | # TODO violates storage abstractions by assuming revlogs. |
|
711 | # TODO violates storage abstractions by assuming revlogs. | |
712 | dirlog = self._repo.manifestlog._revlog.dirlog(dir) |
|
712 | dirlog = self._repo.manifestlog._revlog.dirlog(dir) | |
713 | for chunk in self.group(mfnodes, dirlog, lookuplinknode, |
|
713 | for chunk in self.group(mfnodes, dirlog, lookuplinknode, | |
714 | units=_('manifests')): |
|
714 | units=_('manifests')): | |
715 | yield chunk |
|
715 | yield chunk | |
716 |
|
716 | |||
717 | def generate(self, commonrevs, clnodes, fastpathlinkrev, source): |
|
717 | def generate(self, commonrevs, clnodes, fastpathlinkrev, source): | |
718 | '''yield a sequence of changegroup chunks (strings)''' |
|
718 | '''yield a sequence of changegroup chunks (strings)''' | |
719 | repo = self._repo |
|
719 | repo = self._repo | |
720 | cl = repo.changelog |
|
720 | cl = repo.changelog | |
721 |
|
721 | |||
722 | clrevorder = {} |
|
722 | clrevorder = {} | |
723 | mfs = {} # needed manifests |
|
723 | mfs = {} # needed manifests | |
724 | fnodes = {} # needed file nodes |
|
724 | fnodes = {} # needed file nodes | |
725 | mfl = repo.manifestlog |
|
725 | mfl = repo.manifestlog | |
726 | # TODO violates storage abstraction. |
|
726 | # TODO violates storage abstraction. | |
727 | mfrevlog = mfl._revlog |
|
727 | mfrevlog = mfl._revlog | |
728 | changedfiles = set() |
|
728 | changedfiles = set() | |
729 |
|
729 | |||
730 | # Callback for the changelog, used to collect changed files and |
|
730 | # Callback for the changelog, used to collect changed files and | |
731 | # manifest nodes. |
|
731 | # manifest nodes. | |
732 | # Returns the linkrev node (identity in the changelog case). |
|
732 | # Returns the linkrev node (identity in the changelog case). | |
733 | def lookupcl(x): |
|
733 | def lookupcl(x): | |
734 | c = cl.read(x) |
|
734 | c = cl.read(x) | |
735 | clrevorder[x] = len(clrevorder) |
|
735 | clrevorder[x] = len(clrevorder) | |
736 |
|
736 | |||
737 | if self._ellipses: |
|
737 | if self._ellipses: | |
738 | # Only update mfs if x is going to be sent. Otherwise we |
|
738 | # Only update mfs if x is going to be sent. Otherwise we | |
739 | # end up with bogus linkrevs specified for manifests and |
|
739 | # end up with bogus linkrevs specified for manifests and | |
740 | # we skip some manifest nodes that we should otherwise |
|
740 | # we skip some manifest nodes that we should otherwise | |
741 | # have sent. |
|
741 | # have sent. | |
742 | if (x in self._fullnodes |
|
742 | if (x in self._fullnodes | |
743 | or cl.rev(x) in self._precomputedellipsis): |
|
743 | or cl.rev(x) in self._precomputedellipsis): | |
744 | n = c[0] |
|
744 | n = c[0] | |
745 | # Record the first changeset introducing this manifest |
|
745 | # Record the first changeset introducing this manifest | |
746 | # version. |
|
746 | # version. | |
747 | mfs.setdefault(n, x) |
|
747 | mfs.setdefault(n, x) | |
748 | # Set this narrow-specific dict so we have the lowest |
|
748 | # Set this narrow-specific dict so we have the lowest | |
749 | # manifest revnum to look up for this cl revnum. (Part of |
|
749 | # manifest revnum to look up for this cl revnum. (Part of | |
750 | # mapping changelog ellipsis parents to manifest ellipsis |
|
750 | # mapping changelog ellipsis parents to manifest ellipsis | |
751 | # parents) |
|
751 | # parents) | |
752 | self._nextclrevtolocalrev.setdefault(cl.rev(x), |
|
752 | self._nextclrevtolocalrev.setdefault(cl.rev(x), | |
753 | mfrevlog.rev(n)) |
|
753 | mfrevlog.rev(n)) | |
754 | # We can't trust the changed files list in the changeset if the |
|
754 | # We can't trust the changed files list in the changeset if the | |
755 | # client requested a shallow clone. |
|
755 | # client requested a shallow clone. | |
756 | if self._isshallow: |
|
756 | if self._isshallow: | |
757 | changedfiles.update(mfl[c[0]].read().keys()) |
|
757 | changedfiles.update(mfl[c[0]].read().keys()) | |
758 | else: |
|
758 | else: | |
759 | changedfiles.update(c[3]) |
|
759 | changedfiles.update(c[3]) | |
760 | else: |
|
760 | else: | |
761 |
|
761 | |||
762 | n = c[0] |
|
762 | n = c[0] | |
763 | # record the first changeset introducing this manifest version |
|
763 | # record the first changeset introducing this manifest version | |
764 | mfs.setdefault(n, x) |
|
764 | mfs.setdefault(n, x) | |
765 | # Record a complete list of potentially-changed files in |
|
765 | # Record a complete list of potentially-changed files in | |
766 | # this manifest. |
|
766 | # this manifest. | |
767 | changedfiles.update(c[3]) |
|
767 | changedfiles.update(c[3]) | |
768 |
|
768 | |||
769 | return x |
|
769 | return x | |
770 |
|
770 | |||
771 | self._verbosenote(_('uncompressed size of bundle content:\n')) |
|
771 | self._verbosenote(_('uncompressed size of bundle content:\n')) | |
772 | size = 0 |
|
772 | size = 0 | |
773 | for chunk in self.group(clnodes, cl, lookupcl, units=_('changesets')): |
|
773 | for chunk in self.group(clnodes, cl, lookupcl, units=_('changesets')): | |
774 | size += len(chunk) |
|
774 | size += len(chunk) | |
775 | yield chunk |
|
775 | yield chunk | |
776 | self._verbosenote(_('%8.i (changelog)\n') % size) |
|
776 | self._verbosenote(_('%8.i (changelog)\n') % size) | |
777 |
|
777 | |||
778 | # We need to make sure that the linkrev in the changegroup refers to |
|
778 | # We need to make sure that the linkrev in the changegroup refers to | |
779 | # the first changeset that introduced the manifest or file revision. |
|
779 | # the first changeset that introduced the manifest or file revision. | |
780 | # The fastpath is usually safer than the slowpath, because the filelogs |
|
780 | # The fastpath is usually safer than the slowpath, because the filelogs | |
781 | # are walked in revlog order. |
|
781 | # are walked in revlog order. | |
782 | # |
|
782 | # | |
783 | # When taking the slowpath with reorder=None and the manifest revlog |
|
783 | # When taking the slowpath with reorder=None and the manifest revlog | |
784 | # uses generaldelta, the manifest may be walked in the "wrong" order. |
|
784 | # uses generaldelta, the manifest may be walked in the "wrong" order. | |
785 | # Without 'clrevorder', we would get an incorrect linkrev (see fix in |
|
785 | # Without 'clrevorder', we would get an incorrect linkrev (see fix in | |
786 | # cc0ff93d0c0c). |
|
786 | # cc0ff93d0c0c). | |
787 | # |
|
787 | # | |
788 | # When taking the fastpath, we are only vulnerable to reordering |
|
788 | # When taking the fastpath, we are only vulnerable to reordering | |
789 | # of the changelog itself. The changelog never uses generaldelta, so |
|
789 | # of the changelog itself. The changelog never uses generaldelta, so | |
790 | # it is only reordered when reorder=True. To handle this case, we |
|
790 | # it is only reordered when reorder=True. To handle this case, we | |
791 | # simply take the slowpath, which already has the 'clrevorder' logic. |
|
791 | # simply take the slowpath, which already has the 'clrevorder' logic. | |
792 | # This was also fixed in cc0ff93d0c0c. |
|
792 | # This was also fixed in cc0ff93d0c0c. | |
793 | fastpathlinkrev = fastpathlinkrev and not self._reorder |
|
793 | fastpathlinkrev = fastpathlinkrev and not self._reorder | |
794 | # Treemanifests don't work correctly with fastpathlinkrev |
|
794 | # Treemanifests don't work correctly with fastpathlinkrev | |
795 | # either, because we don't discover which directory nodes to |
|
795 | # either, because we don't discover which directory nodes to | |
796 | # send along with files. This could probably be fixed. |
|
796 | # send along with files. This could probably be fixed. | |
797 | fastpathlinkrev = fastpathlinkrev and ( |
|
797 | fastpathlinkrev = fastpathlinkrev and ( | |
798 | 'treemanifest' not in repo.requirements) |
|
798 | 'treemanifest' not in repo.requirements) | |
799 |
|
799 | |||
800 | for chunk in self.generatemanifests(commonrevs, clrevorder, |
|
800 | for chunk in self.generatemanifests(commonrevs, clrevorder, | |
801 | fastpathlinkrev, mfs, fnodes, source): |
|
801 | fastpathlinkrev, mfs, fnodes, source): | |
802 | yield chunk |
|
802 | yield chunk | |
803 |
|
803 | |||
804 | if self._ellipses: |
|
804 | if self._ellipses: | |
805 | mfdicts = None |
|
805 | mfdicts = None | |
806 | if self._isshallow: |
|
806 | if self._isshallow: | |
807 | mfdicts = [(self._repo.manifestlog[n].read(), lr) |
|
807 | mfdicts = [(self._repo.manifestlog[n].read(), lr) | |
808 | for (n, lr) in mfs.iteritems()] |
|
808 | for (n, lr) in mfs.iteritems()] | |
809 |
|
809 | |||
810 | mfs.clear() |
|
810 | mfs.clear() | |
811 | clrevs = set(cl.rev(x) for x in clnodes) |
|
811 | clrevs = set(cl.rev(x) for x in clnodes) | |
812 |
|
812 | |||
813 | if not fastpathlinkrev: |
|
813 | if not fastpathlinkrev: | |
814 | def linknodes(unused, fname): |
|
814 | def linknodes(unused, fname): | |
815 | return fnodes.get(fname, {}) |
|
815 | return fnodes.get(fname, {}) | |
816 | else: |
|
816 | else: | |
817 | cln = cl.node |
|
817 | cln = cl.node | |
818 | def linknodes(filerevlog, fname): |
|
818 | def linknodes(filerevlog, fname): | |
819 | llr = filerevlog.linkrev |
|
819 | llr = filerevlog.linkrev | |
820 | fln = filerevlog.node |
|
820 | fln = filerevlog.node | |
821 | revs = ((r, llr(r)) for r in filerevlog) |
|
821 | revs = ((r, llr(r)) for r in filerevlog) | |
822 | return dict((fln(r), cln(lr)) for r, lr in revs if lr in clrevs) |
|
822 | return dict((fln(r), cln(lr)) for r, lr in revs if lr in clrevs) | |
823 |
|
823 | |||
824 | if self._ellipses: |
|
824 | if self._ellipses: | |
825 | # We need to pass the mfdicts variable down into |
|
825 | # We need to pass the mfdicts variable down into | |
826 | # generatefiles(), but more than one command might have |
|
826 | # generatefiles(), but more than one command might have | |
827 | # wrapped generatefiles so we can't modify the function |
|
827 | # wrapped generatefiles so we can't modify the function | |
828 | # signature. Instead, we pass the data to ourselves using an |
|
828 | # signature. Instead, we pass the data to ourselves using an | |
829 | # instance attribute. I'm sorry. |
|
829 | # instance attribute. I'm sorry. | |
830 | self._mfdicts = mfdicts |
|
830 | self._mfdicts = mfdicts | |
831 |
|
831 | |||
832 | for chunk in self.generatefiles(changedfiles, linknodes, commonrevs, |
|
832 | for chunk in self.generatefiles(changedfiles, linknodes, commonrevs, | |
833 | source): |
|
833 | source): | |
834 | yield chunk |
|
834 | yield chunk | |
835 |
|
835 | |||
836 | yield self._close() |
|
836 | yield self._close() | |
837 |
|
837 | |||
838 | if clnodes: |
|
838 | if clnodes: | |
839 | repo.hook('outgoing', node=hex(clnodes[0]), source=source) |
|
839 | repo.hook('outgoing', node=hex(clnodes[0]), source=source) | |
840 |
|
840 | |||
841 | def generatemanifests(self, commonrevs, clrevorder, fastpathlinkrev, mfs, |
|
841 | def generatemanifests(self, commonrevs, clrevorder, fastpathlinkrev, mfs, | |
842 | fnodes, source): |
|
842 | fnodes, source): | |
843 | """Returns an iterator of changegroup chunks containing manifests. |
|
843 | """Returns an iterator of changegroup chunks containing manifests. | |
844 |
|
844 | |||
845 | `source` is unused here, but is used by extensions like remotefilelog to |
|
845 | `source` is unused here, but is used by extensions like remotefilelog to | |
846 | change what is sent based in pulls vs pushes, etc. |
|
846 | change what is sent based in pulls vs pushes, etc. | |
847 | """ |
|
847 | """ | |
848 | repo = self._repo |
|
848 | repo = self._repo | |
849 | mfl = repo.manifestlog |
|
849 | mfl = repo.manifestlog | |
850 | dirlog = mfl._revlog.dirlog |
|
850 | dirlog = mfl._revlog.dirlog | |
851 | tmfnodes = {'': mfs} |
|
851 | tmfnodes = {'': mfs} | |
852 |
|
852 | |||
853 | # Callback for the manifest, used to collect linkrevs for filelog |
|
853 | # Callback for the manifest, used to collect linkrevs for filelog | |
854 | # revisions. |
|
854 | # revisions. | |
855 | # Returns the linkrev node (collected in lookupcl). |
|
855 | # Returns the linkrev node (collected in lookupcl). | |
856 | def makelookupmflinknode(dir, nodes): |
|
856 | def makelookupmflinknode(dir, nodes): | |
857 | if fastpathlinkrev: |
|
857 | if fastpathlinkrev: | |
858 | assert not dir |
|
858 | assert not dir | |
859 | return mfs.__getitem__ |
|
859 | return mfs.__getitem__ | |
860 |
|
860 | |||
861 | def lookupmflinknode(x): |
|
861 | def lookupmflinknode(x): | |
862 | """Callback for looking up the linknode for manifests. |
|
862 | """Callback for looking up the linknode for manifests. | |
863 |
|
863 | |||
864 | Returns the linkrev node for the specified manifest. |
|
864 | Returns the linkrev node for the specified manifest. | |
865 |
|
865 | |||
866 | SIDE EFFECT: |
|
866 | SIDE EFFECT: | |
867 |
|
867 | |||
868 | 1) fclnodes gets populated with the list of relevant |
|
868 | 1) fclnodes gets populated with the list of relevant | |
869 | file nodes if we're not using fastpathlinkrev |
|
869 | file nodes if we're not using fastpathlinkrev | |
870 | 2) When treemanifests are in use, collects treemanifest nodes |
|
870 | 2) When treemanifests are in use, collects treemanifest nodes | |
871 | to send |
|
871 | to send | |
872 |
|
872 | |||
873 | Note that this means manifests must be completely sent to |
|
873 | Note that this means manifests must be completely sent to | |
874 | the client before you can trust the list of files and |
|
874 | the client before you can trust the list of files and | |
875 | treemanifests to send. |
|
875 | treemanifests to send. | |
876 | """ |
|
876 | """ | |
877 | clnode = nodes[x] |
|
877 | clnode = nodes[x] | |
878 | mdata = mfl.get(dir, x).readfast(shallow=True) |
|
878 | mdata = mfl.get(dir, x).readfast(shallow=True) | |
879 | for p, n, fl in mdata.iterentries(): |
|
879 | for p, n, fl in mdata.iterentries(): | |
880 | if fl == 't': # subdirectory manifest |
|
880 | if fl == 't': # subdirectory manifest | |
881 | subdir = dir + p + '/' |
|
881 | subdir = dir + p + '/' | |
882 | tmfclnodes = tmfnodes.setdefault(subdir, {}) |
|
882 | tmfclnodes = tmfnodes.setdefault(subdir, {}) | |
883 | tmfclnode = tmfclnodes.setdefault(n, clnode) |
|
883 | tmfclnode = tmfclnodes.setdefault(n, clnode) | |
884 | if clrevorder[clnode] < clrevorder[tmfclnode]: |
|
884 | if clrevorder[clnode] < clrevorder[tmfclnode]: | |
885 | tmfclnodes[n] = clnode |
|
885 | tmfclnodes[n] = clnode | |
886 | else: |
|
886 | else: | |
887 | f = dir + p |
|
887 | f = dir + p | |
888 | fclnodes = fnodes.setdefault(f, {}) |
|
888 | fclnodes = fnodes.setdefault(f, {}) | |
889 | fclnode = fclnodes.setdefault(n, clnode) |
|
889 | fclnode = fclnodes.setdefault(n, clnode) | |
890 | if clrevorder[clnode] < clrevorder[fclnode]: |
|
890 | if clrevorder[clnode] < clrevorder[fclnode]: | |
891 | fclnodes[n] = clnode |
|
891 | fclnodes[n] = clnode | |
892 | return clnode |
|
892 | return clnode | |
893 | return lookupmflinknode |
|
893 | return lookupmflinknode | |
894 |
|
894 | |||
895 | size = 0 |
|
895 | size = 0 | |
896 | while tmfnodes: |
|
896 | while tmfnodes: | |
897 | dir, nodes = tmfnodes.popitem() |
|
897 | dir, nodes = tmfnodes.popitem() | |
898 | prunednodes = self._prune(dirlog(dir), nodes, commonrevs) |
|
898 | prunednodes = self._prune(dirlog(dir), nodes, commonrevs) | |
899 | if not dir or prunednodes: |
|
899 | if not dir or prunednodes: | |
900 | for x in self._packmanifests(dir, prunednodes, |
|
900 | for x in self._packmanifests(dir, prunednodes, | |
901 | makelookupmflinknode(dir, nodes)): |
|
901 | makelookupmflinknode(dir, nodes)): | |
902 | size += len(x) |
|
902 | size += len(x) | |
903 | yield x |
|
903 | yield x | |
904 | self._verbosenote(_('%8.i (manifests)\n') % size) |
|
904 | self._verbosenote(_('%8.i (manifests)\n') % size) | |
905 | yield self._manifestsend |
|
905 | yield self._manifestsend | |
906 |
|
906 | |||
907 | # The 'source' parameter is useful for extensions |
|
907 | # The 'source' parameter is useful for extensions | |
908 | def generatefiles(self, changedfiles, linknodes, commonrevs, source): |
|
908 | def generatefiles(self, changedfiles, linknodes, commonrevs, source): | |
909 | changedfiles = list(filter(self._filematcher, changedfiles)) |
|
909 | changedfiles = list(filter(self._filematcher, changedfiles)) | |
910 |
|
910 | |||
911 | if self._isshallow: |
|
911 | if self._isshallow: | |
912 | # See comment in generate() for why this sadness is a thing. |
|
912 | # See comment in generate() for why this sadness is a thing. | |
913 | mfdicts = self._mfdicts |
|
913 | mfdicts = self._mfdicts | |
914 | del self._mfdicts |
|
914 | del self._mfdicts | |
915 | # In a shallow clone, the linknodes callback needs to also include |
|
915 | # In a shallow clone, the linknodes callback needs to also include | |
916 | # those file nodes that are in the manifests we sent but weren't |
|
916 | # those file nodes that are in the manifests we sent but weren't | |
917 | # introduced by those manifests. |
|
917 | # introduced by those manifests. | |
918 | commonctxs = [self._repo[c] for c in commonrevs] |
|
918 | commonctxs = [self._repo[c] for c in commonrevs] | |
919 | oldlinknodes = linknodes |
|
919 | oldlinknodes = linknodes | |
920 | clrev = self._repo.changelog.rev |
|
920 | clrev = self._repo.changelog.rev | |
921 |
|
921 | |||
922 | # Defining this function has a side-effect of overriding the |
|
922 | # Defining this function has a side-effect of overriding the | |
923 | # function of the same name that was passed in as an argument. |
|
923 | # function of the same name that was passed in as an argument. | |
924 | # TODO have caller pass in appropriate function. |
|
924 | # TODO have caller pass in appropriate function. | |
925 | def linknodes(flog, fname): |
|
925 | def linknodes(flog, fname): | |
926 | for c in commonctxs: |
|
926 | for c in commonctxs: | |
927 | try: |
|
927 | try: | |
928 | fnode = c.filenode(fname) |
|
928 | fnode = c.filenode(fname) | |
929 | self._clrevtolocalrev[c.rev()] = flog.rev(fnode) |
|
929 | self._clrevtolocalrev[c.rev()] = flog.rev(fnode) | |
930 | except error.ManifestLookupError: |
|
930 | except error.ManifestLookupError: | |
931 | pass |
|
931 | pass | |
932 | links = oldlinknodes(flog, fname) |
|
932 | links = oldlinknodes(flog, fname) | |
933 | if len(links) != len(mfdicts): |
|
933 | if len(links) != len(mfdicts): | |
934 | for mf, lr in mfdicts: |
|
934 | for mf, lr in mfdicts: | |
935 | fnode = mf.get(fname, None) |
|
935 | fnode = mf.get(fname, None) | |
936 | if fnode in links: |
|
936 | if fnode in links: | |
937 | links[fnode] = min(links[fnode], lr, key=clrev) |
|
937 | links[fnode] = min(links[fnode], lr, key=clrev) | |
938 | elif fnode: |
|
938 | elif fnode: | |
939 | links[fnode] = lr |
|
939 | links[fnode] = lr | |
940 | return links |
|
940 | return links | |
941 |
|
941 | |||
942 | return self._generatefiles(changedfiles, linknodes, commonrevs, source) |
|
942 | return self._generatefiles(changedfiles, linknodes, commonrevs, source) | |
943 |
|
943 | |||
944 | def _generatefiles(self, changedfiles, linknodes, commonrevs, source): |
|
944 | def _generatefiles(self, changedfiles, linknodes, commonrevs, source): | |
945 | repo = self._repo |
|
945 | repo = self._repo | |
946 | progress = repo.ui.makeprogress(_('bundling'), unit=_('files'), |
|
946 | progress = repo.ui.makeprogress(_('bundling'), unit=_('files'), | |
947 | total=len(changedfiles)) |
|
947 | total=len(changedfiles)) | |
948 | for i, fname in enumerate(sorted(changedfiles)): |
|
948 | for i, fname in enumerate(sorted(changedfiles)): | |
949 | filerevlog = repo.file(fname) |
|
949 | filerevlog = repo.file(fname) | |
950 | if not filerevlog: |
|
950 | if not filerevlog: | |
951 | raise error.Abort(_("empty or missing file data for %s") % |
|
951 | raise error.Abort(_("empty or missing file data for %s") % | |
952 | fname) |
|
952 | fname) | |
953 |
|
953 | |||
954 | linkrevnodes = linknodes(filerevlog, fname) |
|
954 | linkrevnodes = linknodes(filerevlog, fname) | |
955 | # Lookup for filenodes, we collected the linkrev nodes above in the |
|
955 | # Lookup for filenodes, we collected the linkrev nodes above in the | |
956 | # fastpath case and with lookupmf in the slowpath case. |
|
956 | # fastpath case and with lookupmf in the slowpath case. | |
957 | def lookupfilelog(x): |
|
957 | def lookupfilelog(x): | |
958 | return linkrevnodes[x] |
|
958 | return linkrevnodes[x] | |
959 |
|
959 | |||
960 | filenodes = self._prune(filerevlog, linkrevnodes, commonrevs) |
|
960 | filenodes = self._prune(filerevlog, linkrevnodes, commonrevs) | |
961 | if filenodes: |
|
961 | if filenodes: | |
962 | progress.update(i + 1, item=fname) |
|
962 | progress.update(i + 1, item=fname) | |
963 | h = self._fileheader(fname) |
|
963 | h = self._fileheader(fname) | |
964 | size = len(h) |
|
964 | size = len(h) | |
965 | yield h |
|
965 | yield h | |
966 | for chunk in self.group(filenodes, filerevlog, lookupfilelog): |
|
966 | for chunk in self.group(filenodes, filerevlog, lookupfilelog): | |
967 | size += len(chunk) |
|
967 | size += len(chunk) | |
968 | yield chunk |
|
968 | yield chunk | |
969 | self._verbosenote(_('%8.i %s\n') % (size, fname)) |
|
969 | self._verbosenote(_('%8.i %s\n') % (size, fname)) | |
970 | progress.complete() |
|
970 | progress.complete() | |
971 |
|
971 | |||
972 | def _deltaparent(self, store, rev, p1, p2, prev): |
|
972 | def _deltaparent(self, store, rev, p1, p2, prev): | |
973 | if self._useprevdelta: |
|
973 | if self._useprevdelta: | |
974 | if not store.candelta(prev, rev): |
|
974 | if not store.candelta(prev, rev): | |
975 | raise error.ProgrammingError( |
|
975 | raise error.ProgrammingError( | |
976 | 'cg1 should not be used in this case') |
|
976 | 'cg1 should not be used in this case') | |
977 | return prev |
|
977 | return prev | |
978 |
|
978 | |||
979 | # Narrow ellipses mode. |
|
979 | # Narrow ellipses mode. | |
980 | if self._ellipses: |
|
980 | if self._ellipses: | |
981 | # TODO: send better deltas when in narrow mode. |
|
981 | # TODO: send better deltas when in narrow mode. | |
982 | # |
|
982 | # | |
983 | # changegroup.group() loops over revisions to send, |
|
983 | # changegroup.group() loops over revisions to send, | |
984 | # including revisions we'll skip. What this means is that |
|
984 | # including revisions we'll skip. What this means is that | |
985 | # `prev` will be a potentially useless delta base for all |
|
985 | # `prev` will be a potentially useless delta base for all | |
986 | # ellipsis nodes, as the client likely won't have it. In |
|
986 | # ellipsis nodes, as the client likely won't have it. In | |
987 | # the future we should do bookkeeping about which nodes |
|
987 | # the future we should do bookkeeping about which nodes | |
988 | # have been sent to the client, and try to be |
|
988 | # have been sent to the client, and try to be | |
989 | # significantly smarter about delta bases. This is |
|
989 | # significantly smarter about delta bases. This is | |
990 | # slightly tricky because this same code has to work for |
|
990 | # slightly tricky because this same code has to work for | |
991 | # all revlogs, and we don't have the linkrev/linknode here. |
|
991 | # all revlogs, and we don't have the linkrev/linknode here. | |
992 | return p1 |
|
992 | return p1 | |
993 |
|
993 | |||
994 | dp = store.deltaparent(rev) |
|
994 | dp = store.deltaparent(rev) | |
995 | if dp == nullrev and store.storedeltachains: |
|
995 | if dp == nullrev and store.storedeltachains: | |
996 | # Avoid sending full revisions when delta parent is null. Pick prev |
|
996 | # Avoid sending full revisions when delta parent is null. Pick prev | |
997 | # in that case. It's tempting to pick p1 in this case, as p1 will |
|
997 | # in that case. It's tempting to pick p1 in this case, as p1 will | |
998 | # be smaller in the common case. However, computing a delta against |
|
998 | # be smaller in the common case. However, computing a delta against | |
999 | # p1 may require resolving the raw text of p1, which could be |
|
999 | # p1 may require resolving the raw text of p1, which could be | |
1000 | # expensive. The revlog caches should have prev cached, meaning |
|
1000 | # expensive. The revlog caches should have prev cached, meaning | |
1001 | # less CPU for changegroup generation. There is likely room to add |
|
1001 | # less CPU for changegroup generation. There is likely room to add | |
1002 | # a flag and/or config option to control this behavior. |
|
1002 | # a flag and/or config option to control this behavior. | |
1003 | base = prev |
|
1003 | base = prev | |
1004 | elif dp == nullrev: |
|
1004 | elif dp == nullrev: | |
1005 | # revlog is configured to use full snapshot for a reason, |
|
1005 | # revlog is configured to use full snapshot for a reason, | |
1006 | # stick to full snapshot. |
|
1006 | # stick to full snapshot. | |
1007 | base = nullrev |
|
1007 | base = nullrev | |
1008 | elif dp not in (p1, p2, prev): |
|
1008 | elif dp not in (p1, p2, prev): | |
1009 | # Pick prev when we can't be sure remote has the base revision. |
|
1009 | # Pick prev when we can't be sure remote has the base revision. | |
1010 | return prev |
|
1010 | return prev | |
1011 | else: |
|
1011 | else: | |
1012 | base = dp |
|
1012 | base = dp | |
1013 |
|
1013 | |||
1014 | if base != nullrev and not store.candelta(base, rev): |
|
1014 | if base != nullrev and not store.candelta(base, rev): | |
1015 | base = nullrev |
|
1015 | base = nullrev | |
1016 |
|
1016 | |||
1017 | return base |
|
1017 | return base | |
1018 |
|
1018 | |||
1019 | def _revchunk(self, store, rev, prev, linknode): |
|
1019 | def _revchunk(self, store, rev, prev, linknode): | |
1020 | if self._ellipses: |
|
1020 | if self._ellipses: | |
1021 | fn = self._revisiondeltanarrow |
|
1021 | fn = self._revisiondeltanarrow | |
1022 | else: |
|
1022 | else: | |
1023 | fn = self._revisiondeltanormal |
|
1023 | fn = self._revisiondeltanormal | |
1024 |
|
1024 | |||
1025 | delta = fn(store, rev, prev, linknode) |
|
1025 | delta = fn(store, rev, prev, linknode) | |
1026 | if not delta: |
|
1026 | if not delta: | |
1027 | return |
|
1027 | return | |
1028 |
|
1028 | |||
1029 | meta = self._builddeltaheader(delta) |
|
1029 | meta = self._builddeltaheader(delta) | |
1030 | l = len(meta) + sum(len(x) for x in delta.deltachunks) |
|
1030 | l = len(meta) + sum(len(x) for x in delta.deltachunks) | |
1031 |
|
1031 | |||
1032 | yield chunkheader(l) |
|
1032 | yield chunkheader(l) | |
1033 | yield meta |
|
1033 | yield meta | |
1034 | for x in delta.deltachunks: |
|
1034 | for x in delta.deltachunks: | |
1035 | yield x |
|
1035 | yield x | |
1036 |
|
1036 | |||
1037 | def _revisiondeltanormal(self, store, rev, prev, linknode): |
|
1037 | def _revisiondeltanormal(self, store, rev, prev, linknode): | |
1038 | node = store.node(rev) |
|
1038 | node = store.node(rev) | |
1039 | p1, p2 = store.parentrevs(rev) |
|
1039 | p1, p2 = store.parentrevs(rev) | |
1040 | base = self._deltaparent(store, rev, p1, p2, prev) |
|
1040 | base = self._deltaparent(store, rev, p1, p2, prev) | |
1041 |
|
1041 | |||
1042 | prefix = '' |
|
1042 | prefix = '' | |
1043 | if store.iscensored(base) or store.iscensored(rev): |
|
1043 | if store.iscensored(base) or store.iscensored(rev): | |
1044 | try: |
|
1044 | try: | |
1045 | delta = store.revision(node, raw=True) |
|
1045 | delta = store.revision(node, raw=True) | |
1046 | except error.CensoredNodeError as e: |
|
1046 | except error.CensoredNodeError as e: | |
1047 | delta = e.tombstone |
|
1047 | delta = e.tombstone | |
1048 | if base == nullrev: |
|
1048 | if base == nullrev: | |
1049 | prefix = mdiff.trivialdiffheader(len(delta)) |
|
1049 | prefix = mdiff.trivialdiffheader(len(delta)) | |
1050 | else: |
|
1050 | else: | |
1051 | baselen = store.rawsize(base) |
|
1051 | baselen = store.rawsize(base) | |
1052 | prefix = mdiff.replacediffheader(baselen, len(delta)) |
|
1052 | prefix = mdiff.replacediffheader(baselen, len(delta)) | |
1053 | elif base == nullrev: |
|
1053 | elif base == nullrev: | |
1054 | delta = store.revision(node, raw=True) |
|
1054 | delta = store.revision(node, raw=True) | |
1055 | prefix = mdiff.trivialdiffheader(len(delta)) |
|
1055 | prefix = mdiff.trivialdiffheader(len(delta)) | |
1056 | else: |
|
1056 | else: | |
1057 | delta = store.revdiff(base, rev) |
|
1057 | delta = store.revdiff(base, rev) | |
1058 | p1n, p2n = store.parents(node) |
|
1058 | p1n, p2n = store.parents(node) | |
1059 |
|
1059 | |||
1060 | return revisiondelta( |
|
1060 | return revisiondelta( | |
1061 | node=node, |
|
1061 | node=node, | |
1062 | p1node=p1n, |
|
1062 | p1node=p1n, | |
1063 | p2node=p2n, |
|
1063 | p2node=p2n, | |
1064 | basenode=store.node(base), |
|
1064 | basenode=store.node(base), | |
1065 | linknode=linknode, |
|
1065 | linknode=linknode, | |
1066 | flags=store.flags(rev), |
|
1066 | flags=store.flags(rev), | |
1067 | deltachunks=(prefix, delta), |
|
1067 | deltachunks=(prefix, delta), | |
1068 | ) |
|
1068 | ) | |
1069 |
|
1069 | |||
1070 | def _revisiondeltanarrow(self, store, rev, prev, linknode): |
|
1070 | def _revisiondeltanarrow(self, store, rev, prev, linknode): | |
1071 | # build up some mapping information that's useful later. See |
|
1071 | # build up some mapping information that's useful later. See | |
1072 | # the local() nested function below. |
|
1072 | # the local() nested function below. | |
1073 | if not self._changelogdone: |
|
1073 | if not self._changelogdone: | |
1074 | self._clnodetorev[linknode] = rev |
|
1074 | self._clnodetorev[linknode] = rev | |
1075 | linkrev = rev |
|
1075 | linkrev = rev | |
1076 | self._clrevtolocalrev[linkrev] = rev |
|
1076 | self._clrevtolocalrev[linkrev] = rev | |
1077 | else: |
|
1077 | else: | |
1078 | linkrev = self._clnodetorev[linknode] |
|
1078 | linkrev = self._clnodetorev[linknode] | |
1079 | self._clrevtolocalrev[linkrev] = rev |
|
1079 | self._clrevtolocalrev[linkrev] = rev | |
1080 |
|
1080 | |||
1081 | # This is a node to send in full, because the changeset it |
|
1081 | # This is a node to send in full, because the changeset it | |
1082 | # corresponds to was a full changeset. |
|
1082 | # corresponds to was a full changeset. | |
1083 | if linknode in self._fullnodes: |
|
1083 | if linknode in self._fullnodes: | |
1084 | return self._revisiondeltanormal(store, rev, prev, linknode) |
|
1084 | return self._revisiondeltanormal(store, rev, prev, linknode) | |
1085 |
|
1085 | |||
1086 | # At this point, a node can either be one we should skip or an |
|
1086 | # At this point, a node can either be one we should skip or an | |
1087 | # ellipsis. If it's not an ellipsis, bail immediately. |
|
1087 | # ellipsis. If it's not an ellipsis, bail immediately. | |
1088 | if linkrev not in self._precomputedellipsis: |
|
1088 | if linkrev not in self._precomputedellipsis: | |
1089 | return |
|
1089 | return | |
1090 |
|
1090 | |||
1091 | linkparents = self._precomputedellipsis[linkrev] |
|
1091 | linkparents = self._precomputedellipsis[linkrev] | |
1092 | def local(clrev): |
|
1092 | def local(clrev): | |
1093 | """Turn a changelog revnum into a local revnum. |
|
1093 | """Turn a changelog revnum into a local revnum. | |
1094 |
|
1094 | |||
1095 | The ellipsis dag is stored as revnums on the changelog, |
|
1095 | The ellipsis dag is stored as revnums on the changelog, | |
1096 | but when we're producing ellipsis entries for |
|
1096 | but when we're producing ellipsis entries for | |
1097 | non-changelog revlogs, we need to turn those numbers into |
|
1097 | non-changelog revlogs, we need to turn those numbers into | |
1098 | something local. This does that for us, and during the |
|
1098 | something local. This does that for us, and during the | |
1099 | changelog sending phase will also expand the stored |
|
1099 | changelog sending phase will also expand the stored | |
1100 | mappings as needed. |
|
1100 | mappings as needed. | |
1101 | """ |
|
1101 | """ | |
1102 | if clrev == nullrev: |
|
1102 | if clrev == nullrev: | |
1103 | return nullrev |
|
1103 | return nullrev | |
1104 |
|
1104 | |||
1105 | if not self._changelogdone: |
|
1105 | if not self._changelogdone: | |
1106 | # If we're doing the changelog, it's possible that we |
|
1106 | # If we're doing the changelog, it's possible that we | |
1107 | # have a parent that is already on the client, and we |
|
1107 | # have a parent that is already on the client, and we | |
1108 | # need to store some extra mapping information so that |
|
1108 | # need to store some extra mapping information so that | |
1109 | # our contained ellipsis nodes will be able to resolve |
|
1109 | # our contained ellipsis nodes will be able to resolve | |
1110 | # their parents. |
|
1110 | # their parents. | |
1111 | if clrev not in self._clrevtolocalrev: |
|
1111 | if clrev not in self._clrevtolocalrev: | |
1112 | clnode = store.node(clrev) |
|
1112 | clnode = store.node(clrev) | |
1113 | self._clnodetorev[clnode] = clrev |
|
1113 | self._clnodetorev[clnode] = clrev | |
1114 | return clrev |
|
1114 | return clrev | |
1115 |
|
1115 | |||
1116 | # Walk the ellipsis-ized changelog breadth-first looking for a |
|
1116 | # Walk the ellipsis-ized changelog breadth-first looking for a | |
1117 | # change that has been linked from the current revlog. |
|
1117 | # change that has been linked from the current revlog. | |
1118 | # |
|
1118 | # | |
1119 | # For a flat manifest revlog only a single step should be necessary |
|
1119 | # For a flat manifest revlog only a single step should be necessary | |
1120 | # as all relevant changelog entries are relevant to the flat |
|
1120 | # as all relevant changelog entries are relevant to the flat | |
1121 | # manifest. |
|
1121 | # manifest. | |
1122 | # |
|
1122 | # | |
1123 | # For a filelog or tree manifest dirlog however not every changelog |
|
1123 | # For a filelog or tree manifest dirlog however not every changelog | |
1124 | # entry will have been relevant, so we need to skip some changelog |
|
1124 | # entry will have been relevant, so we need to skip some changelog | |
1125 | # nodes even after ellipsis-izing. |
|
1125 | # nodes even after ellipsis-izing. | |
1126 | walk = [clrev] |
|
1126 | walk = [clrev] | |
1127 | while walk: |
|
1127 | while walk: | |
1128 | p = walk[0] |
|
1128 | p = walk[0] | |
1129 | walk = walk[1:] |
|
1129 | walk = walk[1:] | |
1130 | if p in self._clrevtolocalrev: |
|
1130 | if p in self._clrevtolocalrev: | |
1131 | return self._clrevtolocalrev[p] |
|
1131 | return self._clrevtolocalrev[p] | |
1132 | elif p in self._fullnodes: |
|
1132 | elif p in self._fullnodes: | |
1133 | walk.extend([pp for pp in self._repo.changelog.parentrevs(p) |
|
1133 | walk.extend([pp for pp in self._repo.changelog.parentrevs(p) | |
1134 | if pp != nullrev]) |
|
1134 | if pp != nullrev]) | |
1135 | elif p in self._precomputedellipsis: |
|
1135 | elif p in self._precomputedellipsis: | |
1136 | walk.extend([pp for pp in self._precomputedellipsis[p] |
|
1136 | walk.extend([pp for pp in self._precomputedellipsis[p] | |
1137 | if pp != nullrev]) |
|
1137 | if pp != nullrev]) | |
1138 | else: |
|
1138 | else: | |
1139 | # In this case, we've got an ellipsis with parents |
|
1139 | # In this case, we've got an ellipsis with parents | |
1140 | # outside the current bundle (likely an |
|
1140 | # outside the current bundle (likely an | |
1141 | # incremental pull). We "know" that we can use the |
|
1141 | # incremental pull). We "know" that we can use the | |
1142 | # value of this same revlog at whatever revision |
|
1142 | # value of this same revlog at whatever revision | |
1143 | # is pointed to by linknode. "Know" is in scare |
|
1143 | # is pointed to by linknode. "Know" is in scare | |
1144 | # quotes because I haven't done enough examination |
|
1144 | # quotes because I haven't done enough examination | |
1145 | # of edge cases to convince myself this is really |
|
1145 | # of edge cases to convince myself this is really | |
1146 | # a fact - it works for all the (admittedly |
|
1146 | # a fact - it works for all the (admittedly | |
1147 | # thorough) cases in our testsuite, but I would be |
|
1147 | # thorough) cases in our testsuite, but I would be | |
1148 | # somewhat unsurprised to find a case in the wild |
|
1148 | # somewhat unsurprised to find a case in the wild | |
1149 | # where this breaks down a bit. That said, I don't |
|
1149 | # where this breaks down a bit. That said, I don't | |
1150 | # know if it would hurt anything. |
|
1150 | # know if it would hurt anything. | |
1151 | for i in pycompat.xrange(rev, 0, -1): |
|
1151 | for i in pycompat.xrange(rev, 0, -1): | |
1152 | if store.linkrev(i) == clrev: |
|
1152 | if store.linkrev(i) == clrev: | |
1153 | return i |
|
1153 | return i | |
1154 | # We failed to resolve a parent for this node, so |
|
1154 | # We failed to resolve a parent for this node, so | |
1155 | # we crash the changegroup construction. |
|
1155 | # we crash the changegroup construction. | |
1156 | raise error.Abort( |
|
1156 | raise error.Abort( | |
1157 | 'unable to resolve parent while packing %r %r' |
|
1157 | 'unable to resolve parent while packing %r %r' | |
1158 | ' for changeset %r' % (store.indexfile, rev, clrev)) |
|
1158 | ' for changeset %r' % (store.indexfile, rev, clrev)) | |
1159 |
|
1159 | |||
1160 | return nullrev |
|
1160 | return nullrev | |
1161 |
|
1161 | |||
1162 | if not linkparents or ( |
|
1162 | if not linkparents or ( | |
1163 | store.parentrevs(rev) == (nullrev, nullrev)): |
|
1163 | store.parentrevs(rev) == (nullrev, nullrev)): | |
1164 | p1, p2 = nullrev, nullrev |
|
1164 | p1, p2 = nullrev, nullrev | |
1165 | elif len(linkparents) == 1: |
|
1165 | elif len(linkparents) == 1: | |
1166 | p1, = sorted(local(p) for p in linkparents) |
|
1166 | p1, = sorted(local(p) for p in linkparents) | |
1167 | p2 = nullrev |
|
1167 | p2 = nullrev | |
1168 | else: |
|
1168 | else: | |
1169 | p1, p2 = sorted(local(p) for p in linkparents) |
|
1169 | p1, p2 = sorted(local(p) for p in linkparents) | |
1170 |
|
1170 | |||
1171 | n = store.node(rev) |
|
1171 | n = store.node(rev) | |
1172 | p1n, p2n = store.node(p1), store.node(p2) |
|
1172 | p1n, p2n = store.node(p1), store.node(p2) | |
1173 | flags = store.flags(rev) |
|
1173 | flags = store.flags(rev) | |
1174 | flags |= revlog.REVIDX_ELLIPSIS |
|
1174 | flags |= revlog.REVIDX_ELLIPSIS | |
1175 |
|
1175 | |||
1176 | # TODO: try and actually send deltas for ellipsis data blocks |
|
1176 | # TODO: try and actually send deltas for ellipsis data blocks | |
1177 | data = store.revision(n) |
|
1177 | data = store.revision(n) | |
1178 | diffheader = mdiff.trivialdiffheader(len(data)) |
|
1178 | diffheader = mdiff.trivialdiffheader(len(data)) | |
1179 |
|
1179 | |||
1180 | return revisiondelta( |
|
1180 | return revisiondelta( | |
1181 | node=n, |
|
1181 | node=n, | |
1182 | p1node=p1n, |
|
1182 | p1node=p1n, | |
1183 | p2node=p2n, |
|
1183 | p2node=p2n, | |
1184 | basenode=nullid, |
|
1184 | basenode=nullid, | |
1185 | linknode=linknode, |
|
1185 | linknode=linknode, | |
1186 | flags=flags, |
|
1186 | flags=flags, | |
1187 | deltachunks=(diffheader, data), |
|
1187 | deltachunks=(diffheader, data), | |
1188 | ) |
|
1188 | ) | |
1189 |
|
1189 | |||
1190 | def _makecg1packer(repo, filematcher, bundlecaps, ellipses=False, |
|
1190 | def _makecg1packer(repo, filematcher, bundlecaps, ellipses=False, | |
1191 | shallow=False, ellipsisroots=None, fullnodes=None): |
|
1191 | shallow=False, ellipsisroots=None, fullnodes=None): | |
1192 | builddeltaheader = lambda d: _CHANGEGROUPV1_DELTA_HEADER.pack( |
|
1192 | builddeltaheader = lambda d: _CHANGEGROUPV1_DELTA_HEADER.pack( | |
1193 | d.node, d.p1node, d.p2node, d.linknode) |
|
1193 | d.node, d.p1node, d.p2node, d.linknode) | |
1194 |
|
1194 | |||
1195 | return cgpacker(repo, filematcher, b'01', |
|
1195 | return cgpacker(repo, filematcher, b'01', | |
1196 | useprevdelta=True, |
|
1196 | useprevdelta=True, | |
1197 | allowreorder=None, |
|
1197 | allowreorder=None, | |
1198 | builddeltaheader=builddeltaheader, |
|
1198 | builddeltaheader=builddeltaheader, | |
1199 | manifestsend=b'', |
|
1199 | manifestsend=b'', | |
1200 | bundlecaps=bundlecaps, |
|
1200 | bundlecaps=bundlecaps, | |
1201 | ellipses=ellipses, |
|
1201 | ellipses=ellipses, | |
1202 | shallow=shallow, |
|
1202 | shallow=shallow, | |
1203 | ellipsisroots=ellipsisroots, |
|
1203 | ellipsisroots=ellipsisroots, | |
1204 | fullnodes=fullnodes) |
|
1204 | fullnodes=fullnodes) | |
1205 |
|
1205 | |||
1206 | def _makecg2packer(repo, filematcher, bundlecaps, ellipses=False, |
|
1206 | def _makecg2packer(repo, filematcher, bundlecaps, ellipses=False, | |
1207 | shallow=False, ellipsisroots=None, fullnodes=None): |
|
1207 | shallow=False, ellipsisroots=None, fullnodes=None): | |
1208 | builddeltaheader = lambda d: _CHANGEGROUPV2_DELTA_HEADER.pack( |
|
1208 | builddeltaheader = lambda d: _CHANGEGROUPV2_DELTA_HEADER.pack( | |
1209 | d.node, d.p1node, d.p2node, d.basenode, d.linknode) |
|
1209 | d.node, d.p1node, d.p2node, d.basenode, d.linknode) | |
1210 |
|
1210 | |||
1211 | # Since generaldelta is directly supported by cg2, reordering |
|
1211 | # Since generaldelta is directly supported by cg2, reordering | |
1212 | # generally doesn't help, so we disable it by default (treating |
|
1212 | # generally doesn't help, so we disable it by default (treating | |
1213 | # bundle.reorder=auto just like bundle.reorder=False). |
|
1213 | # bundle.reorder=auto just like bundle.reorder=False). | |
1214 | return cgpacker(repo, filematcher, b'02', |
|
1214 | return cgpacker(repo, filematcher, b'02', | |
1215 | useprevdelta=False, |
|
1215 | useprevdelta=False, | |
1216 | allowreorder=False, |
|
1216 | allowreorder=False, | |
1217 | builddeltaheader=builddeltaheader, |
|
1217 | builddeltaheader=builddeltaheader, | |
1218 | manifestsend=b'', |
|
1218 | manifestsend=b'', | |
1219 | bundlecaps=bundlecaps, |
|
1219 | bundlecaps=bundlecaps, | |
1220 | ellipses=ellipses, |
|
1220 | ellipses=ellipses, | |
1221 | shallow=shallow, |
|
1221 | shallow=shallow, | |
1222 | ellipsisroots=ellipsisroots, |
|
1222 | ellipsisroots=ellipsisroots, | |
1223 | fullnodes=fullnodes) |
|
1223 | fullnodes=fullnodes) | |
1224 |
|
1224 | |||
1225 | def _makecg3packer(repo, filematcher, bundlecaps, ellipses=False, |
|
1225 | def _makecg3packer(repo, filematcher, bundlecaps, ellipses=False, | |
1226 | shallow=False, ellipsisroots=None, fullnodes=None): |
|
1226 | shallow=False, ellipsisroots=None, fullnodes=None): | |
1227 | builddeltaheader = lambda d: _CHANGEGROUPV3_DELTA_HEADER.pack( |
|
1227 | builddeltaheader = lambda d: _CHANGEGROUPV3_DELTA_HEADER.pack( | |
1228 | d.node, d.p1node, d.p2node, d.basenode, d.linknode, d.flags) |
|
1228 | d.node, d.p1node, d.p2node, d.basenode, d.linknode, d.flags) | |
1229 |
|
1229 | |||
1230 | return cgpacker(repo, filematcher, b'03', |
|
1230 | return cgpacker(repo, filematcher, b'03', | |
1231 | useprevdelta=False, |
|
1231 | useprevdelta=False, | |
1232 | allowreorder=False, |
|
1232 | allowreorder=False, | |
1233 | builddeltaheader=builddeltaheader, |
|
1233 | builddeltaheader=builddeltaheader, | |
1234 | manifestsend=closechunk(), |
|
1234 | manifestsend=closechunk(), | |
1235 | bundlecaps=bundlecaps, |
|
1235 | bundlecaps=bundlecaps, | |
1236 | ellipses=ellipses, |
|
1236 | ellipses=ellipses, | |
1237 | shallow=shallow, |
|
1237 | shallow=shallow, | |
1238 | ellipsisroots=ellipsisroots, |
|
1238 | ellipsisroots=ellipsisroots, | |
1239 | fullnodes=fullnodes) |
|
1239 | fullnodes=fullnodes) | |
1240 |
|
1240 | |||
1241 | _packermap = {'01': (_makecg1packer, cg1unpacker), |
|
1241 | _packermap = {'01': (_makecg1packer, cg1unpacker), | |
1242 | # cg2 adds support for exchanging generaldelta |
|
1242 | # cg2 adds support for exchanging generaldelta | |
1243 | '02': (_makecg2packer, cg2unpacker), |
|
1243 | '02': (_makecg2packer, cg2unpacker), | |
1244 | # cg3 adds support for exchanging revlog flags and treemanifests |
|
1244 | # cg3 adds support for exchanging revlog flags and treemanifests | |
1245 | '03': (_makecg3packer, cg3unpacker), |
|
1245 | '03': (_makecg3packer, cg3unpacker), | |
1246 | } |
|
1246 | } | |
1247 |
|
1247 | |||
1248 | def allsupportedversions(repo): |
|
1248 | def allsupportedversions(repo): | |
1249 | versions = set(_packermap.keys()) |
|
1249 | versions = set(_packermap.keys()) | |
1250 | if not (repo.ui.configbool('experimental', 'changegroup3') or |
|
1250 | if not (repo.ui.configbool('experimental', 'changegroup3') or | |
1251 | repo.ui.configbool('experimental', 'treemanifest') or |
|
1251 | repo.ui.configbool('experimental', 'treemanifest') or | |
1252 | 'treemanifest' in repo.requirements): |
|
1252 | 'treemanifest' in repo.requirements): | |
1253 | versions.discard('03') |
|
1253 | versions.discard('03') | |
1254 | return versions |
|
1254 | return versions | |
1255 |
|
1255 | |||
1256 | # Changegroup versions that can be applied to the repo |
|
1256 | # Changegroup versions that can be applied to the repo | |
1257 | def supportedincomingversions(repo): |
|
1257 | def supportedincomingversions(repo): | |
1258 | return allsupportedversions(repo) |
|
1258 | return allsupportedversions(repo) | |
1259 |
|
1259 | |||
1260 | # Changegroup versions that can be created from the repo |
|
1260 | # Changegroup versions that can be created from the repo | |
1261 | def supportedoutgoingversions(repo): |
|
1261 | def supportedoutgoingversions(repo): | |
1262 | versions = allsupportedversions(repo) |
|
1262 | versions = allsupportedversions(repo) | |
1263 | if 'treemanifest' in repo.requirements: |
|
1263 | if 'treemanifest' in repo.requirements: | |
1264 | # Versions 01 and 02 support only flat manifests and it's just too |
|
1264 | # Versions 01 and 02 support only flat manifests and it's just too | |
1265 | # expensive to convert between the flat manifest and tree manifest on |
|
1265 | # expensive to convert between the flat manifest and tree manifest on | |
1266 | # the fly. Since tree manifests are hashed differently, all of history |
|
1266 | # the fly. Since tree manifests are hashed differently, all of history | |
1267 | # would have to be converted. Instead, we simply don't even pretend to |
|
1267 | # would have to be converted. Instead, we simply don't even pretend to | |
1268 | # support versions 01 and 02. |
|
1268 | # support versions 01 and 02. | |
1269 | versions.discard('01') |
|
1269 | versions.discard('01') | |
1270 | versions.discard('02') |
|
1270 | versions.discard('02') | |
1271 | if repository.NARROW_REQUIREMENT in repo.requirements: |
|
1271 | if repository.NARROW_REQUIREMENT in repo.requirements: | |
1272 | # Versions 01 and 02 don't support revlog flags, and we need to |
|
1272 | # Versions 01 and 02 don't support revlog flags, and we need to | |
1273 | # support that for stripping and unbundling to work. |
|
1273 | # support that for stripping and unbundling to work. | |
1274 | versions.discard('01') |
|
1274 | versions.discard('01') | |
1275 | versions.discard('02') |
|
1275 | versions.discard('02') | |
1276 | if LFS_REQUIREMENT in repo.requirements: |
|
1276 | if LFS_REQUIREMENT in repo.requirements: | |
1277 | # Versions 01 and 02 don't support revlog flags, and we need to |
|
1277 | # Versions 01 and 02 don't support revlog flags, and we need to | |
1278 | # mark LFS entries with REVIDX_EXTSTORED. |
|
1278 | # mark LFS entries with REVIDX_EXTSTORED. | |
1279 | versions.discard('01') |
|
1279 | versions.discard('01') | |
1280 | versions.discard('02') |
|
1280 | versions.discard('02') | |
1281 |
|
1281 | |||
1282 | return versions |
|
1282 | return versions | |
1283 |
|
1283 | |||
1284 | def localversion(repo): |
|
1284 | def localversion(repo): | |
1285 | # Finds the best version to use for bundles that are meant to be used |
|
1285 | # Finds the best version to use for bundles that are meant to be used | |
1286 | # locally, such as those from strip and shelve, and temporary bundles. |
|
1286 | # locally, such as those from strip and shelve, and temporary bundles. | |
1287 | return max(supportedoutgoingversions(repo)) |
|
1287 | return max(supportedoutgoingversions(repo)) | |
1288 |
|
1288 | |||
1289 | def safeversion(repo): |
|
1289 | def safeversion(repo): | |
1290 | # Finds the smallest version that it's safe to assume clients of the repo |
|
1290 | # Finds the smallest version that it's safe to assume clients of the repo | |
1291 | # will support. For example, all hg versions that support generaldelta also |
|
1291 | # will support. For example, all hg versions that support generaldelta also | |
1292 | # support changegroup 02. |
|
1292 | # support changegroup 02. | |
1293 | versions = supportedoutgoingversions(repo) |
|
1293 | versions = supportedoutgoingversions(repo) | |
1294 | if 'generaldelta' in repo.requirements: |
|
1294 | if 'generaldelta' in repo.requirements: | |
1295 | versions.discard('01') |
|
1295 | versions.discard('01') | |
1296 | assert versions |
|
1296 | assert versions | |
1297 | return min(versions) |
|
1297 | return min(versions) | |
1298 |
|
1298 | |||
1299 | def getbundler(version, repo, bundlecaps=None, filematcher=None, |
|
1299 | def getbundler(version, repo, bundlecaps=None, filematcher=None, | |
1300 | ellipses=False, shallow=False, ellipsisroots=None, |
|
1300 | ellipses=False, shallow=False, ellipsisroots=None, | |
1301 | fullnodes=None): |
|
1301 | fullnodes=None): | |
1302 | assert version in supportedoutgoingversions(repo) |
|
1302 | assert version in supportedoutgoingversions(repo) | |
1303 |
|
1303 | |||
1304 | if filematcher is None: |
|
1304 | if filematcher is None: | |
1305 | filematcher = matchmod.alwaysmatcher(repo.root, '') |
|
1305 | filematcher = matchmod.alwaysmatcher(repo.root, '') | |
1306 |
|
1306 | |||
1307 | if version == '01' and not filematcher.always(): |
|
1307 | if version == '01' and not filematcher.always(): | |
1308 | raise error.ProgrammingError('version 01 changegroups do not support ' |
|
1308 | raise error.ProgrammingError('version 01 changegroups do not support ' | |
1309 | 'sparse file matchers') |
|
1309 | 'sparse file matchers') | |
1310 |
|
1310 | |||
1311 | if ellipses and version in (b'01', b'02'): |
|
1311 | if ellipses and version in (b'01', b'02'): | |
1312 | raise error.Abort( |
|
1312 | raise error.Abort( | |
1313 | _('ellipsis nodes require at least cg3 on client and server, ' |
|
1313 | _('ellipsis nodes require at least cg3 on client and server, ' | |
1314 | 'but negotiated version %s') % version) |
|
1314 | 'but negotiated version %s') % version) | |
1315 |
|
1315 | |||
1316 | # Requested files could include files not in the local store. So |
|
1316 | # Requested files could include files not in the local store. So | |
1317 | # filter those out. |
|
1317 | # filter those out. | |
1318 | filematcher = matchmod.intersectmatchers(repo.narrowmatch(), |
|
1318 | filematcher = matchmod.intersectmatchers(repo.narrowmatch(), | |
1319 | filematcher) |
|
1319 | filematcher) | |
1320 |
|
1320 | |||
1321 | fn = _packermap[version][0] |
|
1321 | fn = _packermap[version][0] | |
1322 | return fn(repo, filematcher, bundlecaps, ellipses=ellipses, |
|
1322 | return fn(repo, filematcher, bundlecaps, ellipses=ellipses, | |
1323 | shallow=shallow, ellipsisroots=ellipsisroots, |
|
1323 | shallow=shallow, ellipsisroots=ellipsisroots, | |
1324 | fullnodes=fullnodes) |
|
1324 | fullnodes=fullnodes) | |
1325 |
|
1325 | |||
1326 | def getunbundler(version, fh, alg, extras=None): |
|
1326 | def getunbundler(version, fh, alg, extras=None): | |
1327 | return _packermap[version][1](fh, alg, extras=extras) |
|
1327 | return _packermap[version][1](fh, alg, extras=extras) | |
1328 |
|
1328 | |||
1329 | def _changegroupinfo(repo, nodes, source): |
|
1329 | def _changegroupinfo(repo, nodes, source): | |
1330 | if repo.ui.verbose or source == 'bundle': |
|
1330 | if repo.ui.verbose or source == 'bundle': | |
1331 | repo.ui.status(_("%d changesets found\n") % len(nodes)) |
|
1331 | repo.ui.status(_("%d changesets found\n") % len(nodes)) | |
1332 | if repo.ui.debugflag: |
|
1332 | if repo.ui.debugflag: | |
1333 | repo.ui.debug("list of changesets:\n") |
|
1333 | repo.ui.debug("list of changesets:\n") | |
1334 | for node in nodes: |
|
1334 | for node in nodes: | |
1335 | repo.ui.debug("%s\n" % hex(node)) |
|
1335 | repo.ui.debug("%s\n" % hex(node)) | |
1336 |
|
1336 | |||
1337 | def makechangegroup(repo, outgoing, version, source, fastpath=False, |
|
1337 | def makechangegroup(repo, outgoing, version, source, fastpath=False, | |
1338 | bundlecaps=None): |
|
1338 | bundlecaps=None): | |
1339 | cgstream = makestream(repo, outgoing, version, source, |
|
1339 | cgstream = makestream(repo, outgoing, version, source, | |
1340 | fastpath=fastpath, bundlecaps=bundlecaps) |
|
1340 | fastpath=fastpath, bundlecaps=bundlecaps) | |
1341 | return getunbundler(version, util.chunkbuffer(cgstream), None, |
|
1341 | return getunbundler(version, util.chunkbuffer(cgstream), None, | |
1342 | {'clcount': len(outgoing.missing) }) |
|
1342 | {'clcount': len(outgoing.missing) }) | |
1343 |
|
1343 | |||
1344 | def makestream(repo, outgoing, version, source, fastpath=False, |
|
1344 | def makestream(repo, outgoing, version, source, fastpath=False, | |
1345 | bundlecaps=None, filematcher=None): |
|
1345 | bundlecaps=None, filematcher=None): | |
1346 | bundler = getbundler(version, repo, bundlecaps=bundlecaps, |
|
1346 | bundler = getbundler(version, repo, bundlecaps=bundlecaps, | |
1347 | filematcher=filematcher) |
|
1347 | filematcher=filematcher) | |
1348 |
|
1348 | |||
1349 | repo = repo.unfiltered() |
|
1349 | repo = repo.unfiltered() | |
1350 | commonrevs = outgoing.common |
|
1350 | commonrevs = outgoing.common | |
1351 | csets = outgoing.missing |
|
1351 | csets = outgoing.missing | |
1352 | heads = outgoing.missingheads |
|
1352 | heads = outgoing.missingheads | |
1353 | # We go through the fast path if we get told to, or if all (unfiltered |
|
1353 | # We go through the fast path if we get told to, or if all (unfiltered | |
1354 | # heads have been requested (since we then know there all linkrevs will |
|
1354 | # heads have been requested (since we then know there all linkrevs will | |
1355 | # be pulled by the client). |
|
1355 | # be pulled by the client). | |
1356 | heads.sort() |
|
1356 | heads.sort() | |
1357 | fastpathlinkrev = fastpath or ( |
|
1357 | fastpathlinkrev = fastpath or ( | |
1358 | repo.filtername is None and heads == sorted(repo.heads())) |
|
1358 | repo.filtername is None and heads == sorted(repo.heads())) | |
1359 |
|
1359 | |||
1360 | repo.hook('preoutgoing', throw=True, source=source) |
|
1360 | repo.hook('preoutgoing', throw=True, source=source) | |
1361 | _changegroupinfo(repo, csets, source) |
|
1361 | _changegroupinfo(repo, csets, source) | |
1362 | return bundler.generate(commonrevs, csets, fastpathlinkrev, source) |
|
1362 | return bundler.generate(commonrevs, csets, fastpathlinkrev, source) | |
1363 |
|
1363 | |||
1364 | def _addchangegroupfiles(repo, source, revmap, trp, expectedfiles, needfiles): |
|
1364 | def _addchangegroupfiles(repo, source, revmap, trp, expectedfiles, needfiles): | |
1365 | revisions = 0 |
|
1365 | revisions = 0 | |
1366 | files = 0 |
|
1366 | files = 0 | |
1367 | progress = repo.ui.makeprogress(_('files'), unit=_('files'), |
|
1367 | progress = repo.ui.makeprogress(_('files'), unit=_('files'), | |
1368 | total=expectedfiles) |
|
1368 | total=expectedfiles) | |
1369 | for chunkdata in iter(source.filelogheader, {}): |
|
1369 | for chunkdata in iter(source.filelogheader, {}): | |
1370 | files += 1 |
|
1370 | files += 1 | |
1371 | f = chunkdata["filename"] |
|
1371 | f = chunkdata["filename"] | |
1372 | repo.ui.debug("adding %s revisions\n" % f) |
|
1372 | repo.ui.debug("adding %s revisions\n" % f) | |
1373 | progress.increment() |
|
1373 | progress.increment() | |
1374 | fl = repo.file(f) |
|
1374 | fl = repo.file(f) | |
1375 | o = len(fl) |
|
1375 | o = len(fl) | |
1376 | try: |
|
1376 | try: | |
1377 | deltas = source.deltaiter() |
|
1377 | deltas = source.deltaiter() | |
1378 | if not fl.addgroup(deltas, revmap, trp): |
|
1378 | if not fl.addgroup(deltas, revmap, trp): | |
1379 | raise error.Abort(_("received file revlog group is empty")) |
|
1379 | raise error.Abort(_("received file revlog group is empty")) | |
1380 | except error.CensoredBaseError as e: |
|
1380 | except error.CensoredBaseError as e: | |
1381 | raise error.Abort(_("received delta base is censored: %s") % e) |
|
1381 | raise error.Abort(_("received delta base is censored: %s") % e) | |
1382 | revisions += len(fl) - o |
|
1382 | revisions += len(fl) - o | |
1383 | if f in needfiles: |
|
1383 | if f in needfiles: | |
1384 | needs = needfiles[f] |
|
1384 | needs = needfiles[f] | |
1385 | for new in pycompat.xrange(o, len(fl)): |
|
1385 | for new in pycompat.xrange(o, len(fl)): | |
1386 | n = fl.node(new) |
|
1386 | n = fl.node(new) | |
1387 | if n in needs: |
|
1387 | if n in needs: | |
1388 | needs.remove(n) |
|
1388 | needs.remove(n) | |
1389 | else: |
|
1389 | else: | |
1390 | raise error.Abort( |
|
1390 | raise error.Abort( | |
1391 | _("received spurious file revlog entry")) |
|
1391 | _("received spurious file revlog entry")) | |
1392 | if not needs: |
|
1392 | if not needs: | |
1393 | del needfiles[f] |
|
1393 | del needfiles[f] | |
1394 | progress.complete() |
|
1394 | progress.complete() | |
1395 |
|
1395 | |||
1396 | for f, needs in needfiles.iteritems(): |
|
1396 | for f, needs in needfiles.iteritems(): | |
1397 | fl = repo.file(f) |
|
1397 | fl = repo.file(f) | |
1398 | for n in needs: |
|
1398 | for n in needs: | |
1399 | try: |
|
1399 | try: | |
1400 | fl.rev(n) |
|
1400 | fl.rev(n) | |
1401 | except error.LookupError: |
|
1401 | except error.LookupError: | |
1402 | raise error.Abort( |
|
1402 | raise error.Abort( | |
1403 | _('missing file data for %s:%s - run hg verify') % |
|
1403 | _('missing file data for %s:%s - run hg verify') % | |
1404 | (f, hex(n))) |
|
1404 | (f, hex(n))) | |
1405 |
|
1405 | |||
1406 | return revisions, files |
|
1406 | return revisions, files |
General Comments 0
You need to be logged in to leave comments.
Login now