Skip to content

Commit c63dcac

Browse files
committed
Convert types to bytes
This makes it easier to deal with things internally as now everything is passed as bytes.
1 parent ecdae96 commit c63dcac

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

gitdb/fun.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
from itertools import islice
1818

1919
from gitdb.utils.compat import izip
20+
from gitdb.typ import (
21+
str_blob_type,
22+
str_commit_type,
23+
str_tree_type,
24+
str_tag_type,
25+
)
2026

2127
from io import StringIO
2228

@@ -27,23 +33,23 @@
2733

2834
type_id_to_type_map = {
2935
0 : "", # EXT 1
30-
1 : "commit",
31-
2 : "tree",
32-
3 : "blob",
33-
4 : "tag",
36+
1 : str_commit_type,
37+
2 : str_tree_type,
38+
3 : str_blob_type,
39+
4 : str_tag_type,
3440
5 : "", # EXT 2
3541
OFS_DELTA : "OFS_DELTA", # OFFSET DELTA
3642
REF_DELTA : "REF_DELTA" # REFERENCE DELTA
3743
}
3844

39-
type_to_type_id_map = dict(
40-
commit=1,
41-
tree=2,
42-
blob=3,
43-
tag=4,
44-
OFS_DELTA=OFS_DELTA,
45-
REF_DELTA=REF_DELTA
46-
)
45+
type_to_type_id_map = {
46+
str_commit_type: 1,
47+
str_tree_type: 2,
48+
str_blob_type: 3,
49+
str_tag_type: 4,
50+
"OFS_DELTA": OFS_DELTA,
51+
"REF_DELTA": REF_DELTA,
52+
}
4753

4854
# used when dealing with larger streams
4955
chunk_size = 1000 * mmap.PAGESIZE
@@ -398,7 +404,7 @@ def loose_object_header_info(m):
398404
hdr = decompressobj().decompress(m, decompress_size)
399405
type_name, size = hdr[:hdr.find(NULL_BYTE)].split(" ".encode("ascii"))
400406

401-
return force_text(type_name), int(size)
407+
return type_name, int(size)
402408

403409
def pack_object_header_info(data):
404410
"""

gitdb/stream.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from gitdb.const import NULL_BYTE
3131
from gitdb.utils.compat import buffer
32-
from gitdb.utils.encoding import force_bytes, force_text
32+
from gitdb.utils.encoding import force_bytes
3333

3434
has_perf_mod = False
3535
try:
@@ -117,7 +117,7 @@ def _parse_header_info(self):
117117

118118
self._phi = True
119119

120-
return force_text(typ), size
120+
return typ, size
121121

122122
#{ Interface
123123

gitdb/typ.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55
"""Module containing information about types known to the database"""
66

7-
#{ String types
7+
from gitdb.utils.encoding import force_bytes
88

9-
str_blob_type = "blob"
10-
str_commit_type = "commit"
11-
str_tree_type = "tree"
12-
str_tag_type = "tag"
13-
14-
#} END string types
9+
str_blob_type = force_bytes("blob")
10+
str_commit_type = force_bytes("commit")
11+
str_tree_type = force_bytes("tree")
12+
str_tag_type = force_bytes("tag")

0 commit comments

Comments
 (0)