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

[PATCH 21/27] upload-pack: support define shallow boundary by excluding revisions

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jun 10, 2016, 12:27 UTC
Message-ID
<20160610122714.3341-22-pclouds@gmail.com>
In-Reply-To
<20160610122714.3341-1-pclouds@gmail.com>

This should allow the user to say "create a shallow clone of this branch after version <some-tag>".

Short refs are accepted and expanded at the server side with expand_ref() because we cannot expand (unknown) refs from the client side.

Like deepen-since, deepen-not cannot be used with deepen. But deepen-not can be mixed with deepen-since. The result is exactly how you do the command "git rev-list --since=... --not ref".

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/technical/pack-protocol.txt         |  3 ++-
 Documentation/technical/protocol-capabilities.txt |  9 +++++++++
 upload-pack.c                                     | 23 +++++++++++++++++++++--
 3 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/Documentation/technical/pack-protocol.txt b/Documentation/technical/pack-protocol.txt
index 9251df1..dee33a6 100644
--- a/Documentation/technical/pack-protocol.txt
+++ b/Documentation/technical/pack-protocol.txt
@@ -220,7 +220,8 @@ out of what the server said it could do with the first 'want' line.
   shallow-line      =  PKT-LINE("shallow" SP obj-id)
 
   depth-request     =  PKT-LINE("deepen" SP depth) /
-		       PKT-LINE("deepen-since" SP timestamp)
+		       PKT-LINE("deepen-since" SP timestamp) /
+		       PKT-LINE("deepen-not" SP ref)
 
   first-want        =  PKT-LINE("want" SP obj-id SP capability-list)
   additional-want   =  PKT-LINE("want" SP obj-id)
diff --git a/Documentation/technical/protocol-capabilities.txt b/Documentation/technical/protocol-capabilities.txt
index f08cc4e..0e6b57d 100644
--- a/Documentation/technical/protocol-capabilities.txt
+++ b/Documentation/technical/protocol-capabilities.txt
@@ -188,6 +188,15 @@ specific time, instead of depth. Internally it's equivalent of doing
 "rev-list --max-age=<timestamp>" on the server side. "deepen-since"
 cannot be used with "deepen".
 
+deepen-not
+----------
+
+This capability adds "deepen-not" command to fetch-pack/upload-pack
+protocol so the client can request shallow clones that are cut at a
+specific revision, instead of depth. Internally it's equivalent of
+doing "rev-list --not <rev>" on the server side. "deepen-not"
+cannot be used with "deepen", but can be used with "deepen-since".
+
 no-progress
 -----------
 
diff --git a/upload-pack.c b/upload-pack.c
index b0ddfff..3f40fcb 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -643,6 +643,7 @@ static void deepen_by_rev_list(int ac, const char **av,
 static void receive_needs(void)
 {
 	struct object_array shallows = OBJECT_ARRAY_INIT;
+	struct string_list deepen_not = STRING_LIST_INIT_DUP;
 	int depth = 0;
 	int has_non_tip = 0;
 	unsigned long deepen_since = 0;
@@ -693,6 +694,16 @@ static void receive_needs(void)
 			deepen_rev_list = 1;
 			continue;
 		}
+		if (skip_prefix(line, "deepen-not ", &arg)) {
+			char *ref = NULL;
+			unsigned char sha1[20];
+			if (expand_ref(arg, strlen(arg), sha1, &ref) != 1)
+				die("git upload-pack: ambiguous deepen-not: %s", line);
+			string_list_append(&deepen_not, ref);
+			free(ref);
+			deepen_rev_list = 1;
+			continue;
+		}
 		if (!skip_prefix(line, "want ", &arg) ||
 		    get_sha1_hex(arg, sha1_buf))
 			die("git upload-pack: protocol error, "
@@ -747,7 +758,7 @@ static void receive_needs(void)
 	if (depth == 0 && !deepen_rev_list && shallows.nr == 0)
 		return;
 	if (depth > 0 && deepen_rev_list)
-		die("git upload-pack: deepen and deepen-since cannot be used together");
+		die("git upload-pack: deepen and deepen-since (or deepen-not) cannot be used together");
 	if (depth > 0)
 		deepen(depth, &shallows);
 	else if (deepen_rev_list) {
@@ -757,6 +768,14 @@ static void receive_needs(void)
 		argv_array_push(&av, "rev-list");
 		if (deepen_since)
 			argv_array_pushf(&av, "--max-age=%lu", deepen_since);
+		if (deepen_not.nr) {
+			argv_array_push(&av, "--not");
+			for (i = 0; i < deepen_not.nr; i++) {
+				struct string_list_item *s = deepen_not.items + i;
+				argv_array_push(&av, s->string);
+			}
+			argv_array_push(&av, "--not");
+		}
 		for (i = 0; i < want_obj.nr; i++) {
 			struct object *o = want_obj.objects[i].item;
 			argv_array_push(&av, oid_to_hex(&o->oid));
@@ -812,7 +831,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
 		    int flag, void *cb_data)
 {
 	static const char *capabilities = "multi_ack thin-pack side-band"
-		" side-band-64k ofs-delta shallow deepen-since no-progress"
+		" side-band-64k ofs-delta shallow deepen-since deepen-not no-progress"
 		" include-tag multi_ack_detailed";
 	const char *refname_nons = strip_namespace(refname);
 	struct object_id peeled;
-- 
2.8.2.524.g6ff3d78
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 25 of 64 in “nd/shallow-deepen updates”
  1. 00/27 nd/shallow-deepen updatesNguyễn Thái Ngọc Duy, Jun 10, 2016
  2. 08/27 upload-pack: tighten number parsing at "deepen" linesNguyễn Thái Ngọc Duy, Jun 10, 2016
  3. 09/27 upload-pack: make check_non_tip() clean things up errorNguyễn Thái Ngọc Duy, Jun 10, 2016
  4. Junio C HamanoJun 10, 2016
  5. 05/27 upload-pack: remove unused variable "backup"Nguyễn Thái Ngọc Duy, Jun 10, 2016
  6. Junio C HamanoJun 10, 2016
  7. 12/27 fetch-pack: use a common function for verbose printingNguyễn Thái Ngọc Duy, Jun 10, 2016
  8. 04/27 upload-pack: move "shallow" sending code out of deepen()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  9. Junio C HamanoJun 10, 2016
  10. 11/27 fetch-pack: use skip_prefix() instead of starts_with()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  11. 06/27 upload-pack: move "unshallow" sending code out of deepen()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  12. Junio C HamanoJun 10, 2016
  13. 03/27 upload-pack: move shallow deepen code out of receive_needs()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  14. 02/27 transport-helper.c: refactor set_helper_option()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  15. 01/27 remote-curl.c: convert fetch_git() to use argv_arrayNguyễn Thái Ngọc Duy, Jun 10, 2016
  16. 07/27 upload-pack: use skip_prefix() instead of starts_with()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  17. 10/27 upload-pack: move rev-list code out of check_non_tip()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  18. Junio C HamanoJun 10, 2016
  19. 25/27 upload-pack: split check_unreachable() in two, prep for get_reachable_list()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  20. 16/27 upload-pack: add deepen-since to cut shallow repos based on timeNguyễn Thái Ngọc Duy, Jun 10, 2016
  21. 17/27 fetch: define shallow boundary with --shallow-sinceNguyễn Thái Ngọc Duy, Jun 10, 2016
  22. 18/27 clone: define shallow clone boundary based on time with --shallow-sinceNguyễn Thái Ngọc Duy, Jun 10, 2016
  23. 24/27 t5500, t5539: tests for shallow depth excluding a refNguyễn Thái Ngọc Duy, Jun 10, 2016
  24. 23/27 clone: define shallow clone boundary with --shallow-excludeNguyễn Thái Ngọc Duy, Jun 10, 2016
  25. 21/27 upload-pack: support define shallow boundary by excluding revisionsNguyễn Thái Ngọc Duy, Jun 10, 2016
  26. 26/27 upload-pack: add get_reachable_list()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  27. 27/27 fetch, upload-pack: --deepen=N extends shallow boundary by N commitsNguyễn Thái Ngọc Duy, Jun 10, 2016
  28. 22/27 fetch: define shallow boundary with --shallow-excludeNguyễn Thái Ngọc Duy, Jun 10, 2016
  29. 14/27 fetch-pack: use a separate flag for fetch in deepening modeNguyễn Thái Ngọc Duy, Jun 10, 2016
  30. 20/27 refs: add expand_ref()Nguyễn Thái Ngọc Duy, Jun 10, 2016
  31. 19/27 t5500, t5539: tests for shallow depth since a specific dateNguyễn Thái Ngọc Duy, Jun 10, 2016
  32. 15/27 shallow.c: implement a generic shallow boundary finder based on rev-listNguyễn Thái Ngọc Duy, Jun 10, 2016
  33. 13/27 fetch-pack.c: mark strings for translatingNguyễn Thái Ngọc Duy, Jun 10, 2016
  34. Eric SunshineJun 10, 2016
  35. Junio C HamanoJun 13, 2016
  36. Duy NguyenJun 14, 2016
  37. 00/27 nd/shallow-deepen updatesNguyễn Thái Ngọc Duy, Jun 12, 2016
  38. 01/27 remote-curl.c: convert fetch_git() to use argv_arrayNguyễn Thái Ngọc Duy, Jun 12, 2016
  39. 02/27 transport-helper.c: refactor set_helper_option()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  40. 03/27 upload-pack: move shallow deepen code out of receive_needs()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  41. 05/27 upload-pack: remove unused variable "backup"Nguyễn Thái Ngọc Duy, Jun 12, 2016
  42. 04/27 upload-pack: move "shallow" sending code out of deepen()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  43. 06/27 upload-pack: move "unshallow" sending code out of deepen()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  44. 07/27 upload-pack: use skip_prefix() instead of starts_with()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  45. 08/27 upload-pack: tighten number parsing at "deepen" linesNguyễn Thái Ngọc Duy, Jun 12, 2016
  46. 09/27 upload-pack: make check_non_tip() clean things up on errorNguyễn Thái Ngọc Duy, Jun 12, 2016
  47. 11/27 fetch-pack: use skip_prefix() instead of starts_with()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  48. 10/27 upload-pack: move rev-list code out of check_non_tip()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  49. 12/27 fetch-pack: use a common function for verbose printingNguyễn Thái Ngọc Duy, Jun 12, 2016
  50. 13/27 fetch-pack.c: mark strings for translatingNguyễn Thái Ngọc Duy, Jun 12, 2016
  51. 14/27 fetch-pack: use a separate flag for fetch in deepening modeNguyễn Thái Ngọc Duy, Jun 12, 2016
  52. 15/27 shallow.c: implement a generic shallow boundary finder based on rev-listNguyễn Thái Ngọc Duy, Jun 12, 2016
  53. 16/27 upload-pack: add deepen-since to cut shallow repos based on timeNguyễn Thái Ngọc Duy, Jun 12, 2016
  54. 17/27 fetch: define shallow boundary with --shallow-sinceNguyễn Thái Ngọc Duy, Jun 12, 2016
  55. 18/27 clone: define shallow clone boundary based on time with --shallow-sinceNguyễn Thái Ngọc Duy, Jun 12, 2016
  56. 20/27 refs: add expand_ref()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  57. 19/27 t5500, t5539: tests for shallow depth since a specific dateNguyễn Thái Ngọc Duy, Jun 12, 2016
  58. 22/27 fetch: define shallow boundary with --shallow-excludeNguyễn Thái Ngọc Duy, Jun 12, 2016
  59. 21/27 upload-pack: support define shallow boundary by excluding revisionsNguyễn Thái Ngọc Duy, Jun 12, 2016
  60. 24/27 t5500, t5539: tests for shallow depth excluding a refNguyễn Thái Ngọc Duy, Jun 12, 2016
  61. 23/27 clone: define shallow clone boundary with --shallow-excludeNguyễn Thái Ngọc Duy, Jun 12, 2016
  62. 25/27 upload-pack: split check_unreachable() in two, prep for get_reachable_list()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  63. 26/27 upload-pack: add get_reachable_list()Nguyễn Thái Ngọc Duy, Jun 12, 2016
  64. 27/27 fetch, upload-pack: --deepen=N extends shallow boundary by N commitsNguyễn Thái Ngọc Duy, Jun 12, 2016

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.