| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -100,9 +100,11 @@ def mode_str_to_int(modestr: Union[bytes, str]) -> int: | |||
| 100 | 100 | module regarding the rwx permissions for user, group and other, special flags | |
| 101 | 101 | and file system flags, such as whether it is a symlink. | |
| 102 | 102 | """ | |
| 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") | ||
| 103 | 106 | mode = 0 | |
| 104 | 107 | for iteration, char in enumerate(reversed(modestr[-6:])): | |
| 105 | - char = cast(Union[str, int], char) | ||
| 106 | 108 | mode += int(char) << iteration * 3 | |
| 107 | 109 | # END for each char | |
| 108 | 110 | return mode | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,6 +22,7 @@ | |||
| 22 | 22 | from git.objects.util import ( | |
| 23 | 23 | altz_to_utctz_str, | |
| 24 | 24 | from_timestamp, | |
| 25 | + mode_str_to_int, | ||
| 25 | 26 | parse_actor_and_date, | |
| 26 | 27 | parse_date, | |
| 27 | 28 | tzoffset, | |
@@ -760,3 +761,10 @@ def test_remove_password_from_command_line(self): | |||
| 760 | 761 | redacted_cmd_6 = remove_password_if_present(cmd_6) | |
| 761 | 762 | assert authorization not in " ".join(redacted_cmd_6) | |
| 762 | 763 | 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 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments