git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: Michael Haggerty <mhagger@alum.mit.edu>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 3/3] clone: add `--seed` shorthand
Date: Thu, 21 May 2015 00:16:20 -0400	[thread overview]
Message-ID: <20150521041619.GC5196@peff.net> (raw)
In-Reply-To: <20150521041435.GA18978@peff.net>

The safe way to use `--reference` is to add in the recent
`--dissociate` option, which optimizes the initial clone,
but does not create any obligation to avoid pruning or
deleting the reference repository. However, it can be rather
tricky to explain why two options are necessary, and why
using `--reference` alone is unsafe.

This patch introduces a single option, `--seed`, which does
the right thing; we can steer users towards it rather than
explaining the complexities. It also provides a natural
interface if we later want to allow seeding from non-local
repositories.

Note that git-repack cannot selectively dissociate from
particular alternates. Therefore using `--reference` and
`--seed` together will dissociate from _all_ referenced
repositories. We issue a warning to the user in this case.

Signed-off-by: Jeff King <peff@peff.net>
---
 Documentation/git-clone.txt |  3 +++
 builtin/clone.c             | 12 +++++++++++-
 t/t5700-clone-reference.sh  |  6 ++++--
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index f1f2a3f..ffeb03b 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -107,6 +107,9 @@ objects from the source repository into a pack in the cloned repository.
 	transfer and stop borrowing from them after a clone is made
 	by making necessary local copies of borrowed objects.
 
+--seed <repository>::
+	A convenient shorthand for `--dissociate --reference=<repository>`.
+
 --quiet::
 -q::
 	Operate quietly.  Progress is not reported to the standard
diff --git a/builtin/clone.c b/builtin/clone.c
index a0ec1a9..dd53bbd 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -49,6 +49,7 @@ static int option_verbosity;
 static int option_progress = -1;
 static struct string_list option_config;
 static struct string_list option_reference;
+static struct string_list option_seed;
 static int option_dissociate;
 
 static struct option builtin_clone_options[] = {
@@ -78,6 +79,8 @@ static struct option builtin_clone_options[] = {
 			N_("reference repository")),
 	OPT_BOOL(0, "dissociate", &option_dissociate,
 		 N_("use --reference only while cloning")),
+	OPT_STRING_LIST(0, "seed", &option_seed, N_("repo"),
+			N_("reference and dissociate from repo")),
 	OPT_STRING('o', "origin", &option_origin, N_("name"),
 		   N_("use <name> instead of 'origin' to track upstream")),
 	OPT_STRING('b', "branch", &option_branch, N_("branch"),
@@ -263,6 +266,7 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)
 static void setup_reference(void)
 {
 	for_each_string_list(&option_reference, add_one_reference, NULL);
+	for_each_string_list(&option_seed, add_one_reference, NULL);
 }
 
 static void copy_alternates(struct strbuf *src, struct strbuf *dst,
@@ -884,7 +888,13 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	git_config_set(key.buf, repo);
 	strbuf_reset(&key);
 
-	if (option_reference.nr)
+	if (option_seed.nr) {
+		if (option_reference.nr)
+			warning(_("--seed and --reference used together implies --dissociate"));
+		option_dissociate = 1;
+	}
+
+	if (option_reference.nr || option_seed.nr)
 		setup_reference();
 	else if (option_dissociate) {
 		warning(_("--dissociate given, but there is no --reference"));
diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh
index 3e783fc..80a794c 100755
--- a/t/t5700-clone-reference.sh
+++ b/t/t5700-clone-reference.sh
@@ -209,10 +209,12 @@ test_expect_success 'clone and dissociate from reference' '
 	) &&
 	git clone --no-local --reference=P Q R &&
 	git clone --no-local --reference=P --dissociate Q S &&
-	# removing the reference P would corrupt R but not S
+	git clone --no-local --seed=P Q T &&
+	# removing the reference P would corrupt R but not S or T
 	rm -fr P &&
 	test_must_fail git -C R fsck &&
-	git -C S fsck
+	git -C S fsck &&
+	git -C T fsck
 '
 
 test_done
-- 
2.4.1.528.g00591e3

  parent reply	other threads:[~2015-05-21  4:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-21  4:14 [PATCH/RFC 0/3] --seed as an alias for --dissociate --reference Jeff King
2015-05-21  4:15 ` [PATCH 1/3] clone: use OPT_STRING_LIST for --reference Jeff King
2015-05-21  4:16 ` [PATCH 2/3] clone: reorder --dissociate and --reference options Jeff King
2015-05-21  4:16 ` Jeff King [this message]
2015-05-21 16:05   ` [PATCH 3/3] clone: add `--seed` shorthand Johannes Schindelin
2015-05-21 19:45     ` Philip Oakley
2015-05-22  6:37       ` Johannes Schindelin
2015-05-22  6:49         ` Jeff King
2015-05-24 19:07           ` Junio C Hamano
2015-05-27  8:19             ` Jeff King
2015-05-27 19:35               ` Junio C Hamano
2015-05-22  6:50     ` Jeff King
2015-05-21  5:01 ` [PATCH/RFC 0/3] --seed as an alias for --dissociate --reference Junio C Hamano
2015-05-21  5:06   ` Jeff King
2015-05-21 16:41     ` Junio C Hamano
2015-05-24 23:53 ` Michael Haggerty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150521041619.GC5196@peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=mhagger@alum.mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).