]> git.ipfire.org Git - thirdparty/git.git/commitdiff
http-fetch: allow custom index-pack args
authorJonathan Tan <jonathantanmy@google.com>
Mon, 22 Feb 2021 19:20:07 +0000 (11:20 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Feb 2021 20:07:40 +0000 (12:07 -0800)
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>
Documentation/git-http-fetch.txt
fetch-pack.c
http-fetch.c
t/t5550-http-fetch-dumb.sh

index 4deb4893f517c3a0bc1e01228f0a28818c05daea..9fa17b60e438381391991c92cfa5045f2ace7f14 100644 (file)
@@ -41,11 +41,17 @@ commit-id::
                <commit-id>['\t'<filename-as-in--w>]
 
 --packfile=<hash>::
-       Instead of a commit id on the command line (which is not expected in
+       For internal use only. Instead of a commit id on the command
+       line (which is not expected in
        this case), 'git http-fetch' fetches the packfile directly at the given
        URL and uses index-pack to generate corresponding .idx and .keep files.
        The hash is used to determine the name of the temporary file and is
-       arbitrary. The output of index-pack is printed to stdout.
+       arbitrary. The output of index-pack is printed to stdout. Requires
+       --index-pack-args.
+
+--index-pack-args=<args>::
+       For internal use only. The command to run on the contents of the
+       downloaded pack. Arguments are URL-encoded separated by spaces.
 
 --recover::
        Verify that everything reachable from target is fetched.  Used after
index 876f90c759a09334bb4a47575c236d27f2887b98..aeac010b0b5779247290b6d9b30b217f27110663 100644 (file)
@@ -1645,6 +1645,9 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
                strvec_pushf(&cmd.args, "--packfile=%.*s",
                             (int) the_hash_algo->hexsz,
                             packfile_uris.items[i].string);
+               strvec_push(&cmd.args, "--index-pack-arg=index-pack");
+               strvec_push(&cmd.args, "--index-pack-arg=--stdin");
+               strvec_push(&cmd.args, "--index-pack-arg=--keep");
                strvec_push(&cmd.args, uri);
                cmd.git_cmd = 1;
                cmd.no_stdin = 1;
index 2d1d9d054f7f95ce8d0cb7ec708c3fb58286ba3e..fa642462a9e63867146c3c563aff9bce7b93d284 100644 (file)
@@ -3,6 +3,7 @@
 #include "exec-cmd.h"
 #include "http.h"
 #include "walker.h"
+#include "strvec.h"
 
 static const char http_fetch_usage[] = "git http-fetch "
 "[-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,
        return rc;
 }
 
-static const char *index_pack_args[] =
-       {"index-pack", "--stdin", "--keep", NULL};
-
 static void fetch_single_packfile(struct object_id *packfile_hash,
-                                 const char *url) {
+                                 const char *url,
+                                 const char **index_pack_args) {
        struct http_pack_request *preq;
        struct slot_results results;
        int ret;
@@ -90,6 +89,7 @@ int cmd_main(int argc, const char **argv)
        int packfile = 0;
        int nongit;
        struct object_id packfile_hash;
+       struct strvec index_pack_args = STRVEC_INIT;
 
        setup_git_directory_gently(&nongit);
 
@@ -116,6 +116,8 @@ int cmd_main(int argc, const char **argv)
                        packfile = 1;
                        if (parse_oid_hex(p, &packfile_hash, &end) || *end)
                                die(_("argument to --packfile must be a valid hash (got '%s')"), p);
+               } else if (skip_prefix(argv[arg], "--index-pack-arg=", &p)) {
+                       strvec_push(&index_pack_args, p);
                }
                arg++;
        }
@@ -128,10 +130,18 @@ int cmd_main(int argc, const char **argv)
        git_config(git_default_config, NULL);
 
        if (packfile) {
-               fetch_single_packfile(&packfile_hash, argv[arg]);
+               if (!index_pack_args.nr)
+                       die(_("--packfile requires --index-pack-args"));
+
+               fetch_single_packfile(&packfile_hash, argv[arg],
+                                     index_pack_args.v);
+
                return 0;
        }
 
+       if (index_pack_args.nr)
+               die(_("--index-pack-args can only be used with --packfile"));
+
        if (commits_on_stdin) {
                commits = walker_targets_stdin(&commit_id, &write_ref);
        } else {
index 483578b2d75409798ae2697742fbf728c6383746..358b322e05bbe2c7277b75d316033b513203757e 100755 (executable)
@@ -224,7 +224,10 @@ test_expect_success 'http-fetch --packfile' '
 
        git init packfileclient &&
        p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && ls objects/pack/pack-*.pack) &&
-       git -C packfileclient http-fetch --packfile=$ARBITRARY "$HTTPD_URL"/dumb/repo_pack.git/$p >out &&
+       git -C packfileclient http-fetch --packfile=$ARBITRARY \
+               --index-pack-arg=index-pack --index-pack-arg=--stdin \
+               --index-pack-arg=--keep \
+               "$HTTPD_URL"/dumb/repo_pack.git/$p >out &&
 
        grep "^keep.[0-9a-f]\{16,\}$" out &&
        cut -c6- out >packhash &&