Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4a67e4e

Browse filesBrowse files
committed
test_fun works
1 parent 31b3673 commit 4a67e4e
Copy full SHA for 4a67e4e

4 files changed

+17-12Lines changed: 17 additions & 12 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎git/compat.py‎

Copy file name to clipboardExpand all lines: git/compat.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@
2929
FileType = io.IOBase
3030
def byte_ord(b):
3131
return b
32+
def bchr(n):
33+
return bytes([n])
3234
else:
3335
FileType = file
3436
# usually, this is just ascii, which might not enough for our encoding needs
3537
# Unless it's set specifically, we override it to be utf-8
3638
if defenc == 'ascii':
3739
defenc = 'utf-8'
3840
byte_ord = ord
41+
bchr = chr
3942

4043

4144
def with_metaclass(meta, *bases):
Collapse file

‎git/index/fun.py‎

Copy file name to clipboardExpand all lines: git/index/fun.py
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
from gitdb.base import IStream
3939
from gitdb.typ import str_tree_type
40+
from git.compat import defenc
4041

4142
__all__ = ('write_cache', 'read_cache', 'write_tree_from_cache', 'entry_key',
4243
'stat_mode_to_index_mode', 'S_IFGITLINK')
@@ -86,9 +87,9 @@ def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1
8687
flags = plen | (entry[2] & CE_NAMEMASK_INV) # clear possible previous values
8788
write(pack(">LLLLLL20sH", entry[6], entry[7], entry[0],
8889
entry[8], entry[9], entry[10], entry[1], flags))
89-
write(path)
90+
write(path.encode(defenc))
9091
real_size = ((tell() - beginoffset + 8) & ~7)
91-
write("\0" * ((beginoffset + real_size) - tell()))
92+
write(b"\0" * ((beginoffset + real_size) - tell()))
9293
# END for each entry
9394

9495
# write previously cached extensions data
@@ -102,7 +103,7 @@ def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1
102103
def read_header(stream):
103104
"""Return tuple(version_long, num_entries) from the given stream"""
104105
type_id = stream.read(4)
105-
if type_id != "DIRC":
106+
if type_id != b"DIRC":
106107
raise AssertionError("Invalid index file header: %r" % type_id)
107108
version, num_entries = unpack(">LL", stream.read(4 * 2))
108109

@@ -142,7 +143,7 @@ def read_cache(stream):
142143
(dev, ino, mode, uid, gid, size, sha, flags) = \
143144
unpack(">LLLLLL20sH", read(20 + 4 * 6 + 2))
144145
path_size = flags & CE_NAMEMASK
145-
path = read(path_size)
146+
path = read(path_size).decode(defenc)
146147

147148
real_size = ((tell() - beginoffset + 8) & ~7)
148149
read((beginoffset + real_size) - tell())
Collapse file

‎git/objects/fun.py‎

Copy file name to clipboardExpand all lines: git/objects/fun.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
byte_ord,
55
defenc,
66
xrange,
7-
text_type
7+
text_type,
8+
bchr
89
)
910

1011
__all__ = ('tree_to_stream', 'tree_entries_from_data', 'traverse_trees_recursive',
@@ -21,7 +22,7 @@ def tree_to_stream(entries, write):
2122
for binsha, mode, name in entries:
2223
mode_str = b''
2324
for i in xrange(6):
24-
mode_str = chr(((mode >> (i * 3)) & bit_mask) + ord_zero) + mode_str
25+
mode_str = bchr(((mode >> (i * 3)) & bit_mask) + ord_zero) + mode_str
2526
# END for each 8 octal value
2627

2728
# git slices away the first octal if its zero
Collapse file

‎git/test/test_fun.py‎

Copy file name to clipboardExpand all lines: git/test/test_fun.py
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
class TestFun(TestBase):
3131

3232
def _assert_index_entries(self, entries, trees):
33-
index = IndexFile.from_tree(self.rorepo, *[self.rorepo.tree(bin_to_hex(t)) for t in trees])
33+
index = IndexFile.from_tree(self.rorepo, *[self.rorepo.tree(bin_to_hex(t).decode('ascii')) for t in trees])
3434
assert entries
3535
assert len(index.entries) == len(entries)
3636
for entry in entries:
@@ -91,9 +91,9 @@ def assert_entries(entries, num_entries, has_conflict=False):
9191
assert has_conflict == (len([e for e in entries if e.stage != 0]) > 0)
9292
mktree = self.mktree
9393

94-
shaa = "\1" * 20
95-
shab = "\2" * 20
96-
shac = "\3" * 20
94+
shaa = b"\1" * 20
95+
shab = b"\2" * 20
96+
shac = b"\3" * 20
9797

9898
odb = rwrepo.odb
9999

@@ -256,6 +256,6 @@ def test_tree_traversal_single(self):
256256
assert entries
257257
# END for each commit
258258

259-
def test_tree_entries_from_data(self):
259+
def test_tree_entries_from_data_with_failing_name_decode(self):
260260
r = tree_entries_from_data(b'100644 \x9f\0aaa')
261-
assert r == [('aaa', 33188, '\x9f')], r
261+
assert r == [(b'aaa', 33188, b'\x9f')], r

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.