File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -100,9 +100,11 @@ def mode_str_to_int(modestr: Union[bytes, str]) -> int:
100100 module regarding the rwx permissions for user, group and other, special flags
101101 and file system flags, such as whether it is a symlink.
102102 """
103+ if isinstance (modestr , bytes ):
104+ # A byte is an int. int(b"4"[0]) is 52, so b"100644" became 0o6767524.
105+ modestr = modestr .decode ("ascii" )
103106 mode = 0
104107 for iteration , char in enumerate (reversed (modestr [- 6 :])):
105- char = cast (Union [str , int ], char )
106108 mode += int (char ) << iteration * 3
107109 # END for each char
108110 return mode
Original file line number Diff line number Diff line change 2222from git .objects .util import (
2323 altz_to_utctz_str ,
2424 from_timestamp ,
25+ mode_str_to_int ,
2526 parse_actor_and_date ,
2627 parse_date ,
2728 tzoffset ,
@@ -760,3 +761,10 @@ def test_remove_password_from_command_line(self):
760761 redacted_cmd_6 = remove_password_if_present (cmd_6 )
761762 assert authorization not in " " .join (redacted_cmd_6 )
762763 assert "http.extraHeader=Authorization: *****" in redacted_cmd_6
764+
765+
766+ def test_mode_str_to_int_accepts_bytes ():
767+ assert mode_str_to_int ("100644" ) == 0o100644
768+ assert mode_str_to_int (b"100644" ) == 0o100644
769+ assert mode_str_to_int ("644" ) == 0o644
770+ assert mode_str_to_int (b"120000" ) == 0o120000
You can’t perform that action at this time.
0 commit comments