FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

objects: decode a byte mode before reading its digits by SashaMIT · Pull Request #2261 · gitpython-developers/GitPython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 3 additions & 1 deletion git/objects/util.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ def mode_str_to_int(modestr: Union[bytes, str]) -> int:
module regarding the rwx permissions for user, group and other, special flags
and file system flags, such as whether it is a symlink.
"""
if isinstance(modestr, bytes):
# A byte is an int. int(b"4"[0]) is 52, so b"100644" became 0o6767524.
modestr = modestr.decode("ascii")
mode = 0
for iteration, char in enumerate(reversed(modestr[-6:])):
char = cast(Union[str, int], char)
mode += int(char) << iteration * 3
# END for each char
return mode
Expand Down
8 changes: 8 additions & 0 deletions test/test_util.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from git.objects.util import (
altz_to_utctz_str,
from_timestamp,
mode_str_to_int,
parse_actor_and_date,
parse_date,
tzoffset,
Expand Down Expand Up @@ -760,3 +761,10 @@ def test_remove_password_from_command_line(self):
redacted_cmd_6 = remove_password_if_present(cmd_6)
assert authorization not in " ".join(redacted_cmd_6)
assert "http.extraHeader=Authorization: *****" in redacted_cmd_6


def test_mode_str_to_int_accepts_bytes():
assert mode_str_to_int("100644") == 0o100644
assert mode_str_to_int(b"100644") == 0o100644
assert mode_str_to_int("644") == 0o644
assert mode_str_to_int(b"120000") == 0o120000
Loading

Back | FazBrowse Home | New Git URL