git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Hostetler <git@jeffhostetler.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, peff@peff.net, jonathantanmy@google.com,
	Jeff Hostetler <jeffhost@microsoft.com>
Subject: [PATCH v7 15/16] fetch: inherit filter-spec from partial clone
Date: Fri,  8 Dec 2017 15:58:50 +0000	[thread overview]
Message-ID: <20171208155851.855-16-git@jeffhostetler.com> (raw)
In-Reply-To: <20171208155851.855-1-git@jeffhostetler.com>

From: Jeff Hostetler <jeffhost@microsoft.com>

Teach (partial) fetch to inherit the filter-spec used by
the partial clone.  Extend --no-filter to override this
inheritance.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
---
 builtin/fetch-pack.c          |  2 +-
 builtin/fetch.c               | 56 ++++++++++++++++++++++++++++++++++++++++---
 builtin/rev-list.c            |  2 +-
 list-objects-filter-options.c |  2 +-
 list-objects-filter-options.h | 12 ++++++++++
 t/t5616-partial-clone.sh      | 22 ++++++++++++++++-
 6 files changed, 89 insertions(+), 7 deletions(-)

diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index cbf5035..a7bc136 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -158,7 +158,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
 			continue;
 		}
 		if (!strcmp(arg, ("--no-" CL_ARG__FILTER))) {
-			list_objects_filter_release(&args.filter_options);
+			list_objects_filter_set_no_filter(&args.filter_options);
 			continue;
 		}
 		usage(fetch_pack_usage);
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 14aab71..79c866c 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1275,6 +1275,56 @@ static int fetch_multiple(struct string_list *list)
 	return result;
 }
 
+/*
+ * Fetching from the promisor remote should use the given filter-spec
+ * or inherit the default filter-spec from the config.
+ */
+static inline void fetch_one_setup_partial(struct remote *remote)
+{
+	/*
+	 * Explicit --no-filter argument overrides everything, regardless
+	 * of any prior partial clones and fetches.
+	 */
+	if (filter_options.no_filter)
+		return;
+
+	/*
+	 * If no prior partial clone/fetch and the current fetch DID NOT
+	 * request a partial-fetch, do a normal fetch.
+	 */
+	if (!repository_format_partial_clone && !filter_options.choice)
+		return;
+
+	/*
+	 * If this is the FIRST partial-fetch request, we enable partial
+	 * on this repo and remember the given filter-spec as the default
+	 * for subsequent fetches to this remote.
+	 */
+	if (!repository_format_partial_clone && filter_options.choice) {
+		partial_clone_register(remote->name, &filter_options);
+		return;
+	}
+
+	/*
+	 * We are currently limited to only ONE promisor remote and only
+	 * allow partial-fetches from the promisor remote.
+	 */
+	if (strcmp(remote->name, repository_format_partial_clone)) {
+		if (filter_options.choice)
+			die(_("--filter can only be used with the remote configured in core.partialClone"));
+		return;
+	}
+
+	/*
+	 * Do a partial-fetch from the promisor remote using either the
+	 * explicitly given filter-spec or inherit the filter-spec from
+	 * the config.
+	 */
+	if (!filter_options.choice)
+		partial_clone_get_default_filter_spec(&filter_options);
+	return;
+}
+
 static int fetch_one(struct remote *remote, int argc, const char **argv)
 {
 	static const char **refs = NULL;
@@ -1404,13 +1454,13 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
 	}
 
 	if (remote) {
-		if (filter_options.choice &&
-		    strcmp(remote->name, repository_format_partial_clone))
-			die(_("--filter can only be used with the remote configured in core.partialClone"));
+		if (filter_options.choice || repository_format_partial_clone)
+			fetch_one_setup_partial(remote);
 		result = fetch_one(remote, argc, argv);
 	} else {
 		if (filter_options.choice)
 			die(_("--filter can only be used with the remote configured in core.partialClone"));
+		/* TODO should this also die if we have a previous partial-clone? */
 		result = fetch_multiple(&list);
 	}
 
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 48f922d..8503dea 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -460,7 +460,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 			continue;
 		}
 		if (!strcmp(arg, ("--no-" CL_ARG__FILTER))) {
-			list_objects_filter_release(&filter_options);
+			list_objects_filter_set_no_filter(&filter_options);
 			continue;
 		}
 		if (!strcmp(arg, "--filter-print-omitted")) {
diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c
index 5c47e2b..6a3cc98 100644
--- a/list-objects-filter-options.c
+++ b/list-objects-filter-options.c
@@ -94,7 +94,7 @@ int opt_parse_list_objects_filter(const struct option *opt,
 	struct list_objects_filter_options *filter_options = opt->value;
 
 	if (unset || !arg) {
-		list_objects_filter_release(filter_options);
+		list_objects_filter_set_no_filter(filter_options);
 		return 0;
 	}
 
diff --git a/list-objects-filter-options.h b/list-objects-filter-options.h
index 1143539..0000a61 100644
--- a/list-objects-filter-options.h
+++ b/list-objects-filter-options.h
@@ -31,6 +31,11 @@ struct list_objects_filter_options {
 	enum list_objects_filter_choice choice;
 
 	/*
+	 * Choice is LOFC_DISABLED because "--no-filter" was requested.
+	 */
+	unsigned int no_filter : 1;
+
+	/*
 	 * Parsed values (fields) from within the filter-spec.  These are
 	 * choice-specific; not all values will be defined for any given
 	 * choice.
@@ -58,6 +63,13 @@ int opt_parse_list_objects_filter(const struct option *opt,
 void list_objects_filter_release(
 	struct list_objects_filter_options *filter_options);
 
+static inline void list_objects_filter_set_no_filter(
+	struct list_objects_filter_options *filter_options)
+{
+	list_objects_filter_release(filter_options);
+	filter_options->no_filter = 1;
+}
+
 void partial_clone_register(
 	const char *remote,
 	const struct list_objects_filter_options *filter_options);
diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh
index 3b8cc0b..433e07e 100755
--- a/t/t5616-partial-clone.sh
+++ b/t/t5616-partial-clone.sh
@@ -59,7 +59,7 @@ test_expect_success 'push new commits to server' '
 	git -C src remote add srv "file://$(pwd)/srv.bare" &&
 	for x in a b c d e
 	do
-		echo "Mod $x" >>src/file.1.txt
+		echo "Mod file.1.txt $x" >>src/file.1.txt
 		git -C src add file.1.txt
 		git -C src commit -m "mod $x"
 	done &&
@@ -93,4 +93,24 @@ test_expect_success 'verify blame causes dynamic object fetch' '
 	test_line_count = 0 observed
 '
 
+# create new commits in "src" repo to establish a history on file.2.txt
+# and push to "srv.bare".
+test_expect_success 'push new commits to server for file.2.txt' '
+	for x in a b c d e f
+	do
+		echo "Mod file.2.txt $x" >>src/file.2.txt
+		git -C src add file.2.txt
+		git -C src commit -m "mod $x"
+	done &&
+	git -C src push -u srv master
+'
+
+# Do FULL fetch by disabling filter-spec using --no-filter.
+# Verify we have all the new blobs.
+test_expect_success 'override inherited filter-spec using --no-filter' '
+	git -C pc1 fetch --no-filter origin &&
+	git -C pc1 rev-list master..origin/master --quiet --objects --missing=print >observed &&
+	test_line_count = 0 observed
+'
+
 test_done
-- 
2.9.3


  parent reply	other threads:[~2017-12-08 15:59 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-08 15:58 [PATCH v7 00/16] Parial clone part 3: clone, fetch, fetch-pack, upload-pack, and tests Jeff Hostetler
2017-12-08 15:58 ` [PATCH v7 01/16] sha1_file: support lazily fetching missing objects Jeff Hostetler
2017-12-08 15:58 ` [PATCH v7 02/16] rev-list: support termination at promisor objects Jeff Hostetler
2017-12-08 15:58 ` [PATCH v7 03/16] gc: do not repack promisor packfiles Jeff Hostetler
2017-12-08 15:58 ` [PATCH v7 04/16] upload-pack: add object filtering for partial clone Jeff Hostetler
2017-12-08 15:58 ` [PATCH v7 05/16] fetch-pack, index-pack, transport: " Jeff Hostetler
2017-12-08 15:58 ` [PATCH v7 06/16] fetch-pack: add --no-filter Jeff Hostetler
2017-12-08 15:58 ` [PATCH v7 07/16] fetch-pack: test support excluding large blobs Jeff Hostetler
2017-12-08 15:58 ` [PATCH v7 08/16] fetch: refactor calculation of remote list Jeff Hostetler
2017-12-08 15:58 ` [PATCH v7 09/16] fetch: support filters Jeff Hostetler
2018-08-19 11:24   ` Duy Nguyen
2018-08-20 19:42     ` Jeff Hostetler
2017-12-08 15:58 ` [PATCH v7 10/16] partial-clone: define partial clone settings in config Jeff Hostetler
2017-12-08 15:58 ` [PATCH v7 11/16] clone: partial clone Jeff Hostetler
2017-12-08 15:58 ` [PATCH v7 12/16] unpack-trees: batch fetching of missing blobs Jeff Hostetler
2017-12-08 15:58 ` [PATCH v7 13/16] fetch-pack: restore save_commit_buffer after use Jeff Hostetler
2017-12-08 15:58 ` [PATCH v7 14/16] t5616: end-to-end tests for partial clone Jeff Hostetler
2017-12-08 15:58 ` Jeff Hostetler [this message]
2017-12-08 15:58 ` [PATCH v7 16/16] t5616: test bulk prefetch after partial fetch Jeff Hostetler
2017-12-08 17:58 ` [PATCH v7 00/16] Parial clone part 3: clone, fetch, fetch-pack, upload-pack, and tests Junio C Hamano
2017-12-08 18:10   ` Jeff Hostetler
2017-12-08 18:23     ` Junio C Hamano
2017-12-08 22:30 ` Brandon Williams
2017-12-11 19:19   ` Jonathan Tan

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

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

  git send-email \
    --in-reply-to=20171208155851.855-16-git@jeffhostetler.com \
    --to=git@jeffhostetler.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jeffhost@microsoft.com \
    --cc=jonathantanmy@google.com \
    --cc=peff@peff.net \
    /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.
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 NNTP newsgroup(s).