Skip to content

Commit d8405ee

Browse files
committed
More bytes handling
1 parent 0269405 commit d8405ee

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

gitdb/db/base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from itertools import chain
2323
from functools import reduce
2424

25+
import sys
26+
2527

2628
__all__ = ('ObjectDBR', 'ObjectDBW', 'FileDBBase', 'CompoundDB', 'CachingDB')
2729

@@ -176,6 +178,14 @@ def db_path(self, rela_path):
176178
"""
177179
:return: the given relative path relative to our database root, allowing
178180
to pontentially access datafiles"""
181+
if sys.version_info[0] == 3:
182+
text_type = str
183+
else:
184+
text_type = basestring
185+
186+
if not isinstance(rela_path, text_type):
187+
rela_path = rela_path.decode("utf-8")
188+
179189
return join(self._root_path, rela_path)
180190
#} END interface
181191

gitdb/fun.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def loose_object_header_info(m):
402402
:param m: memory map from which to read the compressed object data"""
403403
decompress_size = 8192 # is used in cgit as well
404404
hdr = decompressobj().decompress(m, decompress_size)
405-
type_name, size = hdr[:hdr.find("\0")].split(" ")
405+
type_name, size = hdr[:hdr.find("\0".encode("ascii"))].split(" ".encode("ascii"))
406406
return type_name, int(size)
407407

408408
def pack_object_header_info(data):

gitdb/pack.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ def pack_object_at(cursor, offset, as_stream):
121121

122122
abs_data_offset = offset + total_rela_offset
123123
if as_stream:
124-
stream = DecompressMemMapReader(buffer(data, total_rela_offset), False, uncomp_size)
124+
try:
125+
buff = memoryview(data)[total_rela_offset:].tobytes()
126+
except (NameError, TypeError):
127+
buff = buffer(data, total_rela_offset)
128+
stream = DecompressMemMapReader(buff, False, uncomp_size)
125129
if delta_info is None:
126130
return abs_data_offset, OPackStream(offset, type_id, uncomp_size, stream)
127131
else:

gitdb/stream.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def _parse_header_info(self):
105105
maxb = 512 # should really be enough, cgit uses 8192 I believe
106106
self._s = maxb
107107
hdr = self.read(maxb)
108-
hdrend = hdr.find("\0")
109-
type, size = hdr[:hdrend].split(" ")
108+
hdrend = hdr.find("\0".encode("ascii"))
109+
type, size = hdr[:hdrend].split(" ".encode("ascii"))
110110
size = int(size)
111111
self._s = size
112112

gitdb/test/db/test_ref.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def make_alt_file(self, alt_path, alt_list):
1919
The list can be empty"""
2020
alt_file = open(alt_path, "wb")
2121
for alt in alt_list:
22-
alt_file.write(alt + "\n")
22+
alt_file.write(alt.encode("utf-8") + "\n".encode("ascii"))
2323
alt_file.close()
2424

2525
@with_rw_directory

0 commit comments

Comments
 (0)