diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2021-06-26 10:09:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-26 10:09:53 +0800 |
commit | 2d2ff037f9f7a9ae33e5f4f6bdb75b669a1af19a (patch) | |
tree | 5f4fd00ad13fa5455dc876ab9cb9cc4f9b66bdfc /git/objects/fun.py | |
parent | 703280b8c3df6f9b1a5cbe0997b717edbcaa8979 (diff) | |
parent | 5d7b8ba9f2e9298496232e4ae66bd904a1d71001 (diff) | |
download | gitpython-2d2ff037f9f7a9ae33e5f4f6bdb75b669a1af19a.tar.gz |
Merge pull request #1279 from Yobmod/main
Finish typing object, improve verious other types.
Diffstat (limited to 'git/objects/fun.py')
-rw-r--r-- | git/objects/fun.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/git/objects/fun.py b/git/objects/fun.py index 9b36712e..339a53b8 100644 --- a/git/objects/fun.py +++ b/git/objects/fun.py @@ -1,10 +1,19 @@ """Module with functions which are supposed to be as fast as possible""" from stat import S_ISDIR + from git.compat import ( safe_decode, defenc ) +# typing ---------------------------------------------- + +from typing import List, Tuple + + +# --------------------------------------------------- + + __all__ = ('tree_to_stream', 'tree_entries_from_data', 'traverse_trees_recursive', 'traverse_tree_recursive') @@ -38,7 +47,7 @@ def tree_to_stream(entries, write): # END for each item -def tree_entries_from_data(data): +def tree_entries_from_data(data: bytes) -> List[Tuple[bytes, int, str]]: """Reads the binary representation of a tree and returns tuples of Tree items :param data: data block with tree data (as bytes) :return: list(tuple(binsha, mode, tree_relative_path), ...)""" @@ -72,8 +81,8 @@ def tree_entries_from_data(data): # default encoding for strings in git is utf8 # Only use the respective unicode object if the byte stream was encoded - name = data[ns:i] - name = safe_decode(name) + name_bytes = data[ns:i] + name = safe_decode(name_bytes) # byte is NULL, get next 20 i += 1 |