git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Matthijs Kooijman <matthijs@stdin.nl>
To: Junio C Hamano <gitster@pobox.com>
Cc: Duy Nguyen <pclouds@gmail.com>,
	Jonathan Nieder <jrnieder@gmail.com>,
	Stefan Beller <stefanbeller@googlemail.com>,
	schlotter@users.sourceforge.net, Ralf.Wildenhues@gmx.de,
	git@vger.kernel.org, Matthijs Kooijman <matthijs@stdin.nl>
Subject: [PATCH 3/3] fetch-pack: Request fixed-off-by-one-depth when available
Date: Thu, 11 Jul 2013 13:25:54 +0200	[thread overview]
Message-ID: <1373541954-16493-3-git-send-email-matthijs@stdin.nl> (raw)
In-Reply-To: <1373541954-16493-1-git-send-email-matthijs@stdin.nl>

This server feature changes the meaning of the fetch depth, allowing
fetching only a single revision instead of at least two as before. To
make sure the behaviour only depends on the client version, the depth
value sent over the wire is corrected depending on wether the server has
the fix.

There is one corner case: A server without the fix cannot send less than
2 commmits, so when --depth=1 is specified a warning is shown and 2
commits are fetched instead of 1.

Signed-off-by: Matthijs Kooijman <matthijs@stdin.nl>
---
 fetch-pack.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/fetch-pack.c b/fetch-pack.c
index abe5ffb..799b2c1 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -39,6 +39,7 @@ static int marked;
 
 static struct commit_list *rev_list;
 static int non_common_revs, multi_ack, use_sideband, allow_tip_sha1_in_want;
+static int fixed_depth;
 
 static void rev_list_push(struct commit *commit, int mark)
 {
@@ -327,6 +328,7 @@ static int find_common(struct fetch_pack_args *args,
 			if (prefer_ofs_delta)   strbuf_addstr(&c, " ofs-delta");
 			if (agent_supported)    strbuf_addf(&c, " agent=%s",
 							    git_user_agent_sanitized());
+			if (fixed_depth)        strbuf_addstr(&c, " fixed-off-by-one-depth");
 			packet_buf_write(&req_buf, "want %s%s\n", remote_hex, c.buf);
 			strbuf_release(&c);
 		} else
@@ -342,8 +344,23 @@ static int find_common(struct fetch_pack_args *args,
 
 	if (is_repository_shallow())
 		write_shallow_commits(&req_buf, 1);
-	if (args->depth > 0)
-		packet_buf_write(&req_buf, "deepen %d", args->depth);
+	if (args->depth > 0) {
+		if (!fixed_depth && args->depth == 1)
+			warning("Server does not support depth=1, using depth=2 instead");
+		if (!fixed_depth && args->depth > 1) {
+			/* Old server that interprets "deepen 1" as
+			   "give me tip + 1 extra commit" */
+			packet_buf_write(&req_buf, "deepen %d", args->depth - 1);
+		} else if (!fixed_depth && args->depth == 1) {
+			/* Old servers cannot handle depth=1 (deepen=0
+			   means don't change depth / full depth). */
+			packet_buf_write(&req_buf, "deepen 1");
+		} else {
+			/* New server, send depth as-is */
+			packet_buf_write(&req_buf, "deepen %d", args->depth);
+		}
+	}
+
 	packet_buf_flush(&req_buf);
 	state_len = req_buf.len;
 
@@ -874,6 +891,11 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
 			fprintf(stderr, "Server supports ofs-delta\n");
 	} else
 		prefer_ofs_delta = 0;
+	if (server_supports("fixed-off-by-one-depth")) {
+		if (args->verbose)
+			fprintf(stderr, "Server has fixed meaning of depth value\n");
+		fixed_depth = 1;
+	}
 
 	if ((agent_feature = server_feature_value("agent", &agent_len))) {
 		agent_supported = 1;
-- 
1.8.3.rc1

  parent reply	other threads:[~2013-07-11 11:26 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-07 18:06 [PATCH] git clone depth of 0 not possible Stefan Beller
2013-01-07 18:06 ` [PATCH] Documentation on depth option in git clone Stefan Beller
2013-01-08  6:28 ` [PATCH] git clone depth of 0 not possible Jonathan Nieder
2013-01-08  6:54   ` Junio C Hamano
2013-01-08  7:36     ` Junio C Hamano
2013-01-08  8:19       ` Junio C Hamano
2013-01-08 14:28       ` Duy Nguyen
2013-01-08 14:32         ` Stefan Beller
2013-01-08 14:45           ` Duy Nguyen
2013-01-08 17:24           ` Junio C Hamano
2013-01-08  7:38     ` Duy Nguyen
2013-01-08  8:05       ` Junio C Hamano
2013-05-28  9:18         ` Matthijs Kooijman
2013-05-28 16:28           ` Jonathan Nieder
2013-05-28 16:31             ` Jonathan Nieder
2013-05-28 16:34             ` Matthijs Kooijman
2013-05-28 16:58               ` Jonathan Nieder
2013-05-28 17:04           ` Junio C Hamano
2013-05-30  8:23             ` Matthijs Kooijman
2013-06-02 19:14               ` Junio C Hamano
2013-07-09 13:35             ` Matthijs Kooijman
2013-07-11 10:57               ` Matthijs Kooijman
2013-07-11 11:25                 ` [PATCH 1/3] upload-pack: Remove a piece of dead code Matthijs Kooijman
2013-07-11 11:25                   ` [PATCH 2/3] upload-pack: Introduce new "fixed-off-by-one-depth" server feature Matthijs Kooijman
2013-07-11 11:25                   ` Matthijs Kooijman [this message]
2013-07-11 12:08                   ` [PATCH 1/3] upload-pack: Remove a piece of dead code Duy Nguyen
2013-07-11 15:49                     ` Junio C Hamano
2013-01-08  7:33 ` [PATCH] git clone depth of 0 not possible Duy Nguyen
2013-01-08  7:37   ` Junio C Hamano

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=1373541954-16493-3-git-send-email-matthijs@stdin.nl \
    --to=matthijs@stdin.nl \
    --cc=Ralf.Wildenhues@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=pclouds@gmail.com \
    --cc=schlotter@users.sourceforge.net \
    --cc=stefanbeller@googlemail.com \
    --subject='Re: [PATCH 3/3] fetch-pack: Request fixed-off-by-one-depth when available' \
    /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

Code repositories for project(s) associated with this 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).