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

[PATCH v6 10/12] packfile-uri: support for excluding tags

From
Teng Long <dyroneteng@gmail.com>
Date
Oct 19, 2021, 11:38 UTC
Message-ID
<16c41c40a26e72d64959a332fbf7dc1c9794e70c.1634634814.git.tenglong@alibaba-inc.com>
In-Reply-To
<cover.1634634814.git.tenglong@alibaba-inc.com>
From: Teng Long <dyroneteng@gmail.com>

This commit brings the tags exclusion feature of packfile-uri. The excluding level of tag is supported with "ET_SELF", "ET_INCLUDE" and "ET_REACHABLE".

Exclusion scope on different level:
1. When a tag is specified to be excluded with level "ET_SELF",
only the tag object itself will be excluded.
2. When it's specified to be excluded with level "ET_INCLUDE",
exclude the referenced commit, and all trees and blobs contained in its
top-level. If it's a annotated tag, the tag object will be excluded
too.
3. When it is specified with level "ET_REACHABLE", exclude the ancestors
of the referenced commit, as well as the objects need to be excluded
under the level "ET_INCLUDED".
Signed-off-by: Teng Long <dyroneteng@gmail.com>
---
 builtin/pack-objects.c |  6 +++++-
 list-objects.c         | 20 ++++++++++++++++----
 object.c               |  1 +
 object.h               |  1 +
 revision.c             | 13 ++++++++++++-
 revision.h             |  9 +++++++++
 6 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 6713e734fb..073c3815a1 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1416,6 +1416,9 @@ static int want_object_in_pack(const struct object_id *oid,
 		if (referred_objs) {
 			struct commit *commit = referred_objs->commit;
 			struct object_list *trees = referred_objs->trees;
+			struct object_list *tags = referred_objs->tags;
+			if (want_exclude_object(tags))
+				return 0;
 			if (commit) {
 				commit_ex = oidmap_get(&configured_exclusions, &commit->object.oid);
 				if (match_packfile_uri_exclusions(commit_ex) && commit_ex->level > ET_SELF)
@@ -3344,7 +3347,8 @@ static void read_object_list_from_stdin(void)
 
 static void show_commit(struct commit *commit, struct show_info *info)
 {
-	add_object_entry(&commit->object.oid, OBJ_COMMIT, NULL, 0, NULL);
+	struct referred_objects *referred_objs = info->show_cache;
+	add_object_entry(&commit->object.oid, OBJ_COMMIT, NULL, 0, referred_objs);
 	commit->object.flags |= OBJECT_ADDED;
 
 	if (write_bitmap_index)
diff --git a/list-objects.c b/list-objects.c
index 40292e2cc8..2e241e8707 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -348,9 +348,10 @@ static void traverse_trees_and_blobs(struct traversal_context *ctx,
 	for (i = 0; i < ctx->revs->pending.nr; i++) {
 		struct object_array_entry *pending = ctx->revs->pending.objects + i;
 		struct object *obj = pending->item;
-		struct referred_objects *referred_objs = pending->referred_objects;
 		const char *name = pending->name;
 		const char *path = pending->path;
+		struct referred_objects *referred_objs = pending->referred_objects;
+		struct commit_wraps_entry *cw_entry = NULL;
 		if (obj->flags & (UNINTERESTING | SEEN))
 			continue;
 		if (obj->type == OBJ_TAG) {
@@ -358,6 +359,10 @@ static void traverse_trees_and_blobs(struct traversal_context *ctx,
 			ctx->show_object(obj, name, &show_info);
 			continue;
 		}
+		if (referred_objs->commit)
+			cw_entry = oidmap_get(ctx->revs->commit_wraps, &referred_objs->commit->object.oid);
+		if (cw_entry)
+			referred_objs->tags = cw_entry->wraps;
 		if (!path)
 			path = "";
 		if (obj->type == OBJ_TREE) {
@@ -378,12 +383,14 @@ static void do_traverse(struct traversal_context *ctx)
 {
 	struct commit *commit;
 	struct strbuf csp; /* callee's scratch pad */
-	struct show_info show_info;
+	struct commit_wraps_entry *entry;
+	struct oidmap *commit_wraps = ctx->revs->commit_wraps;
+	struct referred_objects referred_objs = { NULL, NULL, NULL };
+	struct show_info show_info = { ctx->show_data , NULL };
 	strbuf_init(&csp, PATH_MAX);
 
-
 	show_info.show_data = ctx->show_data;
-	show_info.show_cache = NULL;
+	show_info.show_cache = &referred_objs;
 
 	while ((commit = get_revision(ctx->revs)) != NULL) {
 		/*
@@ -401,6 +408,11 @@ static void do_traverse(struct traversal_context *ctx)
 			      oid_to_hex(&commit->object.oid));
 		}
 
+		if (commit_wraps) {
+			entry = oidmap_get(commit_wraps, &commit->object.oid);
+			referred_objs.tags = entry ? entry->wraps : NULL;
+		}
+
 		ctx->show_commit(commit, &show_info);
 
 		if (ctx->revs->tree_blobs_in_commit_order)
diff --git a/object.c b/object.c
index 895068cbc2..167cc87ec9 100644
--- a/object.c
+++ b/object.c
@@ -335,6 +335,7 @@ void add_object_array_with_path_and_referred_commit(struct object *obj, const ch
 	referred_objs = xmalloc(sizeof(struct referred_objects));
 	referred_objs->commit = referred_commit;
 	referred_objs->trees = NULL;
+	referred_objs->tags = NULL;
 
 	if (nr >= alloc) {
 		alloc = (alloc + 32) * 2;
diff --git a/object.h b/object.h
index 618d674249..42a2178531 100644
--- a/object.h
+++ b/object.h
@@ -66,6 +66,7 @@ struct object_array {
 struct referred_objects{
     struct commit *commit;
     struct object_list *trees;
+    struct object_list *tags;
 };
 #define OBJECT_ARRAY_INIT { 0, 0, NULL }
 
diff --git a/revision.c b/revision.c
index 89a8b311ea..d16f9bbbb9 100644
--- a/revision.c
+++ b/revision.c
@@ -416,14 +416,17 @@ static struct commit *handle_commit(struct rev_info *revs,
 	const char *path = entry->path;
 	unsigned int mode = entry->mode;
 	unsigned long flags = object->flags;
+	struct object_list *wraps = NULL;
 
 	/*
 	 * Tag object? Look what it points to..
 	 */
 	while (object->type == OBJ_TAG) {
 		struct tag *tag = (struct tag *) object;
-		if (revs->tag_objects && !(flags & UNINTERESTING))
+		if (revs->tag_objects && !(flags & UNINTERESTING)) {
 			add_pending_object(revs, object, tag->tag);
+			object_list_insert(object, &wraps);
+		}
 		object = parse_object(revs->repo, get_tagged_oid(tag));
 		if (!object) {
 			if (revs->ignore_missing_links || (flags & UNINTERESTING))
@@ -449,6 +452,14 @@ static struct commit *handle_commit(struct rev_info *revs,
 	 */
 	if (object->type == OBJ_COMMIT) {
 		struct commit *commit = (struct commit *)object;
+		struct oidmap *commit_wraps = malloc(sizeof(struct oidmap));
+		struct commit_wraps_entry *cw_entry = xmalloc(sizeof(struct commit_wraps_entry));
+
+		oidmap_init(commit_wraps, 0);
+		cw_entry->e.oid = object->oid;
+		cw_entry->wraps = wraps;
+		oidmap_put(commit_wraps, cw_entry);
+		revs->commit_wraps = commit_wraps;
 
 		if (repo_parse_commit(revs->repo, commit) < 0)
 			die("unable to parse commit %s", name);
diff --git a/revision.h b/revision.h
index b2e0c0b9b7..a633ea2174 100644
--- a/revision.h
+++ b/revision.h
@@ -8,6 +8,7 @@
 #include "pretty.h"
 #include "diff.h"
 #include "commit-slab-decl.h"
+#include "oidmap.h"
 
 /**
  * The revision walking API offers functions to build a list of revisions
@@ -64,6 +65,11 @@ struct bloom_key;
 struct bloom_filter_settings;
 define_shared_commit_slab(revision_sources, char *);
 
+struct commit_wraps_entry {
+    struct oidmap_entry e;
+    struct object_list *wraps;
+};
+
 struct rev_cmdline_info {
 	unsigned int nr;
 	unsigned int alloc;
@@ -321,6 +327,9 @@ struct rev_info {
 
 	/* misc. flags related to '--no-kept-objects' */
 	unsigned keep_pack_cache_flags;
+
+	/* The commit_wraps caches the referred wrapped objects(such as tags) of a commit */
+	struct oidmap *commit_wraps;
 };
 
 int ref_excluded(struct string_list *, const char *path);
-- 
2.31.1.453.g945ddc3a74.dirty
Previous: Teng LongNext: Teng Long
Message 70 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.