45
45
)
46
46
import io
47
47
48
- execute_kwargs = ('istream' , 'with_keep_cwd' , 'with_extended_output' ,
49
- 'with_exceptions' , 'as_process' , 'stdout_as_string' ,
50
- 'output_stream' , 'with_stdout' , 'kill_after_timeout' ,
51
- 'universal_newlines' )
48
+ execute_kwargs = set ( ('istream' , 'with_keep_cwd' , 'with_extended_output' ,
49
+ 'with_exceptions' , 'as_process' , 'stdout_as_string' ,
50
+ 'output_stream' , 'with_stdout' , 'kill_after_timeout' ,
51
+ 'universal_newlines' ) )
52
52
53
53
log = logging .getLogger ('git.cmd' )
54
54
log .addHandler (logging .NullHandler ())
@@ -275,7 +275,6 @@ def __setstate__(self, d):
275
275
max_chunk_size = io .DEFAULT_BUFFER_SIZE
276
276
277
277
git_exec_name = "git" # default that should work on linux and windows
278
- git_exec_name_win = "git.cmd" # alternate command name, windows only
279
278
280
279
# Enables debugging of GitPython's git commands
281
280
GIT_PYTHON_TRACE = os .environ .get ("GIT_PYTHON_TRACE" , False )
@@ -778,10 +777,7 @@ def update_environment(self, **kwargs):
778
777
for key , value in kwargs .items ():
779
778
# set value if it is None
780
779
if value is not None :
781
- if key in self ._environment :
782
- old_env [key ] = self ._environment [key ]
783
- else :
784
- old_env [key ] = None
780
+ old_env [key ] = self ._environment .get (key )
785
781
self ._environment [key ] = value
786
782
# remove key from environment if its value is None
787
783
elif key in self ._environment :
@@ -897,12 +893,8 @@ def _call_process(self, method, *args, **kwargs):
897
893
:return: Same as ``execute``"""
898
894
# Handle optional arguments prior to calling transform_kwargs
899
895
# otherwise these'll end up in args, which is bad.
900
- _kwargs = dict ()
901
- for kwarg in execute_kwargs :
902
- try :
903
- _kwargs [kwarg ] = kwargs .pop (kwarg )
904
- except KeyError :
905
- pass
896
+ _kwargs = {k : v for k , v in kwargs .items () if k in execute_kwargs }
897
+ kwargs = {k : v for k , v in kwargs .items () if k not in execute_kwargs }
906
898
907
899
insert_after_this_arg = kwargs .pop ('insert_kwargs_after' , None )
908
900
@@ -922,48 +914,17 @@ def _call_process(self, method, *args, **kwargs):
922
914
args = ext_args [:index + 1 ] + opt_args + ext_args [index + 1 :]
923
915
# end handle kwargs
924
916
925
- def make_call ():
926
- call = [self .GIT_PYTHON_GIT_EXECUTABLE ]
917
+ call = [self .GIT_PYTHON_GIT_EXECUTABLE ]
927
918
928
- # add the git options, the reset to empty
929
- # to avoid side_effects
930
- call .extend (self ._git_options )
931
- self ._git_options = ()
932
-
933
- call .extend ([dashify (method )])
934
- call .extend (args )
935
- return call
936
- # END utility to recreate call after changes
919
+ # add the git options, the reset to empty
920
+ # to avoid side_effects
921
+ call .extend (self ._git_options )
922
+ self ._git_options = ()
937
923
938
- if is_win ():
939
- try :
940
- try :
941
- return self .execute (make_call (), ** _kwargs )
942
- except WindowsError :
943
- # did we switch to git.cmd already, or was it changed from default ? permanently fail
944
- if self .GIT_PYTHON_GIT_EXECUTABLE != self .git_exec_name :
945
- raise
946
- # END handle overridden variable
947
- type(self ).GIT_PYTHON_GIT_EXECUTABLE = self .git_exec_name_win
924
+ call .append (dashify (method ))
925
+ call .extend (args )
948
926
949
- try :
950
- return self .execute (make_call (), ** _kwargs )
951
- finally :
952
- import warnings
953
- msg = "WARNING: Automatically switched to use git.cmd as git executable"
954
- msg += ", which reduces performance by ~70%."
955
- msg += "It is recommended to put git.exe into the PATH or to "
956
- msg += "set the %s " % self ._git_exec_env_var
957
- msg += "environment variable to the executable's location"
958
- warnings .warn (msg )
959
- # END print of warning
960
- # END catch first failure
961
- except WindowsError :
962
- raise WindowsError ("The system cannot find or execute the file at %r" % self .GIT_PYTHON_GIT_EXECUTABLE )
963
- # END provide better error message
964
- else :
965
- return self .execute (make_call (), ** _kwargs )
966
- # END handle windows default installation
927
+ return self .execute (call , ** _kwargs )
967
928
968
929
def _parse_object_header (self , header_line ):
969
930
"""
0 commit comments