All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 17/27] fetch: define shallow boundary with --shallow-since
Date: Sun, 12 Jun 2016 17:53:59 +0700	[thread overview]
Message-ID: <20160612105409.22156-18-pclouds@gmail.com> (raw)
In-Reply-To: <20160612105409.22156-1-pclouds@gmail.com>

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/fetch-options.txt     |  4 ++++
 Documentation/git-fetch-pack.txt    |  4 ++++
 Documentation/gitremote-helpers.txt |  3 +++
 builtin/fetch-pack.c                |  4 ++++
 builtin/fetch.c                     | 29 +++++++++++++++++++++++------
 fetch-pack.c                        | 12 +++++++++++-
 fetch-pack.h                        |  1 +
 remote-curl.c                       | 11 +++++++++--
 transport.c                         |  4 ++++
 transport.h                         |  4 ++++
 10 files changed, 67 insertions(+), 9 deletions(-)

diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt
index 952dfdf..8738d3d 100644
--- a/Documentation/fetch-options.txt
+++ b/Documentation/fetch-options.txt
@@ -14,6 +14,10 @@
 	linkgit:git-clone[1]), deepen or shorten the history to the specified
 	number of commits. Tags for the deepened commits are not fetched.
 
+--shallow-since=<date>::
+	Deepen or shorten the history of a shallow repository to
+	include all reachable commits after <date>.
+
 --unshallow::
 	If the source repository is complete, convert a shallow
 	repository to a complete one, removing all the limitations
diff --git a/Documentation/git-fetch-pack.txt b/Documentation/git-fetch-pack.txt
index 8680f45..99e6257 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.
 
+--shallow-since=<date>::
+	Deepen or shorten the history of a shallow'repository to
+	include all reachable commits after <date>.
+
 --no-progress::
 	Do not show the progress.
 
diff --git a/Documentation/gitremote-helpers.txt b/Documentation/gitremote-helpers.txt
index 78e0b27..9971d9a 100644
--- a/Documentation/gitremote-helpers.txt
+++ b/Documentation/gitremote-helpers.txt
@@ -415,6 +415,9 @@ set by Git if the remote helper has the 'option' capability.
 'option depth' <depth>::
 	Deepens the history of a shallow repository.
 
+'option deepen-since <timestamp>::
+	Deepens the history of a shallow repository based on time.
+
 'option followtags' {'true'|'false'}::
 	If enabled the helper should automatically fetch annotated
 	tag objects if the object the tag points at was transferred
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 8332d3d..0402e27 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -104,6 +104,10 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
 			args.depth = strtol(arg, NULL, 0);
 			continue;
 		}
+		if (skip_prefix(arg, "--shallow-since=", &arg)) {
+			args.deepen_since = xstrdup(arg);
+			continue;
+		}
 		if (!strcmp("--no-progress", arg)) {
 			args.no_progress = 1;
 			continue;
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 8e74213..283aa95 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -36,9 +36,10 @@ static int prune = -1; /* unspecified */
 
 static int all, append, dry_run, force, keep, multiple, update_head_ok, verbosity;
 static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
-static int tags = TAGS_DEFAULT, unshallow, update_shallow;
+static int tags = TAGS_DEFAULT, unshallow, update_shallow, deepen;
 static int max_children = 1;
 static const char *depth;
+static const char *deepen_since;
 static const char *upload_pack;
 static struct strbuf default_rla = STRBUF_INIT;
 static struct transport *gtransport;
@@ -115,6 +116,8 @@ static struct option builtin_fetch_options[] = {
 	OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
 	OPT_STRING(0, "depth", &depth, N_("depth"),
 		   N_("deepen history of shallow clone")),
+	OPT_STRING(0, "shallow-since", &deepen_since, N_("time"),
+		   N_("deepen history of shallow repository based on time")),
 	{ OPTION_SET_INT, 0, "unshallow", &unshallow, NULL,
 		   N_("convert to a complete repository"),
 		   PARSE_OPT_NONEG | PARSE_OPT_NOARG, NULL, 1 },
@@ -754,7 +757,7 @@ static int quickfetch(struct ref *ref_map)
 	 * really need to perform.  Claiming failure now will ensure
 	 * we perform the network exchange to deepen our history.
 	 */
-	if (depth)
+	if (deepen)
 		return -1;
 	return check_everything_connected(iterate_ref_map, 1, &rm);
 }
@@ -859,7 +862,7 @@ static void set_option(struct transport *transport, const char *name, const char
 			name, transport->url);
 }
 
-static struct transport *prepare_transport(struct remote *remote)
+static struct transport *prepare_transport(struct remote *remote, int deepen)
 {
 	struct transport *transport;
 	transport = transport_get(remote, NULL);
@@ -870,6 +873,8 @@ static struct transport *prepare_transport(struct remote *remote)
 		set_option(transport, TRANS_OPT_KEEP, "yes");
 	if (depth)
 		set_option(transport, TRANS_OPT_DEPTH, depth);
+	if (deepen && deepen_since)
+		set_option(transport, TRANS_OPT_DEEPEN_SINCE, deepen_since);
 	if (update_shallow)
 		set_option(transport, TRANS_OPT_UPDATE_SHALLOW, "yes");
 	return transport;
@@ -877,8 +882,18 @@ static struct transport *prepare_transport(struct remote *remote)
 
 static void backfill_tags(struct transport *transport, struct ref *ref_map)
 {
-	if (transport->cannot_reuse) {
-		gsecondary = prepare_transport(transport->remote);
+	int cannot_reuse;
+
+	/*
+	 * Once we have set TRANS_OPT_DEEPEN_SINCE, we can't unset it
+	 * when remote helper is used (setting it to an empty string
+	 * is not unsetting). We could extend the remote helper
+	 * protocol for that, but for now, just force a new connection
+	 * without deepen-since.
+	 */
+	cannot_reuse = transport->cannot_reuse || deepen_since;
+	if (cannot_reuse) {
+		gsecondary = prepare_transport(transport->remote, 0);
 		transport = gsecondary;
 	}
 
@@ -1095,7 +1110,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
 		die(_("No remote repository specified.  Please, specify either a URL or a\n"
 		    "remote name from which new revisions should be fetched."));
 
-	gtransport = prepare_transport(remote);
+	gtransport = prepare_transport(remote, 1);
 
 	if (prune < 0) {
 		/* no command line request */
@@ -1167,6 +1182,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
 	/* no need to be strict, transport_set_option() will validate it again */
 	if (depth && atoi(depth) < 1)
 		die(_("depth %s is not a positive number"), depth);
+	if (depth || deepen_since)
+		deepen = 1;
 
 	if (recurse_submodules != RECURSE_SUBMODULES_OFF) {
 		if (recurse_submodules_default) {
diff --git a/fetch-pack.c b/fetch-pack.c
index a14d24a..a2f25c1 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -21,6 +21,7 @@ static int fetch_unpack_limit = -1;
 static int unpack_limit = 100;
 static int prefer_ofs_delta = 1;
 static int no_done;
+static int deepen_since_ok;
 static int fetch_fsck_objects = -1;
 static int transfer_fsck_objects = -1;
 static int agent_supported;
@@ -326,6 +327,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 (deepen_since_ok)    strbuf_addstr(&c, " deepen-since");
 			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);
@@ -345,6 +347,10 @@ static int find_common(struct fetch_pack_args *args,
 		write_shallow_commits(&req_buf, 1, NULL);
 	if (args->depth > 0)
 		packet_buf_write(&req_buf, "deepen %d", args->depth);
+	if (args->deepen_since) {
+		unsigned long max_age = approxidate(args->deepen_since);
+		packet_buf_write(&req_buf, "deepen-since %lu", max_age);
+	}
 	packet_buf_flush(&req_buf);
 	state_len = req_buf.len;
 
@@ -812,7 +818,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
 
 	if ((args->depth > 0 || is_repository_shallow()) && !server_supports("shallow"))
 		die(_("Server does not support shallow clients"));
-	if (args->depth > 0)
+	if (args->depth > 0 || args->deepen_since)
 		args->deepen = 1;
 	if (server_supports("multi_ack_detailed")) {
 		print_verbose(args, _("Server supports multi_ack_detailed"));
@@ -860,6 +866,10 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
 			print_verbose(args, _("Server version is %.*s"),
 				      agent_len, agent_feature);
 	}
+	if (server_supports("deepen-since"))
+		deepen_since_ok = 1;
+	else if (args->deepen_since)
+		die(_("Server does not support --shallow-since"));
 
 	if (everything_local(args, &ref, sought, nr_sought)) {
 		packet_flush(fd[1]);
diff --git a/fetch-pack.h b/fetch-pack.h
index 4d0adb0..f7eadb2 100644
--- a/fetch-pack.h
+++ b/fetch-pack.h
@@ -10,6 +10,7 @@ struct fetch_pack_args {
 	const char *uploadpack;
 	int unpacklimit;
 	int depth;
+	const char *deepen_since;
 	unsigned quiet:1;
 	unsigned keep_pack:1;
 	unsigned lock_pack:1;
diff --git a/remote-curl.c b/remote-curl.c
index fd030c1..5876f24 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -20,6 +20,7 @@ static struct strbuf url = STRBUF_INIT;
 struct options {
 	int verbosity;
 	unsigned long depth;
+	char *deepen_since;
 	unsigned progress : 1,
 		check_self_contained_and_connected : 1,
 		cloning : 1,
@@ -60,6 +61,10 @@ static int set_option(const char *name, const char *value)
 		options.depth = v;
 		return 0;
 	}
+	else if (!strcmp(name, "deepen-since")) {
+		options.deepen_since = xstrdup(value);
+		return 0;
+	}
 	else if (!strcmp(name, "followtags")) {
 		if (!strcmp(value, "true"))
 			options.followtags = 1;
@@ -699,8 +704,8 @@ static int fetch_dumb(int nr_heads, struct ref **to_fetch)
 	char **targets = xmalloc(nr_heads * sizeof(char*));
 	int ret, i;
 
-	if (options.depth)
-		die("dumb http transport does not support --depth");
+	if (options.depth || options.deepen_since)
+		die("dumb http transport does not support shallow capabilities");
 	for (i = 0; i < nr_heads; i++)
 		targets[i] = xstrdup(oid_to_hex(&to_fetch[i]->old_oid));
 
@@ -746,6 +751,8 @@ static int fetch_git(struct discovery *heads,
 		argv_array_push(&args, "--no-progress");
 	if (options.depth)
 		argv_array_pushf(&args, "--depth=%lu", options.depth);
+	if (options.deepen_since)
+		argv_array_pushf(&args, "--shallow-since=%s", options.deepen_since);
 	argv_array_push(&args, url.buf);
 
 	for (i = 0; i < nr_heads; i++) {
diff --git a/transport.c b/transport.c
index c92f8ae..f04a302 100644
--- a/transport.c
+++ b/transport.c
@@ -151,6 +151,9 @@ static int set_git_option(struct git_transport_options *opts,
 				die("transport: invalid depth option '%s'", value);
 		}
 		return 0;
+	} else if (!strcmp(name, TRANS_OPT_DEEPEN_SINCE)) {
+		opts->deepen_since = value;
+		return 0;
 	}
 	return 1;
 }
@@ -205,6 +208,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.deepen_since = data->options.deepen_since;
 	args.check_self_contained_and_connected =
 		data->options.check_self_contained_and_connected;
 	args.cloning = transport->cloning;
diff --git a/transport.h b/transport.h
index 8ebaaf2..9c10a44 100644
--- a/transport.h
+++ b/transport.h
@@ -13,6 +13,7 @@ struct git_transport_options {
 	unsigned self_contained_and_connected : 1;
 	unsigned update_shallow : 1;
 	int depth;
+	const char *deepen_since;
 	const char *uploadpack;
 	const char *receivepack;
 	struct push_cas_option *cas;
@@ -171,6 +172,9 @@ int transport_restrict_protocols(void);
 /* Limit the depth of the fetch if not null */
 #define TRANS_OPT_DEPTH "depth"
 
+/* Limit the depth of the fetch based on time if not null */
+#define TRANS_OPT_DEEPEN_SINCE "deepen-since"
+
 /* Aggressively fetch annotated tags if possible */
 #define TRANS_OPT_FOLLOWTAGS "followtags"
 
-- 
2.8.2.524.g6ff3d78

  parent reply	other threads:[~2016-06-12 10:56 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-10 12:26 [PATCH 00/27] nd/shallow-deepen updates Nguyễn Thái Ngọc Duy
2016-06-10 12:26 ` [PATCH 01/27] remote-curl.c: convert fetch_git() to use argv_array Nguyễn Thái Ngọc Duy
2016-06-10 12:26 ` [PATCH 02/27] transport-helper.c: refactor set_helper_option() Nguyễn Thái Ngọc Duy
2016-06-10 12:26 ` [PATCH 03/27] upload-pack: move shallow deepen code out of receive_needs() Nguyễn Thái Ngọc Duy
2016-06-10 12:26 ` [PATCH 04/27] upload-pack: move "shallow" sending code out of deepen() Nguyễn Thái Ngọc Duy
2016-06-10 20:05   ` Junio C Hamano
2016-06-10 12:26 ` [PATCH 05/27] upload-pack: remove unused variable "backup" Nguyễn Thái Ngọc Duy
2016-06-10 20:06   ` Junio C Hamano
2016-06-10 12:26 ` [PATCH 06/27] upload-pack: move "unshallow" sending code out of deepen() Nguyễn Thái Ngọc Duy
2016-06-10 20:09   ` Junio C Hamano
2016-06-10 12:26 ` [PATCH 07/27] upload-pack: use skip_prefix() instead of starts_with() Nguyễn Thái Ngọc Duy
2016-06-10 12:26 ` [PATCH 08/27] upload-pack: tighten number parsing at "deepen" lines Nguyễn Thái Ngọc Duy
2016-06-10 12:26 ` [PATCH 09/27] upload-pack: make check_non_tip() clean things up error Nguyễn Thái Ngọc Duy
2016-06-10 20:25   ` Junio C Hamano
2016-06-10 12:26 ` [PATCH 10/27] upload-pack: move rev-list code out of check_non_tip() Nguyễn Thái Ngọc Duy
2016-06-10 20:36   ` Junio C Hamano
2016-06-10 12:26 ` [PATCH 11/27] fetch-pack: use skip_prefix() instead of starts_with() Nguyễn Thái Ngọc Duy
2016-06-10 12:26 ` [PATCH 12/27] fetch-pack: use a common function for verbose printing Nguyễn Thái Ngọc Duy
2016-06-10 12:27 ` [PATCH 13/27] fetch-pack.c: mark strings for translating Nguyễn Thái Ngọc Duy
2016-06-10 12:27 ` [PATCH 14/27] fetch-pack: use a separate flag for fetch in deepening mode Nguyễn Thái Ngọc Duy
2016-06-10 12:27 ` [PATCH 15/27] shallow.c: implement a generic shallow boundary finder based on rev-list Nguyễn Thái Ngọc Duy
2016-06-10 12:27 ` [PATCH 16/27] upload-pack: add deepen-since to cut shallow repos based on time Nguyễn Thái Ngọc Duy
2016-06-10 12:27 ` [PATCH 17/27] fetch: define shallow boundary with --shallow-since Nguyễn Thái Ngọc Duy
2016-06-10 12:27 ` [PATCH 18/27] clone: define shallow clone boundary based on time " Nguyễn Thái Ngọc Duy
2016-06-10 12:27 ` [PATCH 19/27] t5500, t5539: tests for shallow depth since a specific date Nguyễn Thái Ngọc Duy
2016-06-10 12:27 ` [PATCH 20/27] refs: add expand_ref() Nguyễn Thái Ngọc Duy
2016-06-10 12:27 ` [PATCH 21/27] upload-pack: support define shallow boundary by excluding revisions Nguyễn Thái Ngọc Duy
2016-06-10 12:27 ` [PATCH 22/27] fetch: define shallow boundary with --shallow-exclude Nguyễn Thái Ngọc Duy
2016-06-10 12:27 ` [PATCH 23/27] clone: define shallow clone " Nguyễn Thái Ngọc Duy
2016-06-10 12:27 ` [PATCH 24/27] t5500, t5539: tests for shallow depth excluding a ref Nguyễn Thái Ngọc Duy
2016-06-10 12:27 ` [PATCH 25/27] upload-pack: split check_unreachable() in two, prep for get_reachable_list() Nguyễn Thái Ngọc Duy
2016-06-10 12:27 ` [PATCH 26/27] upload-pack: add get_reachable_list() Nguyễn Thái Ngọc Duy
2016-06-10 12:27 ` [PATCH 27/27] fetch, upload-pack: --deepen=N extends shallow boundary by N commits Nguyễn Thái Ngọc Duy
2016-06-10 23:42 ` [PATCH 00/27] nd/shallow-deepen updates Eric Sunshine
2016-06-13 17:10   ` Junio C Hamano
2016-06-14  9:21     ` Duy Nguyen
2016-06-12 10:53 ` [PATCH v2 " Nguyễn Thái Ngọc Duy
2016-06-12 10:53   ` [PATCH v2 01/27] remote-curl.c: convert fetch_git() to use argv_array Nguyễn Thái Ngọc Duy
2016-06-12 10:53   ` [PATCH v2 02/27] transport-helper.c: refactor set_helper_option() Nguyễn Thái Ngọc Duy
2016-06-12 10:53   ` [PATCH v2 03/27] upload-pack: move shallow deepen code out of receive_needs() Nguyễn Thái Ngọc Duy
2016-06-12 10:53   ` [PATCH v2 04/27] upload-pack: move "shallow" sending code out of deepen() Nguyễn Thái Ngọc Duy
2016-06-12 10:53   ` [PATCH v2 05/27] upload-pack: remove unused variable "backup" Nguyễn Thái Ngọc Duy
2016-06-12 10:53   ` [PATCH v2 06/27] upload-pack: move "unshallow" sending code out of deepen() Nguyễn Thái Ngọc Duy
2016-06-12 10:53   ` [PATCH v2 07/27] upload-pack: use skip_prefix() instead of starts_with() Nguyễn Thái Ngọc Duy
2016-06-12 10:53   ` [PATCH v2 08/27] upload-pack: tighten number parsing at "deepen" lines Nguyễn Thái Ngọc Duy
2016-06-12 10:53   ` [PATCH v2 09/27] upload-pack: make check_non_tip() clean things up on error Nguyễn Thái Ngọc Duy
2016-06-12 10:53   ` [PATCH v2 10/27] upload-pack: move rev-list code out of check_non_tip() Nguyễn Thái Ngọc Duy
2016-06-12 10:53   ` [PATCH v2 11/27] fetch-pack: use skip_prefix() instead of starts_with() Nguyễn Thái Ngọc Duy
2016-06-12 10:53   ` [PATCH v2 12/27] fetch-pack: use a common function for verbose printing Nguyễn Thái Ngọc Duy
2016-06-12 10:53   ` [PATCH v2 13/27] fetch-pack.c: mark strings for translating Nguyễn Thái Ngọc Duy
2016-06-12 10:53   ` [PATCH v2 14/27] fetch-pack: use a separate flag for fetch in deepening mode Nguyễn Thái Ngọc Duy
2016-06-12 10:53   ` [PATCH v2 15/27] shallow.c: implement a generic shallow boundary finder based on rev-list Nguyễn Thái Ngọc Duy
2016-06-12 10:53   ` [PATCH v2 16/27] upload-pack: add deepen-since to cut shallow repos based on time Nguyễn Thái Ngọc Duy
2016-06-12 10:53   ` Nguyễn Thái Ngọc Duy [this message]
2016-06-12 10:54   ` [PATCH v2 18/27] clone: define shallow clone boundary based on time with --shallow-since Nguyễn Thái Ngọc Duy
2016-06-12 10:54   ` [PATCH v2 19/27] t5500, t5539: tests for shallow depth since a specific date Nguyễn Thái Ngọc Duy
2016-06-12 10:54   ` [PATCH v2 20/27] refs: add expand_ref() Nguyễn Thái Ngọc Duy
2016-06-12 10:54   ` [PATCH v2 21/27] upload-pack: support define shallow boundary by excluding revisions Nguyễn Thái Ngọc Duy
2016-06-12 10:54   ` [PATCH v2 22/27] fetch: define shallow boundary with --shallow-exclude Nguyễn Thái Ngọc Duy
2016-06-12 10:54   ` [PATCH v2 23/27] clone: define shallow clone " Nguyễn Thái Ngọc Duy
2016-06-12 10:54   ` [PATCH v2 24/27] t5500, t5539: tests for shallow depth excluding a ref Nguyễn Thái Ngọc Duy
2016-06-12 10:54   ` [PATCH v2 25/27] upload-pack: split check_unreachable() in two, prep for get_reachable_list() Nguyễn Thái Ngọc Duy
2016-06-12 10:54   ` [PATCH v2 26/27] upload-pack: add get_reachable_list() Nguyễn Thái Ngọc Duy
2016-06-12 10:54   ` [PATCH v2 27/27] fetch, upload-pack: --deepen=N extends shallow boundary by N commits Nguyễn Thái Ngọc Duy

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=20160612105409.22156-18-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sunshine@sunshineco.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.