6 static int finish_pack(const char *pack_tmp_name
, const char *me
)
13 unsigned char sha1
[20];
17 if (pipe(pipe_fd
) < 0)
18 die("%s: unable to set up pipe", me
);
20 strcpy(idx
, pack_tmp_name
); /* ".git/objects/pack-XXXXXX" */
21 cp
= strrchr(idx
, '/');
22 memcpy(cp
, "/pidx", 5);
26 die("git-clone-pack: unable to fork off git-index-pack");
32 execl_git_cmd("index-pack", "-o", idx
, pack_tmp_name
, NULL
);
33 error("cannot exec git-index-pack <%s> <%s>",
38 if (read(pipe_fd
[0], hash
, 40) != 40) {
39 error("%s: unable to read from git-index-pack", me
);
46 int retval
= waitpid(pid
, &status
, 0);
51 error("waitpid failed (%s)", strerror(errno
));
54 if (WIFSIGNALED(status
)) {
55 int sig
= WTERMSIG(status
);
56 error("git-index-pack died of signal %d", sig
);
59 if (!WIFEXITED(status
)) {
60 error("git-index-pack died of unnatural causes %d",
64 code
= WEXITSTATUS(status
);
66 error("git-index-pack died with error code %d", code
);
74 if (get_sha1_hex(hash
, sha1
)) {
75 error("git-index-pack reported nonsense '%s'", hash
);
78 /* Now we have pack in pack_tmp_name[], and
79 * idx in idx[]; rename them to their final names.
81 snprintf(final
, sizeof(final
),
82 "%s/pack/pack-%s.pack", get_object_directory(), hash
);
83 move_temp_to_file(pack_tmp_name
, final
);
85 snprintf(final
, sizeof(final
),
86 "%s/pack/pack-%s.idx", get_object_directory(), hash
);
87 move_temp_to_file(idx
, final
);
93 unlink(pack_tmp_name
);
97 int receive_unpack_pack(int fd
[2], const char *me
, int quiet
)
104 die("%s: unable to fork off git-unpack-objects", me
);
109 execl_git_cmd("unpack-objects", 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
, int quiet
)
135 char tmpfile
[PATH_MAX
];
138 static struct timeval prev_tv
;
141 snprintf(tmpfile
, sizeof(tmpfile
),
142 "%s/pack/tmp-XXXXXX", get_object_directory());
143 ofd
= mkstemp(tmpfile
);
145 return error("unable to create temporary file %s", tmpfile
);
147 gettimeofday(&prev_tv
, NULL
);
151 ssize_t sz
, wsz
, pos
;
152 sz
= read(ifd
, buf
, sizeof(buf
));
156 error("error reading pack (%s)", strerror(errno
));
163 wsz
= write(ofd
, buf
+ pos
, sz
- pos
);
165 error("error writing pack (%s)",
175 static unsigned long last
;
177 unsigned long diff
= total
- last
;
178 /* not really "msecs", but a power-of-two millisec (1/1024th of a sec) */
181 gettimeofday(&tv
, NULL
);
182 msecs
= tv
.tv_sec
- prev_tv
.tv_sec
;
184 msecs
+= (int)(tv
.tv_usec
- prev_tv
.tv_usec
) >> 10;
188 fprintf(stderr
, "%4lu.%03luMB (%lu kB/s) \r",
190 1000*((total
>> 10) & 1023)>>10,
196 return finish_pack(tmpfile
, me
);