http-fetch: allow custom index-pack args
This is the next step in teaching fetch-pack to pass its index-pack arguments when processing packfiles referenced by URIs. The "--keep" in fetch-pack.c will be replaced with a full message 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
27e35ba6c6b532ad6fc88b554d437b6892b4e915
4 files changed
+30
-8
Documentation/git-http-fetch.txt
+8
-2
@@ -41,11 +41,17 @@ commit-id::
41
<commit-id>['\t'<filename-as-in--w>]
42
43
--packfile=<hash>::
44
- Instead of a commit id on the command line (which is not expected in
44
+ For internal use only. Instead of a commit id on the command
45
+ line (which is not expected in
46
this case), 'git http-fetch' fetches the packfile directly at the given
47
URL and uses index-pack to generate corresponding .idx and .keep files.
48
The hash is used to determine the name of the temporary file and is
48
- arbitrary. The output of index-pack is printed to stdout.
49
+ arbitrary. The output of index-pack is printed to stdout. Requires
50
+ --index-pack-args.
51
+
52
+--index-pack-args=<args>::
53
+ For internal use only. The command to run on the contents of the
54
+ downloaded pack. Arguments are URL-encoded separated by spaces.
55
56
--recover::
57
Verify that everything reachable from target is fetched. Used after
fetch-pack.c
+3
@@ -1645,6 +1645,9 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
1645
strvec_pushf(&cmd.args, "--packfile=%.*s",
1646
(int) the_hash_algo->hexsz,
1647
packfile_uris.items[i].string);
1648
+ strvec_push(&cmd.args, "--index-pack-arg=index-pack");
1649
+ strvec_push(&cmd.args, "--index-pack-arg=--stdin");
1650
+ strvec_push(&cmd.args, "--index-pack-arg=--keep");
1651
strvec_push(&cmd.args, uri);
1652
cmd.git_cmd = 1;
1653
cmd.no_stdin = 1;
http-fetch.c
+15
-5
@@ -3,6 +3,7 @@
3
#include "exec-cmd.h"
4
#include "http.h"
5
#include "walker.h"
6
+#include "strvec.h"
7
8
static const char http_fetch_usage[] = "git http-fetch "
9
"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin | --packfile=hash | commit-id] url";
@@ -43,11 +44,9 @@ static int fetch_using_walker(const char *raw_url, int get_verbosely,
44
return rc;
45
}
46
46
-static const char *index_pack_args[] =
47
- {"index-pack", "--stdin", "--keep", NULL};
48
-
47
static void fetch_single_packfile(struct object_id *packfile_hash,
50
- const char *url) {
48
+ const char *url,
49
+ const char **index_pack_args) {
50
struct http_pack_request *preq;
51
struct slot_results results;
52
int ret;
@@ -90,6 +89,7 @@ int cmd_main(int argc, const char **argv)
89
int packfile = 0;
90
int nongit;
91
struct object_id packfile_hash;
92
+ struct strvec index_pack_args = STRVEC_INIT;
93
94
setup_git_directory_gently(&nongit);
95
@@ -116,6 +116,8 @@ int cmd_main(int argc, const char **argv)
116
packfile = 1;
117
if (parse_oid_hex(p, &packfile_hash, &end) || *end)
118
die(_("argument to --packfile must be a valid hash (got '%s')"), p);
119
+ } else if (skip_prefix(argv[arg], "--index-pack-arg=", &p)) {
120
+ strvec_push(&index_pack_args, p);
121
}
122
arg++;
123
}
@@ -128,10 +130,18 @@ int cmd_main(int argc, const char **argv)
130
git_config(git_default_config, NULL);
131
132
if (packfile) {
131
- fetch_single_packfile(&packfile_hash, argv[arg]);
133
+ if (!index_pack_args.nr)
134
+ die(_("--packfile requires --index-pack-args"));
135
+
136
+ fetch_single_packfile(&packfile_hash, argv[arg],
137
+ index_pack_args.v);
138
+
139
return 0;
140
}
141
142
+ if (index_pack_args.nr)
143
+ die(_("--index-pack-args can only be used with --packfile"));
144
+
145
if (commits_on_stdin) {
146
commits = walker_targets_stdin(&commit_id, &write_ref);
147
} else {
t/t5550-http-fetch-dumb.sh
+4
-1
@@ -224,7 +224,10 @@ test_expect_success 'http-fetch --packfile' '
224
225
git init packfileclient &&
226
p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && ls objects/pack/pack-*.pack) &&
227
- git -C packfileclient http-fetch --packfile=$ARBITRARY "$HTTPD_URL"/dumb/repo_pack.git/$p >out &&
227
+ git -C packfileclient http-fetch --packfile=$ARBITRARY \
228
+ --index-pack-arg=index-pack --index-pack-arg=--stdin \
229
+ --index-pack-arg=--keep \
230
+ "$HTTPD_URL"/dumb/repo_pack.git/$p >out &&
231
232
grep "^keep.[0-9a-f]\{16,\}$" out &&
233
cut -c6- out >packhash &&