| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,13 +29,16 @@ | |||
| 29 | 29 | FileType = io.IOBase | |
| 30 | 30 | def byte_ord(b): | |
| 31 | 31 | return b | |
| 32 | + def bchr(n): | ||
| 33 | + return bytes([n]) | ||
| 32 | 34 | else: | |
| 33 | 35 | FileType = file | |
| 34 | 36 | # usually, this is just ascii, which might not enough for our encoding needs | |
| 35 | 37 | # Unless it's set specifically, we override it to be utf-8 | |
| 36 | 38 | if defenc == 'ascii': | |
| 37 | 39 | defenc = 'utf-8' | |
| 38 | 40 | byte_ord = ord | |
| 41 | + bchr = chr | ||
| 39 | 42 | ||
| 40 | 43 | ||
| 41 | 44 | def with_metaclass(meta, *bases): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,6 +37,7 @@ | |||
| 37 | 37 | ||
| 38 | 38 | from gitdb.base import IStream | |
| 39 | 39 | from gitdb.typ import str_tree_type | |
| 40 | + from git.compat import defenc | ||
| 40 | 41 | ||
| 41 | 42 | __all__ = ('write_cache', 'read_cache', 'write_tree_from_cache', 'entry_key', | |
| 42 | 43 | 'stat_mode_to_index_mode', 'S_IFGITLINK') | |
@@ -86,9 +87,9 @@ def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1 | |||
| 86 | 87 | flags = plen | (entry[2] & CE_NAMEMASK_INV) # clear possible previous values | |
| 87 | 88 | write(pack(">LLLLLL20sH", entry[6], entry[7], entry[0], | |
| 88 | 89 | entry[8], entry[9], entry[10], entry[1], flags)) | |
| 89 | - write(path) | ||
| 90 | + write(path.encode(defenc)) | ||
| 90 | 91 | real_size = ((tell() - beginoffset + 8) & ~7) | |
| 91 | - write("\0" * ((beginoffset + real_size) - tell())) | ||
| 92 | + write(b"\0" * ((beginoffset + real_size) - tell())) | ||
| 92 | 93 | # END for each entry | |
| 93 | 94 | ||
| 94 | 95 | # write previously cached extensions data | |
@@ -102,7 +103,7 @@ def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1 | |||
| 102 | 103 | def read_header(stream): | |
| 103 | 104 | """Return tuple(version_long, num_entries) from the given stream""" | |
| 104 | 105 | type_id = stream.read(4) | |
| 105 | - if type_id != "DIRC": | ||
| 106 | + if type_id != b"DIRC": | ||
| 106 | 107 | raise AssertionError("Invalid index file header: %r" % type_id) | |
| 107 | 108 | version, num_entries = unpack(">LL", stream.read(4 * 2)) | |
| 108 | 109 | ||
@@ -142,7 +143,7 @@ def read_cache(stream): | |||
| 142 | 143 | (dev, ino, mode, uid, gid, size, sha, flags) = \ | |
| 143 | 144 | unpack(">LLLLLL20sH", read(20 + 4 * 6 + 2)) | |
| 144 | 145 | path_size = flags & CE_NAMEMASK | |
| 145 | - path = read(path_size) | ||
| 146 | + path = read(path_size).decode(defenc) | ||
| 146 | 147 | ||
| 147 | 148 | real_size = ((tell() - beginoffset + 8) & ~7) | |
| 148 | 149 | read((beginoffset + real_size) - tell()) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,8 @@ | |||
| 4 | 4 | byte_ord, | |
| 5 | 5 | defenc, | |
| 6 | 6 | xrange, | |
| 7 | - text_type | ||
| 7 | + text_type, | ||
| 8 | + bchr | ||
| 8 | 9 | ) | |
| 9 | 10 | ||
| 10 | 11 | __all__ = ('tree_to_stream', 'tree_entries_from_data', 'traverse_trees_recursive', | |
@@ -21,7 +22,7 @@ def tree_to_stream(entries, write): | |||
| 21 | 22 | for binsha, mode, name in entries: | |
| 22 | 23 | mode_str = b'' | |
| 23 | 24 | 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 | ||
| 25 | 26 | # END for each 8 octal value | |
| 26 | 27 | ||
| 27 | 28 | # git slices away the first octal if its zero | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,7 +30,7 @@ | |||
| 30 | 30 | class TestFun(TestBase): | |
| 31 | 31 | ||
| 32 | 32 | 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]) | ||
| 34 | 34 | assert entries | |
| 35 | 35 | assert len(index.entries) == len(entries) | |
| 36 | 36 | for entry in entries: | |
@@ -91,9 +91,9 @@ def assert_entries(entries, num_entries, has_conflict=False): | |||
| 91 | 91 | assert has_conflict == (len([e for e in entries if e.stage != 0]) > 0) | |
| 92 | 92 | mktree = self.mktree | |
| 93 | 93 | ||
| 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 | ||
| 97 | 97 | ||
| 98 | 98 | odb = rwrepo.odb | |
| 99 | 99 | ||
@@ -256,6 +256,6 @@ def test_tree_traversal_single(self): | |||
| 256 | 256 | assert entries | |
| 257 | 257 | # END for each commit | |
| 258 | 258 | ||
| 259 | - def test_tree_entries_from_data(self): | ||
| 259 | + def test_tree_entries_from_data_with_failing_name_decode(self): | ||
| 260 | 260 | 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 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments