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