##// END OF EJS Templates
cg4: introduce protocol flag to signify the presence of sidedata...
cg4: introduce protocol flag to signify the presence of sidedata We need a way of signaling whether the current revision has sidedata or not, and re-using the revision flags would waste potential revlog flags and mix two normally independent layers. In this change, we add a single byte at the start of the ch4 delta header to set potential protocol flags. We also reclaim the revlog flag for sidedata, since it is no longer used, in its place now lives the (also experimental) copytracing flag. When generating deltas, apply the `CG_FLAG_SIDEDATA` flag if there is sidedata. When applying the deltas, if said flag is present, the next chunk contains the sidedata. Differential Revision: https://phab.mercurial-scm.org/D10343

File last commit:

r47543:521ac0d7 stable
r47843:119790e1 default
Show More
bdiff.py
84 lines | 2.3 KiB | text/x-python | PythonLexer
Yuya Nishihara
cffi: split modules from pure...
r32512 # bdiff.py - CFFI implementation of bdiff.c
#
# Copyright 2016 Maciej Fijalkowski <fijall@gmail.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
import struct
from ..pure.bdiff import *
Matt Harbison
typing: disable import error warnings that are already handled...
r47543 from . import _bdiff # pytype: disable=import-error
Yuya Nishihara
cffi: split modules from pure...
r32512
ffi = _bdiff.ffi
lib = _bdiff.lib
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
cffi: remove superfluous "if True" blocks
r32513 def blocks(sa, sb):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 a = ffi.new(b"struct bdiff_line**")
b = ffi.new(b"struct bdiff_line**")
ac = ffi.new(b"char[]", str(sa))
bc = ffi.new(b"char[]", str(sb))
l = ffi.new(b"struct bdiff_hunk*")
Yuya Nishihara
cffi: remove superfluous "if True" blocks
r32513 try:
an = lib.bdiff_splitlines(ac, len(sa), a)
bn = lib.bdiff_splitlines(bc, len(sb), b)
if not a[0] or not b[0]:
raise MemoryError
count = lib.bdiff_diff(a[0], an, b[0], bn, l)
if count < 0:
raise MemoryError
rl = [None] * count
h = l.next
i = 0
while h:
rl[i] = (h.a1, h.a2, h.b1, h.b2)
h = h.next
i += 1
finally:
lib.free(a[0])
lib.free(b[0])
lib.bdiff_freehunks(l.next)
return rl
Yuya Nishihara
cffi: split modules from pure...
r32512
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
cffi: remove superfluous "if True" blocks
r32513 def bdiff(sa, sb):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 a = ffi.new(b"struct bdiff_line**")
b = ffi.new(b"struct bdiff_line**")
ac = ffi.new(b"char[]", str(sa))
bc = ffi.new(b"char[]", str(sb))
l = ffi.new(b"struct bdiff_hunk*")
Yuya Nishihara
cffi: remove superfluous "if True" blocks
r32513 try:
an = lib.bdiff_splitlines(ac, len(sa), a)
bn = lib.bdiff_splitlines(bc, len(sb), b)
if not a[0] or not b[0]:
raise MemoryError
count = lib.bdiff_diff(a[0], an, b[0], bn, l)
if count < 0:
raise MemoryError
rl = []
h = l.next
la = lb = 0
while h:
if h.a1 != la or h.b1 != lb:
lgt = (b[0] + h.b1).l - (b[0] + lb).l
Augie Fackler
formatting: blacken the codebase...
r43346 rl.append(
struct.pack(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b">lll",
Augie Fackler
formatting: blacken the codebase...
r43346 (a[0] + la).l - a[0].l,
(a[0] + h.a1).l - a[0].l,
lgt,
)
)
Yuya Nishihara
cffi: remove superfluous "if True" blocks
r32513 rl.append(str(ffi.buffer((b[0] + lb).l, lgt)))
la = h.a2
lb = h.b2
h = h.next
Yuya Nishihara
cffi: split modules from pure...
r32512
Yuya Nishihara
cffi: remove superfluous "if True" blocks
r32513 finally:
lib.free(a[0])
lib.free(b[0])
lib.bdiff_freehunks(l.next)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b"".join(rl)