4 static int finish_pack(const char *pack_tmp_name, const char *me)
11 unsigned char sha1[20];
15 if (pipe(pipe_fd) < 0)
16 die("%s: unable to set up pipe", me);
18 strcpy(idx, pack_tmp_name); /* ".git/objects/pack-XXXXXX" */
19 cp = strrchr(idx, '/');
20 memcpy(cp, "/pidx", 5);
24 die("git-clone-pack: unable to fork off git-index-pack");
30 execlp("git-index-pack","git-index-pack",
31 "-o", idx, pack_tmp_name, NULL);
32 error("cannot exec git-index-pack <%s> <%s>",
37 if (read(pipe_fd[0], hash, 40) != 40) {
38 error("%s: unable to read from git-index-pack", me);
45 int retval = waitpid(pid, &status, 0);
50 error("waitpid failed (%s)", strerror(retval));
53 if (WIFSIGNALED(status)) {
54 int sig = WTERMSIG(status);
55 error("git-index-pack died of signal %d", sig);
58 if (!WIFEXITED(status)) {
59 error("git-index-pack died of unnatural causes %d",
63 code = WEXITSTATUS(status);
65 error("git-index-pack died with error code %d", code);
73 if (get_sha1_hex(hash, sha1)) {
74 error("git-index-pack reported nonsense '%s'", hash);
77 /* Now we have pack in pack_tmp_name[], and
78 * idx in idx[]; rename them to their final names.
80 snprintf(final, sizeof(final),
81 "%s/pack/pack-%s.pack", get_object_directory(), hash);
82 move_temp_to_file(pack_tmp_name, final);
84 snprintf(final, sizeof(final),
85 "%s/pack/pack-%s.idx", get_object_directory(), hash);
86 move_temp_to_file(idx, final);
92 unlink(pack_tmp_name);
96 int receive_unpack_pack(int fd[2], const char *me, int quiet)
103 die("%s: unable to fork off git-unpack-objects", me);
108 execlp("git-unpack-objects", "git-unpack-objects",
109 quiet ? "-q" : NULL, NULL);
110 die("git-unpack-objects exec failed");
114 while (waitpid(pid, &status, 0) < 0) {
116 die("waiting for git-unpack-objects: %s",
119 if (WIFEXITED(status)) {
120 int code = WEXITSTATUS(status);
122 die("git-unpack-objects died with error code %d",
126 if (WIFSIGNALED(status)) {
127 int sig = WTERMSIG(status);
128 die("git-unpack-objects died of signal %d", sig);
130 die("git-unpack-objects died of unnatural causes %d", status);
133 int receive_keep_pack(int fd[2], const char *me)
135 char tmpfile[PATH_MAX];
139 snprintf(tmpfile, sizeof(tmpfile),
140 "%s/pack/tmp-XXXXXX", get_object_directory());
141 ofd = mkstemp(tmpfile);
143 return error("unable to create temporary file %s", tmpfile);
147 ssize_t sz, wsz, pos;
148 sz = read(ifd, buf, sizeof(buf));
152 error("error reading pack (%s)", strerror(errno));
159 wsz = write(ofd, buf + pos, sz - pos);
161 error("error writing pack (%s)",
171 return finish_pack(tmpfile, me);