git p4: implement view spec wildcards with "p4 where"
[gitweb.git] / test-path-utils.c
index 0092cbf3540e2fdfd2e882461ba39ba2a833b672..bb975e4d3eaf54bb162ecdad8b4b8995c84fb035 100644 (file)
@@ -28,6 +28,19 @@ static int normalize_ceiling_entry(struct string_list_item *item, void *unused)
        return 1;
 }
 
+static void normalize_argv_string(const char **var, const char *input)
+{
+       if (!strcmp(input, "<null>"))
+               *var = NULL;
+       else if (!strcmp(input, "<empty>"))
+               *var = "";
+       else
+               *var = input;
+
+       if (*var && (**var == '<' || **var == '('))
+               die("Bad value: %s\n", input);
+}
+
 int main(int argc, char **argv)
 {
        if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
@@ -103,6 +116,25 @@ int main(int argc, char **argv)
                return 0;
        }
 
+       if (argc == 3 && !strcmp(argv[1], "mingw_path")) {
+               puts(argv[2]);
+               return 0;
+       }
+
+       if (argc == 4 && !strcmp(argv[1], "relative_path")) {
+               struct strbuf sb = STRBUF_INIT;
+               const char *in, *prefix, *rel;
+               normalize_argv_string(&in, argv[2]);
+               normalize_argv_string(&prefix, argv[3]);
+               rel = relative_path(in, prefix, &sb);
+               if (!rel)
+                       puts("(null)");
+               else
+                       puts(strlen(rel) > 0 ? rel : "(empty)");
+               strbuf_release(&sb);
+               return 0;
+       }
+
        fprintf(stderr, "%s: unknown function name: %s\n", argv[0],
                argv[1] ? argv[1] : "(there was none)");
        return 1;