made subprocess not use a shell...
authorFlorian Apolloner <florian@apolloner.eu>
Tue, 20 May 2008 21:26:06 +0000 (23:26 +0200)
committerFlorian Apolloner <florian@apolloner.eu>
Tue, 20 May 2008 21:26:06 +0000 (23:26 +0200)
lib/git_python/__init__.py
lib/git_python/git.py
lib/git_python/utils.py

index 71142a400ba79be06956873b2c395e9ca08e1571..11f933139bbcf1d07e92385d2bfb16facc39fcb5 100644 (file)
@@ -11,7 +11,7 @@ from git_python.repo import Repo
 from git_python.stats import Stats
 from git_python.tag import Tag
 from git_python.tree import Tree
-from git_python.utils import shell_escape, dashify, touch
+from git_python.utils import dashify, touch
 
 __all__ = [ name for name, obj in locals().items()
             if not (name.startswith('_') or inspect.ismodule(obj)) ]
index 2251ecb251ae6cd741351dbf159de651ef7154eb..25cd1cce114c7db946f235ac8fb33e849811129e 100644 (file)
@@ -12,8 +12,6 @@ class Git(MethodMissingMixin):
         super(Git, self).__init__()
         self.git_dir = git_dir
 
-    git_binary = "/usr/bin/env git"
-
     @property
     def get_dir(self):
         return self.git_dir
@@ -26,12 +24,14 @@ class Git(MethodMissingMixin):
         ``command``
             The command to execute
         """
-        print command
+        print ' '.join(command)
         proc = subprocess.Popen(command,
-                                shell=True,
+                                cwd = self.git_dir,
                                 stdout=subprocess.PIPE
                                 )
-        stdout_value = proc.communicate()[0]
+        proc.wait()
+        stdout_value = proc.stdout.read()
+        proc.stdout.close()
         return stdout_value
 
     def transform_kwargs(self, **kwargs):
@@ -44,12 +44,13 @@ class Git(MethodMissingMixin):
                 if v is True:
                     args.append("-%s" % k)
                 else:
-                    args.append("-%s %r" % (k, v))
+                    args.append("-%s" % k)
+                    args.append(v)
             else:
                 if v is True:
                     args.append("--%s" % dashify(k))
                 else:
-                    args.append("--%s=%r" % (dashify(k), v))
+                    args.append("--%s=%s" % (dashify(k), v))
         return args
 
     def method_missing(self, method, *args, **kwargs):
@@ -73,9 +74,10 @@ class Git(MethodMissingMixin):
             str
         """
         opt_args = self.transform_kwargs(**kwargs)
-        ext_args = map(lambda a: (a == '--') and a or "%s" % shell_escape(a), args)
+        ext_args = map(lambda a: (a == '--') and a or "%s" % a, args)
         args = opt_args + ext_args
 
-        call = "%s --git-dir=%s %s %s" % (self.git_binary, self.git_dir, dashify(method), ' '.join(args))
+        call = ['git-'+dashify(method)]
+        call.extend(args)
         stdout_value = self.execute(call)
         return stdout_value
index 2bd6f2cd8e5e633722a9e9923606c2d9e46e2009..c2140ba0d8e77502c2b30c3b1fbbcf73d7c15aea 100644 (file)
@@ -1,6 +1,3 @@
-def shell_escape(string):
-    return str(string).replace("'", "\\\\'")
-
 def dashify(string):
     return string.replace('_', '-')