@@ -736,13 +736,14 @@ def add(self, items, force=True, fprogress=lambda *args: None):
736736 do not exist.
737737 """
738738 # UTILITIES
739- def raise_exc (e ):
740- raise e
741-
742- def expand_paths (paths ):
739+ def iter_expand_paths (paths ):
743740 """Expand the directories in list of paths to the corresponding paths accordingly,
744- they will always be relative to the repository"""
745- out = list ()
741+
742+ Note: git will add items multiple times even if a glob overlapped
743+ with manually specified paths or if paths where specified multiple
744+ times - we respect that and do not prune"""
745+ def raise_exc (e ):
746+ raise e
746747 r = self .repo .git .git_dir
747748 rs = r + '/'
748749 for path in paths :
@@ -753,26 +754,22 @@ def expand_paths(paths):
753754
754755 # resolve globs if possible
755756 if '?' in path or '*' in path or '[' in path :
756- out .extend (f .replace (rs , '' ) for f in expand_paths (glob .glob (abs_path )))
757+ for f in iter_expand_paths (glob .glob (abs_path )):
758+ yield f .replace (rs , '' )
757759 continue
758760 # END glob handling
759761 try :
760762 for root , dirs , files in os .walk (abs_path , onerror = raise_exc ):
761763 for rela_file in files :
762764 # add relative paths only
763- out . append ( os .path .join (root .replace (rs , '' ), rela_file ) )
765+ yield os .path .join (root .replace (rs , '' ), rela_file )
764766 # END for each file in subdir
765767 # END for each subdirectory
766768 except OSError :
767769 # was a file or something that could not be iterated
768- out . append ( path )
770+ yield path . replace ( rs , '' )
769771 # END path exception handling
770772 # END for each path
771-
772- # NOTE: git will add items multiple times even if a glob overlapped
773- # with manually specified paths or if paths where specified multiple
774- # times - we respect that and do not prune
775- return out
776773 # END expand helper method
777774
778775 def write_path_to_stdin (proc , filepath , item , fmakeexc , read_from_stdout = True ):
@@ -812,10 +809,9 @@ def write_path_to_stdin(proc, filepath, item, fmakeexc, read_from_stdout=True):
812809 args = ("--add" , "--replace" , "--verbose" , "--stdin" )
813810 proc = self .repo .git .update_index (* args , ** {'as_process' :True , 'istream' :subprocess .PIPE })
814811 make_exc = lambda : GitCommandError (("git-update-index" ,)+ args , 128 , proc .stderr .readline ())
815- filepaths = expand_paths (paths )
816812 added_files = list ()
817813
818- for filepath in filepaths :
814+ for filepath in iter_expand_paths ( paths ) :
819815 write_path_to_stdin (proc , filepath , filepath , make_exc , read_from_stdout = False )
820816 added_files .append (filepath )
821817 # END for each filepath
0 commit comments