Преглед на файлове

Move finding of C git into a separate function.

This allows it to only be called when SubprocessGitClient is actually
used.
Jelmer Vernooij преди 10 години
родител
ревизия
f0c8295c46
променени са 1 файла, в които са добавени 19 реда и са изтрити 11 реда
  1. 19 11
      dulwich/client.py

+ 19 - 11
dulwich/client.py

@@ -650,6 +650,21 @@ class SubprocessWrapper(object):
         self.proc.wait()
 
 
+def find_git_command():
+    """Find command to run for system Git (usually C Git).
+    """
+    if sys.platform == 'win32': # support .exe, .bat and .cmd
+        try: # to avoid overhead
+            import win32api
+        except ImportError: # run through cmd.exe with some overhead
+            return ['cmd', '/c', 'git']
+        else:
+            status, git = win32api.FindExecutable('git')
+            return [git]
+    else:
+        return ['git']
+
+
 class SubprocessGitClient(TraditionalGitClient):
     """Git client that talks to a server using a subprocess."""
 
@@ -661,20 +676,13 @@ class SubprocessGitClient(TraditionalGitClient):
             del kwargs['stderr']
         TraditionalGitClient.__init__(self, *args, **kwargs)
 
-    git = ['git']
-    if sys.platform == 'win32': # support .exe, .bat and .cmd
-        try: # to avoid overhead
-            import win32api
-        except ImportError: # run through cmd.exe with some overhead
-            git = ['cmd', '/c'] + git
-        else:
-            status, git = win32api.FindExecutable('git')
-            #TODO: need to check status? (exc is raised if not found)
-            git = [git]
+    git_command = None
 
     def _connect(self, service, path):
         import subprocess
-        argv = self.git + [service, path]
+        if self.git_command is None:
+            git_command = find_git_command()
+        argv = git_command + [service, path]
         p = SubprocessWrapper(
             subprocess.Popen(argv, bufsize=0, stdin=subprocess.PIPE,
                              stdout=subprocess.PIPE,