5 static int finish_pack(const char *pack_tmp_name
, const char *me
)
12 unsigned char sha1
[20];
16 if (pipe(pipe_fd
) < 0)
17 die("%s: unable to set up pipe", me
);
19 strcpy(idx
, pack_tmp_name
); /* ".git/objects/pack-XXXXXX" */
20 cp
= strrchr(idx
, '/');
21 memcpy(cp
, "/pidx", 5);
25 die("git-clone-pack: unable to fork off git-index-pack");
31 execl_git_cmd("index-pack", "-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(errno
));
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 execl_git_cmd("unpack-objects", quiet
? "-q" : NULL
, NULL
);
109 die("git-unpack-objects exec failed");
113 while (waitpid(pid
, &status
, 0) < 0) {
115 die("waiting for git-unpack-objects: %s",
118 if (WIFEXITED(status
)) {
119 int code
= WEXITSTATUS(status
);
121 die("git-unpack-objects died with error code %d",
125 if (WIFSIGNALED(status
)) {
126 int sig
= WTERMSIG(status
);
127 die("git-unpack-objects died of signal %d", sig
);
129 die("git-unpack-objects died of unnatural causes %d", status
);
132 int receive_keep_pack(int fd
[2], const char *me
)
134 char tmpfile
[PATH_MAX
];
138 snprintf(tmpfile
, sizeof(tmpfile
),
139 "%s/pack/tmp-XXXXXX", get_object_directory());
140 ofd
= mkstemp(tmpfile
);
142 return error("unable to create temporary file %s", tmpfile
);
146 ssize_t sz
, wsz
, pos
;
147 sz
= read(ifd
, buf
, sizeof(buf
));
151 error("error reading pack (%s)", strerror(errno
));
158 wsz
= write(ofd
, buf
+ pos
, sz
- pos
);
160 error("error writing pack (%s)",
170 return finish_pack(tmpfile
, me
);