Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]>
---
Documentation/fetch-options.txt | 5 +++++
builtin/fetch.c | 10 ++++++++++
fetch-pack.c | 3 +++
fetch-pack.h | 1 +
t/t5510-fetch.sh | 13 +++++++++++++
transport.c | 4 ++++
transport.h | 5 +++++
7 files changed, 41 insertions(+)
diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt
index ba1fe49..47d55e5 100644
--- a/Documentation/fetch-options.txt
+++ b/Documentation/fetch-options.txt
@@ -17,6 +17,11 @@
Convert a shallow repository to a complete one, removing all
the limitations imposed by shallow repositories.
+--pack-version=<n>::
+ Define the preferred pack format version for data transfer.
+ Valid values are 2 and 4. Default value is specified by
+ core.preferredPackVersion setting. See linkgit:git-config[1].
+
ifndef::git-pull[]
--dry-run::
Show what would be done, without making any changes.
diff --git a/builtin/fetch.c b/builtin/fetch.c
index d784b2e..695fbf1 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -31,6 +31,7 @@ enum {
};
static int all, append, dry_run, force, keep, multiple, prune, update_head_ok,
verbosity;
+static int pack_version;
static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
static int tags = TAGS_DEFAULT, unshallow;
static const char *depth;
@@ -90,6 +91,8 @@ static struct option builtin_fetch_options[] = {
{ OPTION_STRING, 0, "recurse-submodules-default",
&recurse_submodules_default, NULL,
N_("default mode for recursion"), PARSE_OPT_HIDDEN },
+ OPT_INTEGER(0, "pack-version", &pack_version,
+ N_("preferred pack version for transfer")),
OPT_END()
};
@@ -957,6 +960,8 @@ static int fetch_one(struct remote *remote, int argc, const
char **argv)
set_option(TRANS_OPT_KEEP, "yes");
if (depth)
set_option(TRANS_OPT_DEPTH, depth);
+ if (pack_version == 4)
+ set_option(TRANS_OPT_PACKV4, "yes");
if (argc > 0) {
int j = 0;
@@ -1010,6 +1015,11 @@ int cmd_fetch(int argc, const char **argv, const char
*prefix)
argc = parse_options(argc, argv, prefix,
builtin_fetch_options, builtin_fetch_usage, 0);
+ if (!pack_version)
+ pack_version = core_default_pack_version;
+ if (pack_version != 2 && pack_version != 4)
+ die(_("invalid pack version %d"), pack_version);
+
if (unshallow) {
if (depth)
die(_("--depth and --unshallow cannot be used
together"));
diff --git a/fetch-pack.c b/fetch-pack.c
index 6684348..16aa3d0 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -324,6 +324,7 @@ static int find_common(struct fetch_pack_args *args,
if (args->no_progress) strbuf_addstr(&c, "
no-progress");
if (args->include_tag) strbuf_addstr(&c, "
include-tag");
if (prefer_ofs_delta) strbuf_addstr(&c, " ofs-delta");
+ if (args->packv4) strbuf_addstr(&c, " packv4");
if (agent_supported) strbuf_addf(&c, " agent=%s",
git_user_agent_sanitized());
packet_buf_write(&req_buf, "want %s%s\n", remote_hex,
c.buf);
@@ -869,6 +870,8 @@ static struct ref *do_fetch_pack(struct fetch_pack_args
*args,
args->no_progress = 0;
if (!server_supports("include-tag"))
args->include_tag = 0;
+ if (!server_supports("packv4"))
+ args->packv4 = 0;
if (server_supports("ofs-delta")) {
if (args->verbose)
fprintf(stderr, "Server supports ofs-delta\n");
diff --git a/fetch-pack.h b/fetch-pack.h
index 40f08ba..5f03739 100644
--- a/fetch-pack.h
+++ b/fetch-pack.h
@@ -17,6 +17,7 @@ struct fetch_pack_args {
no_progress:1,
include_tag:1,
stateless_rpc:1,
+ packv4:1,
check_self_contained_and_connected:1,
self_contained_and_connected:1;
};
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index fde6891..d3da088 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -512,4 +512,17 @@ test_expect_success 'all boundary commits are excluded' '
test_bundle_object_count .git/objects/pack/pack-${pack##pack }.pack 3
'
+test_expect_success 'fetch --pack-version=4' '
+ git init pv4 &&
+ (
+ cd pv4 &&
+ git fetch --pack-version=4 --keep file://"$D"/.git &&
+ P=`ls .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
+ )
+'
+
test_done
diff --git a/transport.c b/transport.c
index e15db98..ad5a4f1 100644
--- a/transport.c
+++ b/transport.c
@@ -473,6 +473,9 @@ static int set_git_option(struct git_transport_options
*opts,
} else if (!strcmp(name, TRANS_OPT_KEEP)) {
opts->keep = !!value;
return 0;
+ } else if (!strcmp(name, TRANS_OPT_PACKV4)) {
+ opts->packv4 = !!value;
+ return 0;
} else if (!strcmp(name, TRANS_OPT_DEPTH)) {
if (!value)
opts->depth = 0;
@@ -534,6 +537,7 @@ static int fetch_refs_via_pack(struct transport *transport,
args.quiet = (transport->verbose < 0);
args.no_progress = !transport->progress;
args.depth = data->options.depth;
+ args.packv4 = data->options.packv4;
args.check_self_contained_and_connected =
data->options.check_self_contained_and_connected;
diff --git a/transport.h b/transport.h
index ea70ea7..59785c0 100644
--- a/transport.h
+++ b/transport.h
@@ -8,6 +8,7 @@ struct git_transport_options {
unsigned thin : 1;
unsigned keep : 1;
unsigned followtags : 1;
+ unsigned packv4 : 1;
unsigned check_self_contained_and_connected : 1;
unsigned self_contained_and_connected : 1;
int depth;
@@ -135,6 +136,10 @@ struct transport *transport_get(struct remote *, const
char *);
/* Aggressively fetch annotated tags if possible */
#define TRANS_OPT_FOLLOWTAGS "followtags"
+/* Prefer pack version 4 as the transport format */
+#define TRANS_OPT_PACKV4 "packv4"
+
+
/**
* Returns 0 if the option was used, non-zero otherwise. Prints a
* message to stderr if the option is not used.
--
1.8.2.82.gc24b958
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html