Skip to content

Commit 5af5cd9

Browse files
committed
Sha1 verification works as well, forgot to fill in the base buffer for delta-application, and fixed the broken DeltaApplyReader's seek method
1 parent ecb1878 commit 5af5cd9

4 files changed

Lines changed: 14 additions & 5 deletions

File tree

fun.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def apply_delta_data(src_buf, src_buf_size, delta_buf, delta_buf_size, target_fi
200200
if (cp_off + cp_size < cp_size or
201201
cp_off + cp_size > src_buf_size):
202202
break
203-
twrite(src_buf[cp_off:cp_off+cp_size])
203+
twrite(buffer(src_buf, cp_off, cp_size))
204204
elif c:
205205
twrite(db[i:i+c])
206206
i += c

pack.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ def is_valid_stream(self, sha, use_crc=False):
611611
# write a loose object, which is the basis for the sha
612612
write_object(stream.type, stream.size, stream.read, shawriter.write)
613613

614+
assert shawriter.sha(as_hex=False) == sha
614615
return shawriter.sha(as_hex=False) == sha
615616
# END handle crc/sha verification
616617
return True

stream.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ def _set_cache_(self, attr):
358358
# Allocate private memory map big enough to hold the first base buffer
359359
# We need random access to it
360360
bbuf = allocate_memory(base_size)
361+
stream_copy(self._bstream.read, bbuf.write, base_size, 256*mmap.PAGESIZE)
361362

362363
# allocate memory map large enough for the largest (intermediate) target
363364
# We will use it as scratch space for all delta ops. If the final
@@ -408,6 +409,8 @@ def read(self, count=0):
408409
bl = self._size - self._br # bytes left
409410
if count < 1 or count > bl:
410411
count = bl
412+
# NOTE: we could check for certain size limits, and possibly
413+
# return buffers instead of strings to prevent byte copying
411414
data = self._mm_target.read(count)
412415
self._br += len(data)
413416
return data
@@ -418,7 +421,8 @@ def seek(self, offset, whence=os.SEEK_SET):
418421
if offset != 0 or whence != os.SEEK_SET:
419422
raise ValueError("Can only seek to position 0")
420423
# END handle offset
421-
self._size
424+
self._br = 0
425+
self._mm_target.seek(0)
422426

423427
#{ Interface
424428

test/test_pack.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ def _assert_pack_file(self, pack, version, size):
9090
# END get deltastream
9191

9292
# read all
93-
assert len(dstream.read()) == dstream.size
93+
data = dstream.read()
94+
assert len(data) == dstream.size
95+
96+
# test seek
97+
dstream.seek(0)
98+
assert dstream.read() == data
99+
94100

95101
# read chunks
96102
# NOTE: the current implementation is safe, it basically transfers
@@ -119,7 +125,6 @@ def test_pack_entity(self):
119125
(self.packfile_v2_2, self.packindexfile_v2)):
120126
packfile, version, size = packinfo
121127
indexfile, version, size = indexinfo
122-
print packfile
123128
entity = PackEntity(packfile)
124129
assert entity.pack().path() == packfile
125130
assert entity.index().path() == indexfile
@@ -136,7 +141,6 @@ def test_pack_entity(self):
136141
assert not info.type_id in delta_types
137142

138143
# verify the stream
139-
print info
140144
try:
141145
assert entity.is_valid_stream(info.sha, use_crc=True)
142146
except UnsupportedOperation:

0 commit comments

Comments
 (0)