Skip to content

Commit 9cb3cab

Browse files
jonathantanmygitster
authored andcommitted
http: use --stdin when indexing dumb HTTP pack
When Git fetches a pack using dumb HTTP, (among other things) it invokes index-pack on a ".pack.temp" packfile, specifying the filename as an argument. A future commit will require the aforementioned invocation of index-pack to also generate a "keep" file. To use this, we either have to use index-pack's naming convention (because --keep requires the pack's filename to end with ".pack") or to pass the pack through stdin. Of the two, it is simpler to pass the pack through stdin. Thus, teach http to pass --stdin to index-pack. As a bonus, the code is now simpler. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 339a984 commit 9cb3cab

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
@@ -2270,9 +2270,9 @@ int finish_http_pack_request(struct http_pack_request *preq)
22702270
{
22712271
struct packed_git **lst;
22722272
struct packed_git *p = preq->target;
2273-
char *tmp_idx;
2274-
size_t len;
22752273
struct child_process ip = CHILD_PROCESS_INIT;
2274+
int tmpfile_fd;
2275+
int ret = 0;
22762276

22772277
close_pack_index(p);
22782278

@@ -2284,35 +2284,24 @@ int finish_http_pack_request(struct http_pack_request *preq)
22842284
lst = &((*lst)->next);
22852285
*lst = (*lst)->next;
22862286

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

22912289
argv_array_push(&ip.args, "index-pack");
2292-
argv_array_pushl(&ip.args, "-o", tmp_idx, NULL);
2293-
argv_array_push(&ip.args, preq->tmpfile.buf);
2290+
argv_array_push(&ip.args, "--stdin");
22942291
ip.git_cmd = 1;
2295-
ip.no_stdin = 1;
2292+
ip.in = tmpfile_fd;
22962293
ip.no_stdout = 1;
22972294

22982295
if (run_command(&ip)) {
2299-
unlink(preq->tmpfile.buf);
2300-
unlink(tmp_idx);
2301-
free(tmp_idx);
2302-
return -1;
2303-
}
2304-
2305-
unlink(sha1_pack_index_name(p->hash));
2306-
2307-
if (finalize_object_file(preq->tmpfile.buf, sha1_pack_name(p->hash))
2308-
|| finalize_object_file(tmp_idx, sha1_pack_index_name(p->hash))) {
2309-
free(tmp_idx);
2310-
return -1;
2296+
ret = -1;
2297+
goto cleanup;
23112298
}
23122299

23132300
install_packed_git(the_repository, p);
2314-
free(tmp_idx);
2315-
return 0;
2301+
cleanup:
2302+
close(tmpfile_fd);
2303+
unlink(preq->tmpfile.buf);
2304+
return ret;
23162305
}
23172306

23182307
struct http_pack_request *new_http_pack_request(

0 commit comments

Comments
 (0)