Skip to content

Commit b6d3ccd

Browse files
jonathantanmygitster
authored andcommitted
http: use --stdin when getting dumb HTTP pack
When Git fetches a pack using dumb HTTP, it reuses the server's name for the packfile (which incorporates a hash), which is different from the behavior of fetch-pack and receive-pack. A subsequent patch will allow downloading packs over HTTP(S) as part of a fetch. These downloads will not necessarily be from a Git repository, and thus may not have a hash as part of its name. Thus, teach http to pass --stdin to index-pack, so that we have no reliance on the server's name for the packfile. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 572e460 commit b6d3ccd

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

http.c

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,9 +2204,9 @@ int finish_http_pack_request(struct http_pack_request *preq)
22042204
{
22052205
struct packed_git **lst;
22062206
struct packed_git *p = preq->target;
2207-
char *tmp_idx;
2208-
size_t len;
22092207
struct child_process ip = CHILD_PROCESS_INIT;
2208+
int tmpfile_fd;
2209+
int ret = 0;
22102210

22112211
close_pack_index(p);
22122212

@@ -2218,35 +2218,24 @@ int finish_http_pack_request(struct http_pack_request *preq)
22182218
lst = &((*lst)->next);
22192219
*lst = (*lst)->next;
22202220

2221-
if (!strip_suffix(preq->tmpfile.buf, ".pack.temp", &len))
2222-
BUG("pack tmpfile does not end in .pack.temp?");
2223-
tmp_idx = xstrfmt("%.*s.idx.temp", (int)len, preq->tmpfile.buf);
2221+
tmpfile_fd = xopen(preq->tmpfile.buf, O_RDONLY);
22242222

22252223
argv_array_push(&ip.args, "index-pack");
2226-
argv_array_pushl(&ip.args, "-o", tmp_idx, NULL);
2227-
argv_array_push(&ip.args, preq->tmpfile.buf);
2224+
argv_array_push(&ip.args, "--stdin");
22282225
ip.git_cmd = 1;
2229-
ip.no_stdin = 1;
2226+
ip.in = tmpfile_fd;
22302227
ip.no_stdout = 1;
22312228

22322229
if (run_command(&ip)) {
2233-
unlink(preq->tmpfile.buf);
2234-
unlink(tmp_idx);
2235-
free(tmp_idx);
2236-
return -1;
2237-
}
2238-
2239-
unlink(sha1_pack_index_name(p->sha1));
2240-
2241-
if (finalize_object_file(preq->tmpfile.buf, sha1_pack_name(p->sha1))
2242-
|| finalize_object_file(tmp_idx, sha1_pack_index_name(p->sha1))) {
2243-
free(tmp_idx);
2244-
return -1;
2230+
ret = -1;
2231+
goto cleanup;
22452232
}
22462233

22472234
install_packed_git(the_repository, p);
2248-
free(tmp_idx);
2249-
return 0;
2235+
cleanup:
2236+
close(tmpfile_fd);
2237+
unlink(preq->tmpfile.buf);
2238+
return ret;
22502239
}
22512240

22522241
struct http_pack_request *new_http_pack_request(

0 commit comments

Comments
 (0)