Signed-off-by: Nguyễn Thái Ngọc Duy <pclo...@gmail.com>
---
 Documentation/git-fetch-pack.txt    |  4 ++++
 Documentation/gitremote-helpers.txt |  3 +++
 builtin/fetch-pack.c                |  7 +++++++
 remote-curl.c                       | 14 +++++++++++++-
 t/t5551-http-fetch.sh               |  9 +++++++++
 transport-helper.c                  |  3 +++
 6 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/Documentation/git-fetch-pack.txt b/Documentation/git-fetch-pack.txt
index 1e71754..b68cd45 100644
--- a/Documentation/git-fetch-pack.txt
+++ b/Documentation/git-fetch-pack.txt
@@ -87,6 +87,10 @@ be in a separate packet, and the list must end with a flush 
packet.
        'git-upload-pack' treats the special depth 2147483647 as
        infinite even if there is an ancestor-chain that long.
 
+--pack-version=<n>::
+       Define the preferred pack format version for data transfer.
+       Valid values are 2 and 4. Default is 2.
+
 --no-progress::
        Do not show the progress.
 
diff --git a/Documentation/gitremote-helpers.txt 
b/Documentation/gitremote-helpers.txt
index 0827f69..90dfc2e 100644
--- a/Documentation/gitremote-helpers.txt
+++ b/Documentation/gitremote-helpers.txt
@@ -416,6 +416,9 @@ set by Git if the remote helper has the 'option' capability.
        must not rely on this option being set before
        connect request occurs.
 
+'option packv4 \{'true'|'false'\}::
+       Prefer pack version 4 (true) or 2 (false) for data transfer.
+
 SEE ALSO
 --------
 linkgit:git-remote[1]
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index aba4465..bfe940a 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -100,6 +100,13 @@ int cmd_fetch_pack(int argc, const char **argv, const char 
*prefix)
                        pack_lockfile_ptr = &pack_lockfile;
                        continue;
                }
+               if (!prefixcmp(arg, "--pack-version=")) {
+                       int ver = strtol(arg + 15, NULL, 0);
+                       if (ver != 2 && ver != 4)
+                               die(_("invalid pack version %d"), ver);
+                       args.packv4 = ver == 4;
+                       continue;
+               }
                usage(fetch_pack_usage);
        }
 
diff --git a/remote-curl.c b/remote-curl.c
index 5b3ce9e..1a3d215 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -18,6 +18,7 @@ struct options {
        unsigned progress : 1,
                followtags : 1,
                dry_run : 1,
+               packv4 : 1,
                thin : 1;
 };
 static struct options options;
@@ -67,6 +68,15 @@ static int set_option(const char *name, const char *value)
                        return -1;
                return 0;
        }
+       else if (!strcmp(name, "packv4")) {
+               if (!strcmp(value, "true"))
+                       options.packv4 = 1;
+               else if (!strcmp(value, "false"))
+                       options.packv4 = 0;
+               else
+                       return -1;
+               return 0;
+       }
        else {
                return 1 /* unsupported */;
        }
@@ -654,7 +664,7 @@ static int fetch_git(struct discovery *heads,
        struct strbuf preamble = STRBUF_INIT;
        char *depth_arg = NULL;
        int argc = 0, i, err;
-       const char *argv[15];
+       const char *argv[16];
 
        argv[argc++] = "fetch-pack";
        argv[argc++] = "--stateless-rpc";
@@ -676,6 +686,8 @@ static int fetch_git(struct discovery *heads,
                depth_arg = strbuf_detach(&buf, NULL);
                argv[argc++] = depth_arg;
        }
+       if (options.packv4)
+               argv[argc++] = "--pack-version=4";
        argv[argc++] = url;
        argv[argc++] = NULL;
 
diff --git a/t/t5551-http-fetch.sh b/t/t5551-http-fetch.sh
index 55a866a..5b4e6aa 100755
--- a/t/t5551-http-fetch.sh
+++ b/t/t5551-http-fetch.sh
@@ -222,5 +222,14 @@ test_expect_success EXPENSIVE 'clone the 50,000 tag repo 
to check OS command lin
        )
 '
 
+test_expect_success 'clone http repository with pack v4' '
+       git -c transfer.unpackLimit=1 clone --pack-version=4 
$HTTPD_URL/smart/repo.git pv4 &&
+       P=`ls pv4/.git/objects/pack/pack-*.pack` &&
+       # Offset 4 is pack version
+       test-dump ntohl "$P" 4 >ver.actual &&
+       echo 4 >ver.expected &&
+       test_cmp ver.expected ver.actual
+'
+
 stop_httpd
 test_done
diff --git a/transport-helper.c b/transport-helper.c
index 63cabc3..07fbf6e 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -350,6 +350,9 @@ static int fetch_with_fetch(struct transport *transport,
 
        standard_options(transport);
 
+       set_helper_option(transport, "packv4",
+                         data->transport_options.packv4 ? "true" : "false");
+
        for (i = 0; i < nr_heads; i++) {
                const struct ref *posn = to_fetch[i];
                if (posn->status & REF_STATUS_UPTODATE)
-- 
1.8.2.82.gc24b958

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to