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

[PATCH v2 1/3] packfile-uris: support for excluding commit object

From
Teng Long <dyroneteng@gmail.com>
Date
May 18, 2021, 08:49 UTC
Message-ID
<73e64147b17cb382d34357c913616095b6169650.1621327467.git.dyroneteng@gmail.com>
In-Reply-To
<cover.1621327467.git.dyroneteng@gmail.com>

On the server, more sophisticated means of excluding objects should be supported, such as commit object. This commit introduces a new configuration `uploadpack.excludeobject` for this.

The old configuration `uploadpack.blobpackfileuri` is only support to exclude blobs and the name has no abstract meaning, so the configruation name changes, to support more object types. Compatibility issues will not be considered because packfile-uris now is an experimental feature.

In addition to the configuration name, the format of the configuration value has also been expanded. When excluding the commits (or trees in the future) objects, the old format `<object-hash> <pack-hash> <uri>` can not express the meaning of recursion. So, the format is expanded, the new format `<object-hash> <recursively> <pack-hash> <uri>` should deal with this scenario (When processing commit objects, whether they are absolutely recursively excluded).

Signed-off-by: Teng Long <dyroneteng@gmail.com>
---
 builtin/pack-objects.c | 53 ++++++++++++++++++++++++++++++------------
 fetch-pack.c           |  5 ++++
 upload-pack.c          |  5 ++--
 3 files changed, 45 insertions(+), 18 deletions(-)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 6d13cd3e1a..e687061420 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -99,6 +99,8 @@ static struct bitmap *reuse_packfile_bitmap;
 static int use_bitmap_index_default = 1;
 static int use_bitmap_index = -1;
 static int allow_pack_reuse = 1;
+static int in_commit_order;
+static int exclude_until_next_commit;
 static enum {
 	WRITE_BITMAP_FALSE = 0,
 	WRITE_BITMAP_QUIET,
@@ -132,6 +134,7 @@ struct configured_exclusion {
 	struct oidmap_entry e;
 	char *pack_hash_hex;
 	char *uri;
+	int recursively:1;
 };
 static struct oidmap configured_exclusions;
 
@@ -1291,10 +1294,16 @@ static int want_object_in_pack_one(struct packed_git *p,
  * and its offset in these variables.
  */
 static int want_object_in_pack(const struct object_id *oid,
+			       enum object_type type,
 			       int exclude,
 			       struct packed_git **found_pack,
 			       off_t *found_offset)
 {
+	if (exclude_until_next_commit && type != OBJ_COMMIT)
+		return 0;
+	if (type == OBJ_COMMIT)
+		exclude_until_next_commit = 0 ;
+
 	int want;
 	struct list_head *pos;
 	struct multi_pack_index *m;
@@ -1345,6 +1354,8 @@ static int want_object_in_pack(const struct object_id *oid,
 						&p) &&
 				    *p == ':') {
 					oidset_insert(&excluded_by_config, oid);
+					if(ex->recursively && type == OBJ_COMMIT)
+						exclude_until_next_commit = 1;
 					return 0;
 				}
 			}
@@ -1394,7 +1405,7 @@ static int add_object_entry(const struct object_id *oid, enum object_type type,
 	if (have_duplicate_entry(oid, exclude))
 		return 0;
 
-	if (!want_object_in_pack(oid, exclude, &found_pack, &found_offset)) {
+	if (!want_object_in_pack(oid, type, exclude, &found_pack, &found_offset)) {
 		/* The pack is missing an object, so it will not have closure */
 		if (write_bitmap_index) {
 			if (write_bitmap_index != WRITE_BITMAP_QUIET)
@@ -1420,7 +1431,7 @@ static int add_object_entry_from_bitmap(const struct object_id *oid,
 	if (have_duplicate_entry(oid, 0))
 		return 0;
 
-	if (!want_object_in_pack(oid, 0, &pack, &offset))
+	if (!want_object_in_pack(oid, type, 0, &pack, &offset))
 		return 0;
 
 	create_object_entry(oid, type, name_hash, 0, 0, pack, offset);
@@ -2985,27 +2996,33 @@ static int git_pack_config(const char *k, const char *v, void *cb)
 			pack_idx_opts.flags &= ~WRITE_REV;
 		return 0;
 	}
-	if (!strcmp(k, "uploadpack.blobpackfileuri")) {
+	if (!strcmp(k, "uploadpack.excludeobject")) {
 		struct configured_exclusion *ex = xmalloc(sizeof(*ex));
-		const char *oid_end, *pack_end;
+		const char *oid_end, *pack_end, *recursively_end;
 		/*
 		 * Stores the pack hash. This is not a true object ID, but is
 		 * of the same form.
 		 */
 		struct object_id pack_hash;
-
+		char recursively[2];
 		if (parse_oid_hex(v, &ex->e.oid, &oid_end) ||
 		    *oid_end != ' ' ||
-		    parse_oid_hex(oid_end + 1, &pack_hash, &pack_end) ||
+		    !strlcpy(recursively, oid_end + 1, sizeof(recursively)) ||
+		    parse_oid_hex(oid_end + 3, &pack_hash, &pack_end) ||
 		    *pack_end != ' ')
-			die(_("value of uploadpack.blobpackfileuri must be "
-			      "of the form '<object-hash> <pack-hash> <uri>' (got '%s')"), v);
+                        die(_("value of uploadpack.excludeobject must be "
+                              "of the form '<object-hash> <recursively> <pack-hash> <uri>' (got '%s')"), v);
 		if (oidmap_get(&configured_exclusions, &ex->e.oid))
-			die(_("object already configured in another "
-			      "uploadpack.blobpackfileuri (got '%s')"), v);
-		ex->pack_hash_hex = xcalloc(1, pack_end - oid_end);
-		memcpy(ex->pack_hash_hex, oid_end + 1, pack_end - oid_end - 1);
+                        die(_("object already configured by an earlier "
+                              "uploadpack.excludeobject (got '%s')"), v);
+		recursively_end = oid_end + 2;
+		ex->pack_hash_hex = xcalloc(1, pack_end - recursively_end);
+		memcpy(ex->pack_hash_hex, recursively_end + 1, pack_end - recursively_end - 1);
 		ex->uri = xstrdup(pack_end + 1);
+		if (atoi(recursively)) {
+			ex->recursively = 1;
+			in_commit_order = 1;
+                }
 		oidmap_put(&configured_exclusions, ex);
 	}
 	return git_default_config(k, v, cb);
@@ -3023,7 +3040,7 @@ static int add_object_entry_from_pack(const struct object_id *oid,
 	struct rev_info *revs = _data;
 	struct object_info oi = OBJECT_INFO_INIT;
 	off_t ofs;
-	enum object_type type;
+	static enum object_type type;
 
 	display_progress(progress_state, ++nr_seen);
 
@@ -3031,7 +3048,7 @@ static int add_object_entry_from_pack(const struct object_id *oid,
 		return 0;
 
 	ofs = nth_packed_object_offset(p, pos);
-	if (!want_object_in_pack(oid, 0, &p, &ofs))
+	if (!want_object_in_pack(oid, type, 0, &p, &ofs))
 		return 0;
 
 	oi.typep = &type;
@@ -3831,7 +3848,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 			 N_("respect islands during delta compression")),
 		OPT_STRING_LIST(0, "uri-protocol", &uri_protocols,
 				N_("protocol"),
-				N_("exclude any configured uploadpack.blobpackfileuri with this protocol")),
+				N_("exclude any configured uploadpack.excludeobject with this protocol")),
 		OPT_END(),
 	};
 
@@ -3903,6 +3920,12 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 		fetch_if_missing = 0;
 		strvec_push(&rp, "--exclude-promisor-objects");
 	}
+
+	if (in_commit_order){
+		use_internal_rev_list = 1;
+		strvec_push(&rp, "--in-commit-order");
+	}
+
 	if (unpack_unreachable || keep_unreachable || pack_loose_unreachable)
 		use_internal_rev_list = 1;
 
diff --git a/fetch-pack.c b/fetch-pack.c
index 2318ebe680..cdf8777907 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -23,6 +23,7 @@
 #include "fetch-negotiator.h"
 #include "fsck.h"
 #include "shallow.h"
+#include "strmap.h"
 
 static int transfer_unpack_limit = -1;
 static int fetch_unpack_limit = -1;
@@ -1677,6 +1678,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 		}
 	}
 
+	struct strset uris;
+	strset_init(&uris);
 	for (i = 0; i < packfile_uris.nr; i++) {
 		int j;
 		struct child_process cmd = CHILD_PROCESS_INIT;
@@ -1684,6 +1687,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 		const char *uri = packfile_uris.items[i].string +
 			the_hash_algo->hexsz + 1;
 
+		if (!strset_add(&uris, uri))
+			continue;
 		strvec_push(&cmd.args, "http-fetch");
 		strvec_pushf(&cmd.args, "--packfile=%.*s",
 			     (int) the_hash_algo->hexsz,
diff --git a/upload-pack.c b/upload-pack.c
index 5c1cd19612..4d994658d2 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -1745,9 +1745,8 @@ int upload_pack_advertise(struct repository *r,
 			strbuf_addstr(value, " sideband-all");
 
 		if (!repo_config_get_string(the_repository,
-					    "uploadpack.blobpackfileuri",
-					    &str) &&
-		    str) {
+					 "uploadpack.excludeobject",
+					 &str) && str) {
 			strbuf_addstr(value, " packfile-uris");
 			free(str);
 		}
-- 
2.31.1.442.g7e39198978.dirty
Previous: Teng LongNext: Junio C Hamano
Message 4 of 72 in “Packfile-uris support excluding commit objects”
  1. Packfile-uris support excluding commit objectsTeng Long, May 7, 2021
  2. Ævar Arnfjörð BjarmasonMay 10, 2021
  3. 0/3 packfile-uris: commit objects exclusionTeng Long, May 18, 2021
  4. 1/3 packfile-uris: support for excluding commit objectTeng Long, May 18, 2021
  5. Junio C HamanoMay 19, 2021
  6. Junio C HamanoMay 20, 2021
  7. 2/3 packfile-uris.txt: excluding commit objectTeng Long, May 18, 2021
  8. 3/3 t5702: excluding commits with packfile-urisTeng Long, May 18, 2021
  9. 0/3 packfile-uris: commit objects exclusioTeng Long, Jul 26, 2021
  10. 1/3 packfile-uris: support for excluding commit objectsTeng Long, Jul 26, 2021
  11. Junio C HamanoJul 26, 2021
  12. Felipe ContrerasJul 26, 2021
  13. Teng LongAug 11, 2021
  14. 2/3 t5702: support for excluding commit objectsTeng Long, Jul 26, 2021
  15. Ævar Arnfjörð BjarmasonJul 26, 2021
  16. Teng LongAug 11, 2021
  17. 3/3 packfile-uri.txt: support for excluding commit objectsTeng Long, Jul 26, 2021
  18. Junio C HamanoJul 26, 2021
  19. Teng LongAug 11, 2021
  20. Ævar Arnfjörð BjarmasonJul 26, 2021
  21. Teng LongAug 11, 2021
  22. 0/7 packfile-uris: commits and trees exclusionTeng Long, Aug 11, 2021
  23. 1/7 pack-objects.c: introduce new method `match_packfile_uri_exclusions`Teng Long, Aug 11, 2021
  24. 2/7 Add new parameter "carry_data" for "show_object" functionTeng Long, Aug 11, 2021
  25. 3/7 packfile-uri: support for excluding commit objectsTeng Long, Aug 11, 2021
  26. 4/7 packfile-uri: support for excluding tree objectsTeng Long, Aug 11, 2021
  27. 5/7 packfile-uri.txt: support for excluding commits and treesTeng Long, Aug 11, 2021
  28. Bagas SanjayaAug 11, 2021
  29. 6/7 t5702: replace with "test_when_finished" for cleanupTeng Long, Aug 11, 2021
  30. 7/7 t5702: support for excluding commit objectsTeng Long, Aug 11, 2021
  31. 00/14 packfile-uris: commits, trees and tags exclusionTeng Long, Aug 25, 2021
  32. 01/14 pack-objects.c: introduce new method `match_packfile_uri_exclusions`Teng Long, Aug 25, 2021
  33. 02/14 Add new parameter "carry_data" for "show_object" functionTeng Long, Aug 25, 2021
  34. Junio C HamanoAug 26, 2021
  35. Teng LongSep 2, 2021
  36. 03/14 packfile-uri: support for excluding commit objectsTeng Long, Aug 25, 2021
  37. Ævar Arnfjörð BjarmasonAug 25, 2021
  38. Teng LongSep 2, 2021
  39. Junio C HamanoAug 26, 2021
  40. Teng LongSep 2, 2021
  41. 04/14 packfile-uri: support for excluding tree objectsTeng Long, Aug 25, 2021
  42. 05/14 packfile-uri.txt: support for excluding commits and treesTeng Long, Aug 25, 2021
  43. Ævar Arnfjörð BjarmasonAug 25, 2021
  44. Teng LongSep 2, 2021
  45. 06/14 t5702: replace with "test_when_finished" for cleanupTeng Long, Aug 25, 2021
  46. Ævar Arnfjörð BjarmasonAug 25, 2021
  47. Teng LongSep 2, 2021
  48. 07/14 t5702: support for excluding commit objectsTeng Long, Aug 25, 2021
  49. 08/14 Add new parameter "carry_data" for "show_commit functionTeng Long, Aug 25, 2021
  50. 09/14 commit.h: add wrapped tags in commit structTeng Long, Aug 25, 2021
  51. Ævar Arnfjörð BjarmasonAug 25, 2021
  52. Teng LongSep 2, 2021
  53. ZheNing HuSep 2, 2021
  54. Teng LongSep 2, 2021
  55. 10/14 object.h: add referred tags in `referred_objects` structTeng Long, Aug 25, 2021
  56. 11/14 packfile-uri: support for excluding tag objectsTeng Long, Aug 25, 2021
  57. 12/14 packfile-uri.txt: support for excluding tag objectsTeng Long, Aug 25, 2021
  58. 13/14 t5702: add tag exclusion test caseTeng Long, Aug 25, 2021
  59. 14/14 pack-objects.c: introduce `want_exclude_object` functionTeng Long, Aug 25, 2021
  60. 00/12 packfile-uri: support excluding multiple object typesTeng Long, Oct 19, 2021
  61. 01/12 objects.c: introduce `exclude_level` enumTeng Long, Oct 19, 2021
  62. 02/12 Introduce function `match_packfile_uri_exclusions`Teng Long, Oct 19, 2021
  63. 03/12 Replace `show_data` with structure `show_info`Teng Long, Oct 19, 2021
  64. 04/12 Introduce `uploadpack.excludeobject` configurationTeng Long, Oct 19, 2021
  65. 05/12 t5702: test cases for `uploadpack.excludeobject`Teng Long, Oct 19, 2021
  66. 06/12 packfile-uri: support for excluding commitsTeng Long, Oct 19, 2021
  67. 07/12 t5702: test cases for excluding commitsTeng Long, Oct 19, 2021
  68. 08/12 packfile-uri: support for excluding treesTeng Long, Oct 19, 2021
  69. 09/12 t5702: test cases for excluding treesTeng Long, Oct 19, 2021
  70. 10/12 packfile-uri: support for excluding tagsTeng Long, Oct 19, 2021
  71. 11/12 t5702: test cases for excluding tagsTeng Long, Oct 19, 2021
  72. 12/12 packfile-uri.txt: support multiple object typesTeng Long, Oct 19, 2021

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.