mirror of https://github.com/borgbackup/borg.git
Merge pull request #5788 from RonnyPfannschmidt/move-chunks-equals
move chunk_equals to module level and modernize tox.ini
This commit is contained in:
commit
c114e060ec
|
@ -517,36 +517,36 @@ class ItemDiff:
|
||||||
return self._item1.chunks == self._item2.chunks
|
return self._item1.chunks == self._item2.chunks
|
||||||
if self._item1.get_size() != self._item2.get_size():
|
if self._item1.get_size() != self._item2.get_size():
|
||||||
return False
|
return False
|
||||||
return ItemDiff._chunk_content_equal(chunk_iterator1, chunk_iterator2)
|
return chunks_contents_equal(chunk_iterator1, chunk_iterator2)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _chunk_content_equal(chunks1, chunks2):
|
|
||||||
"""
|
|
||||||
Compare chunk content and return True if they are identical.
|
|
||||||
|
|
||||||
The chunks must be given as chunk iterators (like returned by :meth:`.DownloadPipeline.fetch_many`).
|
def chunks_contents_equal(chunks1, chunks2):
|
||||||
"""
|
"""
|
||||||
|
Compare chunk content and return True if they are identical.
|
||||||
|
|
||||||
end = object()
|
The chunks must be given as chunk iterators (like returned by :meth:`.DownloadPipeline.fetch_many`).
|
||||||
alen = ai = 0
|
"""
|
||||||
blen = bi = 0
|
|
||||||
while True:
|
end = object()
|
||||||
if not alen - ai:
|
alen = ai = 0
|
||||||
a = next(chunks1, end)
|
blen = bi = 0
|
||||||
if a is end:
|
while True:
|
||||||
return not blen - bi and next(chunks2, end) is end
|
if not alen - ai:
|
||||||
a = memoryview(a)
|
a = next(chunks1, end)
|
||||||
alen = len(a)
|
if a is end:
|
||||||
ai = 0
|
return not blen - bi and next(chunks2, end) is end
|
||||||
if not blen - bi:
|
a = memoryview(a)
|
||||||
b = next(chunks2, end)
|
alen = len(a)
|
||||||
if b is end:
|
ai = 0
|
||||||
return not alen - ai and next(chunks1, end) is end
|
if not blen - bi:
|
||||||
b = memoryview(b)
|
b = next(chunks2, end)
|
||||||
blen = len(b)
|
if b is end:
|
||||||
bi = 0
|
return not alen - ai and next(chunks1, end) is end
|
||||||
slicelen = min(alen - ai, blen - bi)
|
b = memoryview(b)
|
||||||
if a[ai:ai + slicelen] != b[bi:bi + slicelen]:
|
blen = len(b)
|
||||||
return False
|
bi = 0
|
||||||
ai += slicelen
|
slicelen = min(alen - ai, blen - bi)
|
||||||
bi += slicelen
|
if a[ai:ai + slicelen] != b[bi:bi + slicelen]:
|
||||||
|
return False
|
||||||
|
ai += slicelen
|
||||||
|
bi += slicelen
|
||||||
|
|
|
@ -47,7 +47,7 @@ from ..helpers import msgpack
|
||||||
from ..helpers import flags_noatime, flags_normal
|
from ..helpers import flags_noatime, flags_normal
|
||||||
from ..nanorst import RstToTextLazy, rst_to_terminal
|
from ..nanorst import RstToTextLazy, rst_to_terminal
|
||||||
from ..patterns import IECommand, PatternMatcher, parse_pattern
|
from ..patterns import IECommand, PatternMatcher, parse_pattern
|
||||||
from ..item import Item, ItemDiff
|
from ..item import Item, ItemDiff, chunks_contents_equal
|
||||||
from ..locking import LockFailed
|
from ..locking import LockFailed
|
||||||
from ..logger import setup_logging
|
from ..logger import setup_logging
|
||||||
from ..remote import RemoteRepository, PathNotAllowed
|
from ..remote import RemoteRepository, PathNotAllowed
|
||||||
|
@ -4218,8 +4218,8 @@ def test_chunk_content_equal():
|
||||||
def ccc(a, b):
|
def ccc(a, b):
|
||||||
chunks_a = [data for data in a]
|
chunks_a = [data for data in a]
|
||||||
chunks_b = [data for data in b]
|
chunks_b = [data for data in b]
|
||||||
compare1 = ItemDiff._chunk_content_equal(iter(chunks_a), iter(chunks_b))
|
compare1 = chunks_contents_equal(iter(chunks_a), iter(chunks_b))
|
||||||
compare2 = ItemDiff._chunk_content_equal(iter(chunks_b), iter(chunks_a))
|
compare2 = chunks_contents_equal(iter(chunks_b), iter(chunks_a))
|
||||||
assert compare1 == compare2
|
assert compare1 == compare2
|
||||||
return compare1
|
return compare1
|
||||||
assert ccc([
|
assert ccc([
|
||||||
|
|
28
tox.ini
28
tox.ini
|
@ -3,31 +3,29 @@
|
||||||
|
|
||||||
[tox]
|
[tox]
|
||||||
envlist = py{36,37,38,39,310}-{none,fuse2,fuse3}
|
envlist = py{36,37,38,39,310}-{none,fuse2,fuse3}
|
||||||
|
minversion = 3.2
|
||||||
|
requires =
|
||||||
|
pkgconfig
|
||||||
|
cython
|
||||||
|
wheel
|
||||||
|
setuptools_scm
|
||||||
[testenv]
|
[testenv]
|
||||||
|
setenv =
|
||||||
|
fuse2: BORG_FUSE_IMPL=llfuse
|
||||||
|
fuse3: BORG_FUSE_IMPL=pyfuse3
|
||||||
deps =
|
deps =
|
||||||
|
fuse2: llfuse
|
||||||
|
fuse3: pyfuse3
|
||||||
-rrequirements.d/development.txt
|
-rrequirements.d/development.txt
|
||||||
commands = py.test -v -n {env:XDISTN:1} -rs --cov=borg --cov-config=.coveragerc --benchmark-skip --pyargs {posargs:borg.testsuite}
|
commands = py.test -v -n {env:XDISTN:1} -rs --cov=borg --cov-config=.coveragerc --benchmark-skip --pyargs {posargs:borg.testsuite}
|
||||||
# fakeroot -u needs some env vars:
|
# fakeroot -u needs some env vars:
|
||||||
passenv = *
|
passenv = *
|
||||||
|
|
||||||
[testenv:py{36,37,38,39}-fuse2]
|
|
||||||
setenv =
|
|
||||||
BORG_FUSE_IMPL=llfuse
|
|
||||||
deps =
|
|
||||||
llfuse
|
|
||||||
{[testenv]deps}
|
|
||||||
|
|
||||||
[testenv:py{36,37,38,39}-fuse3]
|
|
||||||
setenv =
|
|
||||||
BORG_FUSE_IMPL=pyfuse3
|
|
||||||
deps =
|
|
||||||
pyfuse3
|
|
||||||
{[testenv]deps}
|
|
||||||
|
|
||||||
[testenv:flake8]
|
[testenv:flake8]
|
||||||
|
skip_sdist=true
|
||||||
|
skip_install=true
|
||||||
changedir =
|
changedir =
|
||||||
deps =
|
deps =
|
||||||
flake8
|
flake8
|
||||||
pkgconfig
|
|
||||||
commands = flake8 src scripts conftest.py
|
commands = flake8 src scripts conftest.py
|
||||||
|
|
Loading…
Reference in New Issue