4545)
4646import io
4747
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' ) )
5252
5353log = logging .getLogger ('git.cmd' )
5454log .addHandler (logging .NullHandler ())
@@ -275,7 +275,6 @@ def __setstate__(self, d):
275275max_chunk_size = io .DEFAULT_BUFFER_SIZE
276276
277277git_exec_name = "git" # default that should work on linux and windows
278- git_exec_name_win = "git.cmd" # alternate command name, windows only
279278
280279# Enables debugging of GitPython's git commands
281280GIT_PYTHON_TRACE = os .environ .get ("GIT_PYTHON_TRACE" ,False )
@@ -778,10 +777,7 @@ def update_environment(self, **kwargs):
778777for key ,value in kwargs .items ():
779778# set value if it is None
780779if 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 )
785781self ._environment [key ]= value
786782# remove key from environment if its value is None
787783elif key in self ._environment :
@@ -897,12 +893,8 @@ def _call_process(self, method, *args, **kwargs):
897893 :return: Same as ``execute``"""
898894# Handle optional arguments prior to calling transform_kwargs
899895# 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 }
906898
907899insert_after_this_arg = kwargs .pop ('insert_kwargs_after' ,None )
908900
@@ -922,48 +914,17 @@ def _call_process(self, method, *args, **kwargs):
922914args = ext_args [:index + 1 ]+ opt_args + ext_args [index + 1 :]
923915# end handle kwargs
924916
925- def make_call ():
926- call = [self .GIT_PYTHON_GIT_EXECUTABLE ]
917+ call = [self .GIT_PYTHON_GIT_EXECUTABLE ]
927918
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 = ()
937923
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 )
948926
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 )
967928
968929def _parse_object_header (self ,header_line ):
969930"""