File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -70,9 +70,13 @@ def tree_entries_from_data(data):
7070 # default encoding for strings in git is utf8
7171 # Only use the respective unicode object if the byte stream was encoded
7272 name = data [ns :i ]
73- name_enc = name .decode ("utf-8" )
74- if len (name ) > len (name_enc ):
75- name = name_enc
73+ try :
74+ name_enc = name .decode ("utf-8" )
75+ except UnicodeDecodeError :
76+ pass
77+ else :
78+ if len (name ) > len (name_enc ):
79+ name = name_enc
7680 # END handle encoding
7781
7882 # byte is NULL, get next 20
Original file line number Diff line number Diff line change @@ -249,3 +249,8 @@ def test_tree_traversal_single(self):
249249 entries = traverse_tree_recursive (odb , commit .tree .binsha , '' )
250250 assert entries
251251 # END for each commit
252+
253+ def test_tree_entries_from_data ():
254+ from git .objects .fun import tree_entries_from_data
255+ r = tree_entries_from_data (b'100644 \x9f \0 aaa' )
256+ assert r == [('aaa' , 33188 , '\x9f ' )], r
You can’t perform that action at this time.
0 commit comments