git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 05/10] clone: new option to set preferred pack version for transfer

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Sep 26, 2013, 02:26 UTC
Message-ID
<1380162409-18224-6-git-send-email-pclouds@gmail.com>
In-Reply-To
<1380162409-18224-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/git-clone.txt |  4 ++++
 builtin/clone.c             | 19 +++++++++++++++++++
 t/t5601-clone.sh            | 12 ++++++++++++
 3 files changed, 35 insertions(+)
diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 450f158..6299a70 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -217,6 +217,10 @@ objects from the source repository into a pack in the cloned repository.
 	The result is Git repository can be separated from working
 	tree.
 
+--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].
 
 <repository>::
 	The (possibly remote) repository to clone from.  See the
diff --git a/builtin/clone.c b/builtin/clone.c
index 430307b..9c0e296 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -46,6 +46,7 @@ static const char *real_git_dir;
 static char *option_upload_pack = "git-upload-pack";
 static int option_verbosity;
 static int option_progress = -1;
+static int pack_version;
 static struct string_list option_config;
 static struct string_list option_reference;
 
@@ -98,6 +99,8 @@ static struct option builtin_clone_options[] = {
 		   N_("separate git dir from working tree")),
 	OPT_STRING_LIST('c', "config", &option_config, N_("key=value"),
 			N_("set config inside the new repository")),
+	OPT_INTEGER(0, "pack-version", &pack_version,
+		    N_("preferred pack version for transfer")),
 	OPT_END()
 };
 
@@ -764,6 +767,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		usage_msg_opt(_("You must specify a repository to clone."),
 			builtin_clone_usage, builtin_clone_options);
 
+	if (!pack_version)
+		pack_version = core_default_pack_version;
+	if (pack_version != 2 && pack_version != 4)
+		die(_("invalid pack version %d"), pack_version);
+
 	if (option_single_branch == -1)
 		option_single_branch = option_depth ? 1 : 0;
 
@@ -794,6 +802,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	is_local = option_local != 0 && path && !is_bundle;
 	if (is_local && option_depth)
 		warning(_("--depth is ignored in local clones; use file:// instead."));
+	if (is_local && pack_version == 4)
+		warning(_("--pack-version is ignored in local clones; use file:// instead."));
 	if (option_local > 0 && !is_local)
 		warning(_("--local is ignored"));
 
@@ -868,6 +878,12 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	} else {
 		strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin);
 	}
+	if (pack_version != core_default_pack_version) {
+		struct strbuf sb = STRBUF_INIT;
+		strbuf_addf(&sb, "%d", pack_version);
+		git_config_set("core.preferredPackVersion", sb.buf);
+		strbuf_release(&sb);
+	}
 
 	strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top.buf);
 	strbuf_addf(&key, "remote.%s.url", option_origin);
@@ -903,6 +919,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 			transport_set_option(transport, TRANS_OPT_UPLOADPACK,
 					     option_upload_pack);
 
+		if (pack_version == 4)
+			transport_set_option(transport, TRANS_OPT_PACKV4, "yes");
+
 		if (transport->smart_options && !option_depth)
 			transport->smart_options->check_self_contained_and_connected = 1;
 	}
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index 0629149..8118524 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -285,4 +285,16 @@ test_expect_success NOT_MINGW,NOT_CYGWIN 'clone local path foo:bar' '
 	git clone "./foo:bar" foobar
 '
 
+test_expect_success 'clone --pack-version=4' '
+	git clone --pack-version=4 --no-local src 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 &&
+	git --git-dir=pv4/.git config --int core.preferredPackVersion >cfgver.actual &&
+	echo 4 >cfgver.expected &&
+	test_cmp cfgver.expected cfgver.actual
+'
+
 test_done
-- 
1.8.2.82.gc24b958
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 6 of 20 in “pack v4 UI support”
  1. 00/10 pack v4 UI supportNguyễn Thái Ngọc Duy, Sep 26, 2013
  2. 01/10 test-dump: new test program to examine binary dataNguyễn Thái Ngọc Duy, Sep 26, 2013
  3. 02/10 config: add core.preferredPackVersionNguyễn Thái Ngọc Duy, Sep 26, 2013
  4. 03/10 upload-pack: new capability to send pack v4Nguyễn Thái Ngọc Duy, Sep 26, 2013
  5. 04/10 fetch: new option to set preferred pack version for transferNguyễn Thái Ngọc Duy, Sep 26, 2013
  6. 05/10 clone: new option to set preferred pack version for transferNguyễn Thái Ngọc Duy, Sep 26, 2013
  7. 06/10 fetch: pack v4 support on smart httpNguyễn Thái Ngọc Duy, Sep 26, 2013
  8. 07/10 receive-pack: request for packv4 if it's the preferred versionNguyễn Thái Ngọc Duy, Sep 26, 2013
  9. Junio C HamanoOct 17, 2013
  10. 08/10 send-pack: support pack v4Nguyễn Thái Ngọc Duy, Sep 26, 2013
  11. 09/10 repack: add --pack-version and fall back to core.preferredPackVersionNguyễn Thái Ngọc Duy, Sep 26, 2013
  12. repack: Add --version parameterStefan Beller, Sep 26, 2013
  13. Felipe ContrerasSep 26, 2013
  14. Stefan BellerSep 28, 2013
  15. Duy NguyenSep 26, 2013
  16. Stefan BellerSep 28, 2013
  17. 10/10 count-objects: report pack v4 usageNguyễn Thái Ngọc Duy, Sep 26, 2013
  18. Nicolas PitreSep 26, 2013
  19. Duy NguyenSep 26, 2013
  20. Nicolas PitreSep 27, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.