git@vger.kernel.org mailing list mirror (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 2/3] upload-pack: Introduce new "fixed-off-by-one-depth" server feature
Date: Thu, 11 Jul 2013 13:25:53 +0200	[thread overview]
Message-ID: <1373541954-16493-2-git-send-email-matthijs@stdin.nl> (raw)
In-Reply-To: <1373541954-16493-1-git-send-email-matthijs@stdin.nl>

Commit 682c7d2 (upload-pack: fix off-by-one depth calculation in shallow
clone) changed the meaning of the fetch depth sent over the wire to mean
the total number of commits to return, instead of the number of commits
beyond the first. However, when this change is deployed on some servers
but not others, this can cause a client to behave differently based on
the server version, which is unexpected.

To prevent this, the new, fixed, depth behaviour is advertised as a server
feature and the old behaviour is restored when the feature is not
requested by the client.

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

diff --git a/upload-pack.c b/upload-pack.c
index 127e59a..59f43d1 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -46,6 +46,7 @@ static unsigned int timeout;
 static int use_sideband;
 static int advertise_refs;
 static int stateless_rpc;
+static int fixed_depth;
 
 static void reset_timeout(void)
 {
@@ -633,6 +634,8 @@ static void receive_needs(void)
 			no_progress = 1;
 		if (parse_feature_request(features, "include-tag"))
 			use_include_tag = 1;
+		if (parse_feature_request(features, "fixed-off-by-one-depth"))
+			fixed_depth = 1;
 
 		o = parse_object(sha1_buf);
 		if (!o)
@@ -669,10 +672,14 @@ static void receive_needs(void)
 				struct object *object = shallows.objects[i].item;
 				object->flags |= NOT_SHALLOW;
 			}
-		else
+		else {
+			/* Emulate off-by-one bug in older versions */
+			if (!fixed_depth)
+				depth++;
 			backup = result =
 				get_shallow_commits(&want_obj, depth,
 						    SHALLOW, NOT_SHALLOW);
+		}
 		while (result) {
 			struct object *object = &result->item->object;
 			if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
@@ -738,7 +745,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
 {
 	static const char *capabilities = "multi_ack thin-pack side-band"
 		" side-band-64k ofs-delta shallow no-progress"
-		" include-tag multi_ack_detailed";
+		" include-tag multi_ack_detailed fixed-off-by-one-depth";
 	const char *refname_nons = strip_namespace(refname);
 	unsigned char peeled[20];
 
-- 
1.8.3.rc1

  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                   ` Matthijs Kooijman [this message]
2013-07-11 11:25                   ` [PATCH 3/3] fetch-pack: Request fixed-off-by-one-depth when available Matthijs Kooijman
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-2-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 \
    /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).