##// END OF EJS Templates
changegroup: introduce cg2packer/unpacker...
Sune Foldager -
r23181:832b7ef2 default
parent child Browse files
Show More
@@ -13,6 +13,7 b' import struct, os, bz2, zlib, tempfile'
13 import discovery, error, phases, branchmap
13 import discovery, error, phases, branchmap
14
14
15 _CHANGEGROUPV1_DELTA_HEADER = "20s20s20s20s"
15 _CHANGEGROUPV1_DELTA_HEADER = "20s20s20s20s"
16 _CHANGEGROUPV2_DELTA_HEADER = "20s20s20s20s20s"
16
17
17 def readexactly(stream, n):
18 def readexactly(stream, n):
18 '''read n bytes from stream.read and abort if less was available'''
19 '''read n bytes from stream.read and abort if less was available'''
@@ -215,6 +216,14 b' class cg1unpacker(object):'
215 pos = next
216 pos = next
216 yield closechunk()
217 yield closechunk()
217
218
219 class cg2unpacker(cg1unpacker):
220 deltaheader = _CHANGEGROUPV2_DELTA_HEADER
221 deltaheadersize = struct.calcsize(deltaheader)
222
223 def _deltaheader(self, headertuple, prevnode):
224 node, p1, p2, deltabase, cs = headertuple
225 return node, p1, p2, deltabase, cs
226
218 class headerlessfixup(object):
227 class headerlessfixup(object):
219 def __init__(self, fh, h):
228 def __init__(self, fh, h):
220 self._h = h
229 self._h = h
@@ -410,10 +419,13 b' class cg1packer(object):'
410 reorder=reorder):
419 reorder=reorder):
411 yield chunk
420 yield chunk
412
421
422 def deltaparent(self, revlog, rev, p1, p2, prev):
423 return prev
424
413 def revchunk(self, revlog, rev, prev, linknode):
425 def revchunk(self, revlog, rev, prev, linknode):
414 node = revlog.node(rev)
426 node = revlog.node(rev)
415 p1, p2 = revlog.parentrevs(rev)
427 p1, p2 = revlog.parentrevs(rev)
416 base = prev
428 base = self.deltaparent(revlog, rev, p1, p2, prev)
417
429
418 prefix = ''
430 prefix = ''
419 if base == nullrev:
431 if base == nullrev:
@@ -433,7 +445,29 b' class cg1packer(object):'
433 # do nothing with basenode, it is implicitly the previous one in HG10
445 # do nothing with basenode, it is implicitly the previous one in HG10
434 return struct.pack(self.deltaheader, node, p1n, p2n, linknode)
446 return struct.pack(self.deltaheader, node, p1n, p2n, linknode)
435
447
436 packermap = {'01': (cg1packer, cg1unpacker)}
448 class cg2packer(cg1packer):
449
450 deltaheader = _CHANGEGROUPV2_DELTA_HEADER
451
452 def group(self, nodelist, revlog, lookup, units=None, reorder=None):
453 if (revlog._generaldelta and reorder is not True):
454 reorder = False
455 return cg1packer.group(self, nodelist, revlog, lookup,
456 units=units, reorder=reorder)
457
458 def deltaparent(self, revlog, rev, p1, p2, prev):
459 dp = revlog.deltaparent(rev)
460 # avoid storing full revisions; pick prev in those cases
461 # also pick prev when we can't be sure remote has dp
462 if dp == nullrev or (dp != p1 and dp != p2 and dp != prev):
463 return prev
464 return dp
465
466 def builddeltaheader(self, node, p1n, p2n, basenode, linknode):
467 return struct.pack(self.deltaheader, node, p1n, p2n, basenode, linknode)
468
469 packermap = {'01': (cg1packer, cg1unpacker),
470 '02': (cg2packer, cg2unpacker)}
437
471
438 def _changegroupinfo(repo, nodes, source):
472 def _changegroupinfo(repo, nodes, source):
439 if repo.ui.verbose or source == 'bundle':
473 if repo.ui.verbose or source == 'bundle':
General Comments 0
You need to be logged in to leave comments. Login now