Skip to content

Commit 27e35ba

Browse files
jonathantanmygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 726b25a commit 27e35ba

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

Documentation/git-http-fetch.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,17 @@ commit-id::
4141
<commit-id>['\t'<filename-as-in--w>]
4242

4343
--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
4546
this case), 'git http-fetch' fetches the packfile directly at the given
4647
URL and uses index-pack to generate corresponding .idx and .keep files.
4748
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.
4955

5056
--recover::
5157
Verify that everything reachable from target is fetched. Used after

fetch-pack.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,9 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
16451645
strvec_pushf(&cmd.args, "--packfile=%.*s",
16461646
(int) the_hash_algo->hexsz,
16471647
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");
16481651
strvec_push(&cmd.args, uri);
16491652
cmd.git_cmd = 1;
16501653
cmd.no_stdin = 1;

http-fetch.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "exec-cmd.h"
44
#include "http.h"
55
#include "walker.h"
6+
#include "strvec.h"
67

78
static const char http_fetch_usage[] = "git http-fetch "
89
"[-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,
4344
return rc;
4445
}
4546

46-
static const char *index_pack_args[] =
47-
{"index-pack", "--stdin", "--keep", NULL};
48-
4947
static void fetch_single_packfile(struct object_id *packfile_hash,
50-
const char *url) {
48+
const char *url,
49+
const char **index_pack_args) {
5150
struct http_pack_request *preq;
5251
struct slot_results results;
5352
int ret;
@@ -90,6 +89,7 @@ int cmd_main(int argc, const char **argv)
9089
int packfile = 0;
9190
int nongit;
9291
struct object_id packfile_hash;
92+
struct strvec index_pack_args = STRVEC_INIT;
9393

9494
setup_git_directory_gently(&nongit);
9595

@@ -116,6 +116,8 @@ int cmd_main(int argc, const char **argv)
116116
packfile = 1;
117117
if (parse_oid_hex(p, &packfile_hash, &end) || *end)
118118
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);
119121
}
120122
arg++;
121123
}
@@ -128,10 +130,18 @@ int cmd_main(int argc, const char **argv)
128130
git_config(git_default_config, NULL);
129131

130132
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+
132139
return 0;
133140
}
134141

142+
if (index_pack_args.nr)
143+
die(_("--index-pack-args can only be used with --packfile"));
144+
135145
if (commits_on_stdin) {
136146
commits = walker_targets_stdin(&commit_id, &write_ref);
137147
} else {

t/t5550-http-fetch-dumb.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,10 @@ test_expect_success 'http-fetch --packfile' '
224224
225225
git init packfileclient &&
226226
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 &&
228231
229232
grep "^keep.[0-9a-f]\{16,\}$" out &&
230233
cut -c6- out >packhash &&

0 commit comments

Comments
 (0)