git-svn: rebuild convenience and bugfixes
[gitweb.git] / clone-pack.c
index 2ac35f6825fa84e1f18ba191d943b367744ba9a0..a4370f595f1206840e66d488423f1c7e42029c6d 100644 (file)
@@ -1,12 +1,13 @@
 #include "cache.h"
 #include "refs.h"
 #include "pkt-line.h"
-#include <sys/wait.h>
 
-static int quiet;
-static const char clone_pack_usage[] = "git-clone-pack [-q] [--exec=<git-upload-pack>] [<host>:]<directory> [<heads>]*";
+static const char clone_pack_usage[] =
+"git-clone-pack [--exec=<git-upload-pack>] [<host>:]<directory> [<heads>]*";
 static const char *exec = "git-upload-pack";
 
+static int quiet = 0;
+
 static void clone_handshake(int fd[2], struct ref *ref)
 {
        unsigned char sha1[20];
@@ -116,7 +117,6 @@ static int clone_pack(int fd[2], int nr_match, char **match)
 {
        struct ref *refs;
        int status;
-       pid_t pid;
 
        get_remote_heads(fd[0], &refs, nr_match, match, 1);
        if (!refs) {
@@ -124,35 +124,23 @@ static int clone_pack(int fd[2], int nr_match, char **match)
                die("no matching remote head");
        }
        clone_handshake(fd, refs);
-       pid = fork();
-       if (pid < 0)
-               die("git-clone-pack: unable to fork off git-unpack-objects");
-       if (!pid) {
-               dup2(fd[0], 0);
-               close(fd[0]);
-               close(fd[1]);
-               execlp("git-unpack-objects", "git-unpack-objects",
-                       quiet ? "-q" : NULL, NULL);
-               die("git-unpack-objects exec failed");
-       }
-       close(fd[0]);
-       close(fd[1]);
-       while (waitpid(pid, &status, 0) < 0) {
-               if (errno != EINTR)
-                       die("waiting for git-unpack-objects: %s", strerror(errno));
-       }
-       if (WIFEXITED(status)) {
-               int code = WEXITSTATUS(status);
-               if (code)
-                       die("git-unpack-objects died with error code %d", code);
-               write_refs(refs);
-               return 0;
-       }
-       if (WIFSIGNALED(status)) {
-               int sig = WTERMSIG(status);
-               die("git-unpack-objects died of signal %d", sig);
+
+       status = receive_keep_pack(fd, "git-clone-pack", quiet);
+       if (!quiet)
+               fprintf(stderr, "\n");
+
+       if (!status) {
+               if (nr_match == 0)
+                       write_refs(refs);
+               else
+                       while (refs) {
+                               printf("%s %s\n",
+                                      sha1_to_hex(refs->old_sha1),
+                                      refs->name);
+                               refs = refs->next;
+                       }
        }
-       die("Sherlock Holmes! git-unpack-objects died of unnatural causes %d!", status);
+       return status;
 }
 
 int main(int argc, char **argv)
@@ -162,6 +150,8 @@ int main(int argc, char **argv)
        int fd[2];
        pid_t pid;
 
+       setup_git_directory();
+
        nr_heads = 0;
        heads = NULL;
        for (i = 1; i < argc; i++) {