Geoff Lane avatar Geoff Lane committed 680f598

Add support in Hg for unknown and modified using a forked process.
Forked process isn't the most efficient way to do it, but currently
don't know how to get these values with straight C. Hopefully someone
will come behind me and figure it out so it's more efficient.

Comments (0)

Files changed (1)

 #include <arpa/inet.h>
 #endif
 
+#include "capture.h"
 #include "common.h"
 #include "hg.h"
 
     free(last_line);
 }
 
+static void
+read_modified_unknown(vccontext_t *context, result_t *result)
+{
+    // No easy way that we know to get the modified or unknown status
+    // without forking an hg process. Replace this with a more efficient version
+    // if you ever figure it out.
+    if (!context->options->show_modified && !context->options->show_unknown)
+        return;
+
+    char *argv[] = { "hg", "status", "--modified", "--unknown", "--quiet", NULL};
+    capture_t *capture = capture_child("hg", argv);
+    if (capture == NULL) {
+        debug("unable to execute 'hg status'");
+        return;
+    }
+    char *cstdout = capture->childout.buf;
+    if (context->options->show_unknown) {
+        result->unknown = (strstr(cstdout, "? ") != NULL);
+    }
+
+    if (context->options->show_modified) {
+	result->modified = (strstr(cstdout, "M ") != NULL ||
+			    strstr(cstdout, "A ") != NULL||
+			    strstr(cstdout, "! ") != NULL||
+			    strstr(cstdout, "R ") != NULL);
+    }
+
+    cstdout = NULL;
+    free_capture(capture);
+}
+
 static result_t*
 hg_get_info(vccontext_t *context)
 {
 
     read_parents(context, result);
     read_patch_name(context, result);
+    read_modified_unknown(context, result);
 
     return result;
 }
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.