summaryrefslogtreecommitdiff
path: root/gitdb
diff options
context:
space:
mode:
authorKevin Brown <kevin@kevinbrown.in>2014-07-13 19:55:00 -0400
committerKevin Brown <kevin@kevinbrown.in>2014-07-13 19:55:00 -0400
commitd8405ee00bfc1ebdae7c41b45f8c374902a3d2b4 (patch)
tree9d24be0480a83b02358ad4612e7b2365a04f7489 /gitdb
parent0269405121d7ef065f7008c9c033e95e734f029a (diff)
downloadgitdb-d8405ee00bfc1ebdae7c41b45f8c374902a3d2b4.tar.gz
More bytes handling
Diffstat (limited to 'gitdb')
-rw-r--r--gitdb/db/base.py10
-rw-r--r--gitdb/fun.py2
-rw-r--r--gitdb/pack.py6
-rw-r--r--gitdb/stream.py4
-rw-r--r--gitdb/test/db/test_ref.py2
5 files changed, 19 insertions, 5 deletions
diff --git a/gitdb/db/base.py b/gitdb/db/base.py
index 85df324..aa7a7ee 100644
--- a/gitdb/db/base.py
+++ b/gitdb/db/base.py
@@ -22,6 +22,8 @@ from async import (
from itertools import chain
from functools import reduce
+import sys
+
__all__ = ('ObjectDBR', 'ObjectDBW', 'FileDBBase', 'CompoundDB', 'CachingDB')
@@ -176,6 +178,14 @@ class FileDBBase(object):
"""
:return: the given relative path relative to our database root, allowing
to pontentially access datafiles"""
+ if sys.version_info[0] == 3:
+ text_type = str
+ else:
+ text_type = basestring
+
+ if not isinstance(rela_path, text_type):
+ rela_path = rela_path.decode("utf-8")
+
return join(self._root_path, rela_path)
#} END interface
diff --git a/gitdb/fun.py b/gitdb/fun.py
index 8f2d463..9baeac3 100644
--- a/gitdb/fun.py
+++ b/gitdb/fun.py
@@ -402,7 +402,7 @@ def loose_object_header_info(m):
:param m: memory map from which to read the compressed object data"""
decompress_size = 8192 # is used in cgit as well
hdr = decompressobj().decompress(m, decompress_size)
- type_name, size = hdr[:hdr.find("\0")].split(" ")
+ type_name, size = hdr[:hdr.find("\0".encode("ascii"))].split(" ".encode("ascii"))
return type_name, int(size)
def pack_object_header_info(data):
diff --git a/gitdb/pack.py b/gitdb/pack.py
index 4a9ee9f..ad5eccb 100644
--- a/gitdb/pack.py
+++ b/gitdb/pack.py
@@ -121,7 +121,11 @@ def pack_object_at(cursor, offset, as_stream):
abs_data_offset = offset + total_rela_offset
if as_stream:
- stream = DecompressMemMapReader(buffer(data, total_rela_offset), False, uncomp_size)
+ try:
+ buff = memoryview(data)[total_rela_offset:].tobytes()
+ except (NameError, TypeError):
+ buff = buffer(data, total_rela_offset)
+ stream = DecompressMemMapReader(buff, False, uncomp_size)
if delta_info is None:
return abs_data_offset, OPackStream(offset, type_id, uncomp_size, stream)
else:
diff --git a/gitdb/stream.py b/gitdb/stream.py
index a099eeb..75993db 100644
--- a/gitdb/stream.py
+++ b/gitdb/stream.py
@@ -105,8 +105,8 @@ class DecompressMemMapReader(LazyMixin):
maxb = 512 # should really be enough, cgit uses 8192 I believe
self._s = maxb
hdr = self.read(maxb)
- hdrend = hdr.find("\0")
- type, size = hdr[:hdrend].split(" ")
+ hdrend = hdr.find("\0".encode("ascii"))
+ type, size = hdr[:hdrend].split(" ".encode("ascii"))
size = int(size)
self._s = size
diff --git a/gitdb/test/db/test_ref.py b/gitdb/test/db/test_ref.py
index 752c31d..e303fe2 100644
--- a/gitdb/test/db/test_ref.py
+++ b/gitdb/test/db/test_ref.py
@@ -19,7 +19,7 @@ class TestReferenceDB(TestDBBase):
The list can be empty"""
alt_file = open(alt_path, "wb")
for alt in alt_list:
- alt_file.write(alt + "\n")
+ alt_file.write(alt.encode("utf-8") + "\n".encode("ascii"))
alt_file.close()
@with_rw_directory