66
66
67
67
# typing -----------------------------------------------------------------------------
68
68
69
- from typing import (Any , Callable , Dict , IO , Iterable , Iterator , List ,
69
+ from typing import (Any , BinaryIO , Callable , Dict , IO , Iterable , Iterator , List ,
70
70
Sequence , TYPE_CHECKING , Tuple , Union )
71
71
72
72
from git .types import PathLike , TBD
@@ -567,7 +567,8 @@ def write_tree(self) -> Tree:
567
567
root_tree ._cache = tree_items
568
568
return root_tree
569
569
570
- def _process_diff_args (self , args : Any ) -> List [Any ]:
570
+ def _process_diff_args (self , args : List [Union [str , diff .Diffable , object ]]
571
+ ) -> List [Union [str , diff .Diffable , object ]]:
571
572
try :
572
573
args .pop (args .index (self ))
573
574
except IndexError :
@@ -607,13 +608,14 @@ def _preprocess_add_items(self, items: Sequence[Union[PathLike, Blob, BaseIndexE
607
608
# END for each item
608
609
return paths , entries
609
610
610
- def _store_path (self , filepath , fprogress ) :
611
+ def _store_path (self , filepath : PathLike , fprogress : Callable ) -> BaseIndexEntry :
611
612
"""Store file at filepath in the database and return the base index entry
612
613
Needs the git_working_dir decorator active ! This must be assured in the calling code"""
613
614
st = os .lstat (filepath ) # handles non-symlinks as well
614
615
if S_ISLNK (st .st_mode ):
615
616
# in PY3, readlink is string, but we need bytes. In PY2, it's just OS encoded bytes, we assume UTF-8
616
- open_stream = lambda : BytesIO (force_bytes (os .readlink (filepath ), encoding = defenc ))
617
+ open_stream = lambda : BytesIO (force_bytes (os .readlink (filepath ),
618
+ encoding = defenc )) # type: Callable[[], BinaryIO]
617
619
else :
618
620
open_stream = lambda : open (filepath , 'rb' )
619
621
with open_stream () as stream :
@@ -625,16 +627,18 @@ def _store_path(self, filepath, fprogress):
625
627
626
628
@unbare_repo
627
629
@git_working_dir
628
- def _entries_for_paths (self , paths , path_rewriter , fprogress , entries ):
629
- entries_added = []
630
+ def _entries_for_paths (self , paths : List [str ], path_rewriter : Callable , fprogress : Callable ,
631
+ entries : List [BaseIndexEntry ]) -> List [BaseIndexEntry ]:
632
+ entries_added = [] # type: List[BaseIndexEntry]
630
633
if path_rewriter :
631
634
for path in paths :
632
635
if osp .isabs (path ):
633
636
abspath = path
634
- gitrelative_path = path [len (self .repo .working_tree_dir ) + 1 :]
637
+ gitrelative_path = path [len (str ( self .repo .working_tree_dir ) ) + 1 :]
635
638
else :
636
639
gitrelative_path = path
637
- abspath = osp .join (self .repo .working_tree_dir , gitrelative_path )
640
+ if self .repo .working_tree_dir :
641
+ abspath = osp .join (self .repo .working_tree_dir , gitrelative_path )
638
642
# end obtain relative and absolute paths
639
643
640
644
blob = Blob (self .repo , Blob .NULL_BIN_SHA ,
0 commit comments