Greg Ward avatar Greg Ward committed 10dc39e

git: use capture_child() instead of system().

Comments (0)

Files changed (1)

 #include <stdlib.h>
 #include <string.h>
 #include <sys/wait.h>
+
 #include "git.h"
+#include "capture.h"
+#include "common.h"
+
 
 static int
 git_probe(vccontext_t* context)
             }
         }
         if (context->options->show_modified) {
-            int status = system("git diff --no-ext-diff --quiet --exit-code");
-            if (WEXITSTATUS(status) == 1)       /* files modified */
-                result->modified = 1;
+            char *argv[] = {
+                "git", "diff", "--no-ext-diff", "--quiet", "--exit-code", NULL};
+            capture_t *capture = capture_child("git", argv);
+            result->modified = (capture->status == 1);
+
             /* any other outcome (including failure to fork/exec,
                failure to run git, or diff error): assume no
                modifications */
+            free_capture(capture);
         }
         if (context->options->show_unknown) {
-            int status = system("test -n \"$(git ls-files --others --exclude-standard)\"");
-            if (WEXITSTATUS(status) == 0)
-                result->unknown = 1;
+            char *argv[] = {
+                "git", "ls-files", "--others", "--exclude-standard", NULL};
+            capture_t *capture = capture_child("git", argv);
+            result->unknown = (capture != NULL && capture->stdout.len > 0);
+
             /* again, ignore other errors and assume no unknown files */
+            free_capture(capture);
         }
     }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.