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

[PATCH 1/2] [GSOC] ref-filter: add obj-type check in grab contents

From
ZheNing Hu via GitGitGadget <gitgitgadget@gmail.com>
Date
Jun 1, 2021, 14:37 UTC
Message-ID
<97955705c22e00a718a8de7555ab7e0e401e792e.1622558243.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.966.git.1622558243.gitgitgadget@gmail.com>
From: ZheNing Hu <adlternative@gmail.com>

Only tag and commit objects use `grab_sub_body_contents()` to grab object contents in the current codebase. We want to teach the function to also handle blobs and trees to get their raw data, without parsing a blob (whose contents looks like a commit or a tag) incorrectly as a commit or a tag.

Skip the block of code that is specific to handling commits and tags early when the given object is of a wrong type to help later addition to handle other types of objects in this function.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Hariom Verma <hariom18599@gmail.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
---
 ref-filter.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/ref-filter.c b/ref-filter.c
index 4db0e40ff4c6..c0334857653a 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1356,7 +1356,8 @@ static void append_lines(struct strbuf *out, const char *buf, unsigned long size
 }
 
 /* See grab_values */
-static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf)
+static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf,
+				   struct object *obj)
 {
 	int i;
 	const char *subpos = NULL, *bodypos = NULL, *sigpos = NULL;
@@ -1371,10 +1372,13 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf)
 			continue;
 		if (deref)
 			name++;
-		if (strcmp(name, "body") &&
-		    !starts_with(name, "subject") &&
-		    !starts_with(name, "trailers") &&
-		    !starts_with(name, "contents"))
+
+		if ((obj->type != OBJ_TAG &&
+		     obj->type != OBJ_COMMIT) ||
+		    (strcmp(name, "body") &&
+		     !starts_with(name, "subject") &&
+		     !starts_with(name, "trailers") &&
+		     !starts_with(name, "contents")))
 			continue;
 		if (!subpos)
 			find_subpos(buf,
@@ -1443,12 +1447,12 @@ static void grab_values(struct atom_value *val, int deref, struct object *obj, v
 	switch (obj->type) {
 	case OBJ_TAG:
 		grab_tag_values(val, deref, obj);
-		grab_sub_body_contents(val, deref, buf);
+		grab_sub_body_contents(val, deref, buf, obj);
 		grab_person("tagger", val, deref, buf);
 		break;
 	case OBJ_COMMIT:
 		grab_commit_values(val, deref, obj);
-		grab_sub_body_contents(val, deref, buf);
+		grab_sub_body_contents(val, deref, buf, obj);
 		grab_person("author", val, deref, buf);
 		grab_person("committer", val, deref, buf);
 		break;
-- 
gitgitgadget
Previous: ZheNing Hu via GitGitGadgetNext: Junio C Hamano
Message 2 of 23 in “[GSOC] ref-filter: add %(raw) atom”
  1. 0/2 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jun 1, 2021
  2. 1/2 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jun 1, 2021
  3. Junio C HamanoJun 3, 2021
  4. ZheNing HuJun 3, 2021
  5. 2/2 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jun 1, 2021
  6. Junio C HamanoJun 3, 2021
  7. ZheNing HuJun 3, 2021
  8. ZheNing HuJun 3, 2021
  9. Junio C HamanoJun 3, 2021
  10. Junio C HamanoJun 3, 2021
  11. ZheNing HuJun 4, 2021
  12. Bagas SanjayaJun 3, 2021
  13. ZheNing HuJun 3, 2021
  14. 0/2 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jun 4, 2021
  15. 1/2 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jun 4, 2021
  16. 2/2 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jun 4, 2021
  17. Christian CouderJun 4, 2021
  18. Christian CouderJun 4, 2021
  19. ZheNing HuJun 5, 2021
  20. Christian CouderJun 5, 2021
  21. ZheNing HuJun 5, 2021
  22. Christian CouderJun 5, 2021
  23. ZheNing HuJun 5, 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.