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 <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Tan committed
Jun 10, 2020 at 13:57 UTC
9cb3cab56063754d9ee5bb27886c616ca1aec134
1 file changed
+11
-22
http.c
+11
-22
@@ -2270,9 +2270,9 @@ int finish_http_pack_request(struct http_pack_request *preq)
2270
{
2271
struct packed_git **lst;
2272
struct packed_git *p = preq->target;
2273
- char *tmp_idx;
2274
- size_t len;
2273
struct child_process ip = CHILD_PROCESS_INIT;
2274
+ int tmpfile_fd;
2275
+ int ret = 0;
2276
2277
close_pack_index(p);
2278
@@ -2284,35 +2284,24 @@ int finish_http_pack_request(struct http_pack_request *preq)
2284
lst = &((*lst)->next);
2285
*lst = (*lst)->next;
2286
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);
2288
2289
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");
2291
ip.git_cmd = 1;
2295
- ip.no_stdin = 1;
2292
+ ip.in = tmpfile_fd;
2293
ip.no_stdout = 1;
2294
2295
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;
2298
}
2299
2300
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;
2305
}
2306
2307
struct http_pack_request *new_http_pack_request(