git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] upload-pack: Introduce new "fixed-off-by-one-depth" server feature

From
Matthijs Kooijman <matthijs@stdin.nl>
Date
Jul 11, 2013, 11:25 UTC
Message-ID
<1373541954-16493-2-git-send-email-matthijs@stdin.nl>
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
Previous: Matthijs KooijmanNext: Matthijs Kooijman
Message 24 of 29 in “git clone depth of 0 not possible.”
  1. git clone depth of 0 not possible.Stefan Beller, Jan 7, 2013
  2. Documentation on depth option in git clone.Stefan Beller, Jan 7, 2013
  3. Jonathan NiederJan 8, 2013
  4. Junio C HamanoJan 8, 2013
  5. Junio C HamanoJan 8, 2013
  6. Junio C HamanoJan 8, 2013
  7. Duy NguyenJan 8, 2013
  8. Stefan BellerJan 8, 2013
  9. Duy NguyenJan 8, 2013
  10. Junio C HamanoJan 8, 2013
  11. Duy NguyenJan 8, 2013
  12. Junio C HamanoJan 8, 2013
  13. Matthijs KooijmanMay 28, 2013
  14. Jonathan NiederMay 28, 2013
  15. Jonathan NiederMay 28, 2013
  16. Matthijs KooijmanMay 28, 2013
  17. Jonathan NiederMay 28, 2013
  18. Junio C HamanoMay 28, 2013
  19. Matthijs KooijmanMay 30, 2013
  20. Junio C HamanoJun 2, 2013
  21. Matthijs KooijmanJul 9, 2013
  22. Matthijs KooijmanJul 11, 2013
  23. 1/3 upload-pack: Remove a piece of dead codeMatthijs Kooijman, Jul 11, 2013
  24. 2/3 upload-pack: Introduce new "fixed-off-by-one-depth" server featureMatthijs Kooijman, Jul 11, 2013
  25. 3/3 fetch-pack: Request fixed-off-by-one-depth when availableMatthijs Kooijman, Jul 11, 2013
  26. Duy NguyenJul 11, 2013
  27. Junio C HamanoJul 11, 2013
  28. Duy NguyenJan 8, 2013
  29. Junio C HamanoJan 8, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.