+ int fd[2];
+ pid_t pid;
+ int create_full_pack = (nr_our_refs == nr_needs && !nr_has);
+
+ if (pipe(fd) < 0)
+ die("git-upload-pack: unable to create pipe");
+ pid = fork();
+ if (pid < 0)
+ die("git-upload-pack: unable to fork git-rev-list");
+
+ if (!pid) {
+ int i;
+ int args;
+ char **argv;
+ char *buf;
+ char **p;
+
+ if (create_full_pack) {
+ args = 10;
+ use_thin_pack = 0; /* no point doing it */
+ }
+ else
+ args = nr_has + nr_needs + 5;
+ argv = xmalloc(args * sizeof(char *));
+ buf = xmalloc(args * 45);
+ p = argv;
+
+ dup2(fd[1], 1);
+ close(0);
+ close(fd[0]);
+ close(fd[1]);
+ *p++ = "rev-list";
+ *p++ = use_thin_pack ? "--objects-edge" : "--objects";
+ if (create_full_pack || MAX_NEEDS <= nr_needs)
+ *p++ = "--all";
+ else {
+ for (i = 0; i < nr_needs; i++) {
+ *p++ = buf;
+ memcpy(buf, sha1_to_hex(needs_sha1[i]), 41);
+ buf += 41;
+ }
+ }
+ if (!create_full_pack)
+ for (i = 0; i < nr_has; i++) {
+ *p++ = buf;
+ *buf++ = '^';
+ memcpy(buf, sha1_to_hex(has_sha1[i]), 41);
+ buf += 41;
+ }
+ *p++ = NULL;
+ execv_git_cmd(argv);
+ die("git-upload-pack: unable to exec git-rev-list");
+ }
+ dup2(fd[0], 0);
+ close(fd[0]);
+ close(fd[1]);
+ execl_git_cmd("pack-objects", "--stdout", NULL);
+ die("git-upload-pack: unable to exec git-pack-objects");