##// END OF EJS Templates
git: drop the zope `repository.ifilestorage` decoration on `gitlog.filelog`...
git: drop the zope `repository.ifilestorage` decoration on `gitlog.filelog` The next logical step is to disable the conditional import of `zope` in the `mercurial.interfaces.util` module, and just run with the no-op decorators. But doing that then generates these pytype errors: File "/mnt/c/Users/Matt/hg/hgext/git/gitlog.py", line 485, in read: No attribute 'gitrepo' on filelog [attribute-error] File "/mnt/c/Users/Matt/hg/hgext/git/gitlog.py", line 495, in lookup: No attribute 'gitrepo' on filelog [attribute-error] File "/mnt/c/Users/Matt/hg/hgext/git/gitlog.py", line 505, in add: No attribute 'gitrepo' on filelog [attribute-error] File "/mnt/c/Users/Matt/hg/hgext/git/gitlog.py", line 508, in __iter__: No attribute '_db' on filelog [attribute-error] File "/mnt/c/Users/Matt/hg/hgext/git/gitlog.py", line 522, in rev: No attribute '_db' on filelog [attribute-error] File "/mnt/c/Users/Matt/hg/hgext/git/gitlog.py", line 534, in node: No attribute '_db' on filelog [attribute-error] File "/mnt/c/Users/Matt/hg/hgext/git/gitlog.py", line 549, in parents: No attribute '_db' on filelog [attribute-error] File "/mnt/c/Users/Matt/hg/hgext/git/gitlog.py", line 556, in parents: No attribute '_db' on filelog [attribute-error] File "/mnt/c/Users/Matt/hg/hgext/git/gitlog.py", line 564, in parents: No attribute 'gitrepo' on filelog [attribute-error] File "/mnt/c/Users/Matt/hg/hgext/git/gitlog.py", line 564, in parents: No attribute '_db' on filelog [attribute-error] I'm not sure what exactly the issue is, but the pyi file that was being generated up to this point has `filelog` typed as `Any` (because it had a decorator, and pytype chokes on that), and `baselog` was typed as a class. So it apparently can't see the `_db` and `gitrepo` attributes of the subclass, because it doesn't think `filelog` is a class. Leave the decorator commented out so it hits when searching for the remaining zope things that need to be updated to Protocol.

File last commit:

r52827:09f3a679 default
r53341:cdb45eb7 default
Show More
bdiff.py
104 lines | 2.8 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.
Matt Harbison
typing: add `from __future__ import annotations` to most files...
r52756 from __future__ import annotations
Yuya Nishihara
cffi: split modules from pure...
r32512
import struct
Matt Harbison
interfaces: add the optional `bdiff.xdiffblocks()` method...
r52827 import typing
Yuya Nishihara
cffi: split modules from pure...
r32512
Matt Harbison
typing: add type hints to bdiff implementations...
r50493 from typing import (
List,
Matt Harbison
interfaces: add the optional `bdiff.xdiffblocks()` method...
r52827 Optional,
Matt Harbison
typing: add type hints to bdiff implementations...
r50493 Tuple,
)
Yuya Nishihara
cffi: split modules from pure...
r32512 from ..pure.bdiff import *
Matt Harbison
interfaces: add the optional `bdiff.xdiffblocks()` method...
r52827
from ..interfaces import (
modules as intmod,
)
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
Matt Harbison
typing: add type hints to bdiff implementations...
r50493 def blocks(sa: bytes, sb: bytes) -> List[Tuple[int, int, int, int]]:
Manuel Jacob
cffi: pass C type and attribute names as str instead of bytes
r52683 a = ffi.new("struct bdiff_line**")
b = ffi.new("struct bdiff_line**")
Manuel Jacob
cffi: pass bytes instead of str to ffi.new("char[]", …)...
r52685 ac = ffi.new("char[]", bytes(sa))
bc = ffi.new("char[]", bytes(sb))
Manuel Jacob
cffi: pass C type and attribute names as str instead of bytes
r52683 l = ffi.new("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
Matt Harbison
cffi: adjust the list returned by bdiff.blocks to never have a None entry...
r50492 rl = [(0, 0, 0, 0)] * count
Yuya Nishihara
cffi: remove superfluous "if True" blocks
r32513 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
Matt Harbison
typing: add type hints to bdiff implementations...
r50493 def bdiff(sa: bytes, sb: bytes) -> bytes:
Manuel Jacob
cffi: pass C type and attribute names as str instead of bytes
r52683 a = ffi.new("struct bdiff_line**")
b = ffi.new("struct bdiff_line**")
Manuel Jacob
cffi: pass bytes instead of str to ffi.new("char[]", …)...
r52685 ac = ffi.new("char[]", bytes(sa))
bc = ffi.new("char[]", bytes(sb))
Manuel Jacob
cffi: pass C type and attribute names as str instead of bytes
r52683 l = ffi.new("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,
)
)
Manuel Jacob
cffi: call bytes() instead of str() on CFFI buffer instances
r52684 rl.append(bytes(ffi.buffer((b[0] + lb).l, lgt)))
Yuya Nishihara
cffi: remove superfluous "if True" blocks
r32513 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)
Matt Harbison
interfaces: add the optional `bdiff.xdiffblocks()` method...
r52827
# In order to adhere to the module protocol, these functions must be visible to
# the type checker, though they aren't actually implemented by this
# implementation of the module protocol. Callers are responsible for
# checking that the implementation is available before using them.
if typing.TYPE_CHECKING:
xdiffblocks: Optional[intmod.BDiffBlocksFnc] = None