[PATCH 1/5] Drop vestigial compat.buffer

0 views
Skip to first unread message

Rob Browning

unread,
May 17, 2024, 2:40:50 PMMay 17
to bup-...@googlegroups.com
Signed-off-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
---
Pushed to main.

lib/bup/compat.py | 8 --------
lib/bup/git.py | 12 ++++++++----
2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/lib/bup/compat.py b/lib/bup/compat.py
index c531754fd..894e27fc1 100644
--- a/lib/bup/compat.py
+++ b/lib/bup/compat.py
@@ -42,14 +42,6 @@ def bytes_from_byte(b): # python > 2: b[3] returns ord('x'), not b'x'

byte_int = lambda x: x

-def buffer(object, offset=None, size=None):
- if size:
- assert offset is not None
- return memoryview(object)[offset:offset + size]
- if offset:
- return memoryview(object)[offset:]
- return memoryview(object)
-
def getcwd():
return fsencode(os.getcwd())

diff --git a/lib/bup/git.py b/lib/bup/git.py
index a134f769e..c9048cf94 100644
--- a/lib/bup/git.py
+++ b/lib/bup/git.py
@@ -12,8 +12,7 @@ from itertools import islice
from shutil import rmtree

from bup import _helpers, hashsplit, path, midx, bloom, xstat
-from bup.compat import (buffer,
- byte_int, bytes_from_byte, bytes_from_uint,
+from bup.compat import (byte_int, bytes_from_byte, bytes_from_uint,
environ,
pending_raise)
from bup.io import path_msg
@@ -425,7 +424,9 @@ class PackIdxV1(PackIdx):
self.nsha = self.fanout[255]
self.sha_ofs = 256 * 4
# Avoid slicing shatable for individual hashes (very high overhead)
- self.shatable = buffer(self.map, self.sha_ofs, self.nsha * 24)
+ assert self.nsha
+ self.shatable = \
+ memoryview(self.map)[self.sha_ofs:self.sha_ofs + self.nsha * 24]

def __enter__(self):
return self
@@ -482,7 +483,10 @@ class PackIdxV2(PackIdx):
self.ofstable_ofs = self.sha_ofs + self.nsha * 20 + self.nsha * 4
self.ofs64table_ofs = self.ofstable_ofs + self.nsha * 4
# Avoid slicing this for individual hashes (very high overhead)
- self.shatable = buffer(self.map, self.sha_ofs, self.nsha*20)
+ assert self.nsha
+ self.shatable = \
+ memoryview(self.map)[self.sha_ofs:self.sha_ofs + self.nsha * 20]
+

def __enter__(self):
return self
--
2.43.0

Rob Browning

unread,
May 17, 2024, 2:40:52 PMMay 17
to bup-...@googlegroups.com
Signed-off-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
---
Pushed to main.

lib/bup/compat.py | 2 --
lib/bup/git.py | 10 +++++-----
lib/bup/helpers.py | 4 ++--
3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/lib/bup/compat.py b/lib/bup/compat.py
index af5d73b59..460831e48 100644
--- a/lib/bup/compat.py
+++ b/lib/bup/compat.py
@@ -40,8 +40,6 @@ def bytes_from_uint(i):
def bytes_from_byte(b): # python > 2: b[3] returns ord('x'), not b'x'
return bytes((b,))

-byte_int = lambda x: x
-
def getcwd():
return fsencode(os.getcwd())

diff --git a/lib/bup/git.py b/lib/bup/git.py
index c9048cf94..a5ea4decc 100644
--- a/lib/bup/git.py
+++ b/lib/bup/git.py
@@ -12,7 +12,7 @@ from itertools import islice
from shutil import rmtree

from bup import _helpers, hashsplit, path, midx, bloom, xstat
-from bup.compat import (byte_int, bytes_from_byte, bytes_from_uint,
+from bup.compat import (bytes_from_byte, bytes_from_uint,
environ,
pending_raise)
from bup.io import path_msg
@@ -359,14 +359,14 @@ def _encode_packobj(type, content, compression_level=1):

def _decode_packobj(buf):
assert(buf)
- c = byte_int(buf[0])
+ c = buf[0]
type = _typermap[(c & 0x70) >> 4]
sz = c & 0x0f
shift = 4
i = 0
while c & 0x80:
i += 1
- c = byte_int(buf[i])
+ c = buf[i]
sz |= (c & 0x7f) << shift
shift += 7
if not (c & 0x80):
@@ -392,7 +392,7 @@ class PackIdx(object):
global _total_searches, _total_steps
_total_searches += 1
assert(len(hash) == 20)
- b1 = byte_int(hash[0])
+ b1 = hash[0]
start = self.fanout[b1-1] # range -1..254
end = self.fanout[b1] # range 0..255
want = hash
@@ -987,7 +987,7 @@ class PackIdxV2Writer:
def add(self, sha, crc, offs):
assert(sha)
self.count += 1
- self.idx[byte_int(sha[0])].append((sha, crc, offs))
+ self.idx[sha[0]].append((sha, crc, offs))

def write(self, filename, packbin):
ofs64_count = 0
diff --git a/lib/bup/helpers.py b/lib/bup/helpers.py
index 6fce7e5da..d4da1756b 100644
--- a/lib/bup/helpers.py
+++ b/lib/bup/helpers.py
@@ -14,7 +14,7 @@ import hashlib, heapq, math, operator, time

from bup import _helpers
from bup import io
-from bup.compat import argv_bytes, byte_int, nullcontext, pending_raise
+from bup.compat import argv_bytes, nullcontext, pending_raise
from bup.io import byte_stream, path_msg
# This function should really be in helpers, not in bup.options. But we
# want options.py to be standalone so people can include it in other projects.
@@ -1158,7 +1158,7 @@ def valid_save_name(name):
if _some_invalid_save_parts_rx.search(name):
return False
for c in name:
- if byte_int(c) < 0x20 or byte_int(c) == 0x7f:
+ if c < 0x20 or c == 0x7f:
return False
for part in name.split(b'/'):
if part.startswith(b'.') or part.endswith(b'.lock'):
--
2.43.0

Reply all
Reply to author
Forward
0 new messages