gitweb: whitespace cleanup
[gitweb.git] / fetch.c
diff --git a/fetch.c b/fetch.c
index 281df61e7be1a998c4b384ee06bcdabaecd83504..aeb6bf2639cc75b6f738348bcc267179a8a0da65 100644 (file)
--- a/fetch.c
+++ b/fetch.c
@@ -7,6 +7,7 @@
 #include "tag.h"
 #include "blob.h"
 #include "refs.h"
+#include "strbuf.h"
 
 int get_tree = 0;
 int get_history = 0;
@@ -210,6 +211,45 @@ static int mark_complete(const char *path, const unsigned char *sha1)
        return 0;
 }
 
+int pull_targets_stdin(char ***target, const char ***write_ref)
+{
+       int targets = 0, targets_alloc = 0;
+       struct strbuf buf;
+       *target = NULL; *write_ref = NULL;
+       strbuf_init(&buf);
+       while (1) {
+               char *rf_one = NULL;
+               char *tg_one;
+
+               read_line(&buf, stdin, '\n');
+               if (buf.eof)
+                       break;
+               tg_one = buf.buf;
+               rf_one = strchr(tg_one, '\t');
+               if (rf_one)
+                       *rf_one++ = 0;
+
+               if (targets >= targets_alloc) {
+                       targets_alloc = targets_alloc ? targets_alloc * 2 : 64;
+                       *target = xrealloc(*target, targets_alloc * sizeof(**target));
+                       *write_ref = xrealloc(*write_ref, targets_alloc * sizeof(**write_ref));
+               }
+               (*target)[targets] = strdup(tg_one);
+               (*write_ref)[targets] = rf_one ? strdup(rf_one) : NULL;
+               targets++;
+       }
+       return targets;
+}
+
+void pull_targets_free(int targets, char **target, const char **write_ref)
+{
+       while (targets--) {
+               free(target[targets]);
+               if (write_ref && write_ref[targets])
+                       free((char *) write_ref[targets]);
+       }
+}
+
 int pull(int targets, char **target, const char **write_ref,
          const char *write_ref_log_details)
 {
@@ -223,7 +263,7 @@ int pull(int targets, char **target, const char **write_ref,
        track_object_refs = 0;
 
        for (i = 0; i < targets; i++) {
-               if (!write_ref[i])
+               if (!write_ref || !write_ref[i])
                        continue;
 
                lock[i] = lock_ref_sha1(write_ref[i], NULL, 0);
@@ -255,7 +295,7 @@ int pull(int targets, char **target, const char **write_ref,
                msg = NULL;
        }
        for (i = 0; i < targets; i++) {
-               if (!write_ref[i])
+               if (!write_ref || !write_ref[i])
                        continue;
                ret = write_ref_sha1(lock[i], &sha1[20 * i], msg ? msg : "fetch (unknown)");
                lock[i] = NULL;