http: allow custom index-pack args

Currently, when fetching, packfiles referenced by URIs are run through index-pack without any arguments other than --stdin and --keep, no matter what arguments are used for the packfile that is inline in the fetch response. As a preparation for ensuring that all packs (whether inline or not) use the same index-pack arguments, teach the http subsystem to allow custom index-pack arguments. http-fetch has been updated to use the new API. For now, it passes --keep alone instead of --keep with a process ID, but this is only temporary because http-fetch itself will be taught to accept index-pack parameters (instead of using a hardcoded constant) in a subsequent commit. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Feb 22, 2021 at 11:20 UTC 726b25a91ba0e8f26f83c8d39ad16351b7bdb510
3 files changed +18 -13
http-fetch.c
+5 -1
@@ -43,6 +43,9 @@ static int fetch_using_walker(const char *raw_url, int get_verbosely,
43 return rc;
44 }
45
46 +static const char *index_pack_args[] =
47 + {"index-pack", "--stdin", "--keep", NULL};
48 +
49 static void fetch_single_packfile(struct object_id *packfile_hash,
50 const char *url) {
51 struct http_pack_request *preq;
@@ -55,7 +58,8 @@ static void fetch_single_packfile(struct object_id *packfile_hash,
58 if (preq == NULL)
59 die("couldn't create http pack request");
60 preq->slot->results = &results;
58 - preq->generate_keep = 1;
61 + preq->index_pack_args = index_pack_args;
62 + preq->preserve_index_pack_stdout = 1;
63
64 if (start_active_slot(preq->slot)) {
65 run_active_slot(preq->slot);
http.c
+8 -7
@@ -2259,6 +2259,9 @@ void release_http_pack_request(struct http_pack_request *preq)
2259 free(preq);
2260 }
2261
2262 +static const char *default_index_pack_args[] =
2263 + {"index-pack", "--stdin", NULL};
2264 +
2265 int finish_http_pack_request(struct http_pack_request *preq)
2266 {
2267 struct child_process ip = CHILD_PROCESS_INIT;
@@ -2270,17 +2273,15 @@ int finish_http_pack_request(struct http_pack_request *preq)
2273
2274 tmpfile_fd = xopen(preq->tmpfile.buf, O_RDONLY);
2275
2273 - strvec_push(&ip.args, "index-pack");
2274 - strvec_push(&ip.args, "--stdin");
2276 ip.git_cmd = 1;
2277 ip.in = tmpfile_fd;
2277 - if (preq->generate_keep) {
2278 - strvec_pushf(&ip.args, "--keep=git %"PRIuMAX,
2279 - (uintmax_t)getpid());
2278 + ip.argv = preq->index_pack_args ? preq->index_pack_args
2279 + : default_index_pack_args;
2280 +
2281 + if (preq->preserve_index_pack_stdout)
2282 ip.out = 0;
2281 - } else {
2283 + else
2284 ip.no_stdout = 1;
2283 - }
2285
2286 if (run_command(&ip)) {
2287 ret = -1;
http.h
+5 -5
@@ -218,12 +218,12 @@ struct http_pack_request {
218 char *url;
219
220 /*
221 - * If this is true, finish_http_pack_request() will pass "--keep" to
222 - * index-pack, resulting in the creation of a keep file, and will not
223 - * suppress its stdout (that is, the "keep\t<hash>\n" line will be
224 - * printed to stdout).
221 + * index-pack command to run. Must be terminated by NULL.
222 + *
223 + * If NULL, defaults to {"index-pack", "--stdin", NULL}.
224 */
226 - unsigned generate_keep : 1;
225 + const char **index_pack_args;
226 + unsigned preserve_index_pack_stdout : 1;
227
228 FILE *packfile;
229 struct strbuf tmpfile;