git-fetch: rewrite another shell loop in C
[gitweb.git] / builtin-fetch--tool.c
index 24343ac9b0f9f8f02034a8c921b698f48b0188ff..705a6649a996202f6f7a9da52ddd0292a55d6637 100644 (file)
@@ -283,6 +283,46 @@ static int fetch_native_store(FILE *fp,
        return err;
 }
 
+static int parse_reflist(const char *reflist)
+{
+       const char *ref;
+
+       printf("refs='");
+       for (ref = reflist; ref; ) {
+               const char *next;
+               while (*ref && isspace(*ref))
+                       ref++;
+               if (!*ref)
+                       break;
+               for (next = ref; *next && !isspace(*next); next++)
+                       ;
+               printf("\n%.*s", (int)(next - ref), ref);
+               ref = next;
+       }
+       printf("'\n");
+
+       printf("rref='");
+       for (ref = reflist; ref; ) {
+               const char *next, *colon;
+               while (*ref && isspace(*ref))
+                       ref++;
+               if (!*ref)
+                       break;
+               for (next = ref; *next && !isspace(*next); next++)
+                       ;
+               if (*ref == '.')
+                       ref++;
+               if (*ref == '+')
+                       ref++;
+               colon = strchr(ref, ':');
+               putchar('\n');
+               printf("%.*s", (int)((colon ? colon : next) - ref), ref);
+               ref = next;
+       }
+       printf("'\n");
+       return 0;
+}
+
 int cmd_fetch__tool(int argc, const char **argv, const char *prefix)
 {
        int verbose = 0;
@@ -335,5 +375,11 @@ int cmd_fetch__tool(int argc, const char **argv, const char *prefix)
                fclose(fp);
                return result;
        }
+       if (!strcmp("parse-reflist", argv[1])) {
+               if (argc != 3)
+                       return error("parse-reflist takes 1 arg");
+               return parse_reflist(argv[2]);
+       }
+
        return error("Unknown subcommand: %s", argv[1]);
 }