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

[PATCH 09/15] [GSOC] ref-filter: modify the error message and value in get_object

From
ZheNing Hu via GitGitGadget <gitgitgadget@gmail.com>
Date
Jul 1, 2021, 16:08 UTC
Message-ID
<0149940ee4d7282360234f1ef1ec270def83c907.1625155693.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.989.git.1625155693.gitgitgadget@gmail.com>
From: ZheNing Hu <adlternative@gmail.com>

Let get_object() return 1 and print "<oid> missing" instead of returning -1 and printing "missing object <oid> for <refname>" if oid_object_info_extended() unable to find the data corresponding to oid. When `cat-file --batch` use ref-filter logic later it can help `format_ref_array_item()` just report that the object is missing without letting Git exit.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Hariom Verma <hariom18599@gmail.com>
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
---
 ref-filter.c                   | 4 ++--
 t/t6301-for-each-ref-errors.sh | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/ref-filter.c b/ref-filter.c
index 45122959eef..9ca3dd5557d 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1749,8 +1749,8 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj
 	}
 	if (oid_object_info_extended(the_repository, &oi->oid, &oi->info,
 				     OBJECT_INFO_LOOKUP_REPLACE))
-		return strbuf_addf_ret(err, -1, _("missing object %s for %s"),
-				       oid_to_hex(&oi->oid), ref->refname);
+		return strbuf_addf_ret(err, 1, _("%s missing"),
+				       oid_to_hex(&oi->oid));
 	if (oi->info.disk_sizep && oi->disk_size < 0)
 		BUG("Object size is less than zero.");
 
diff --git a/t/t6301-for-each-ref-errors.sh b/t/t6301-for-each-ref-errors.sh
index 40edf9dab53..3553f84a00c 100755
--- a/t/t6301-for-each-ref-errors.sh
+++ b/t/t6301-for-each-ref-errors.sh
@@ -41,7 +41,7 @@ test_expect_success 'Missing objects are reported correctly' '
 	r=refs/heads/missing &&
 	echo $MISSING >.git/$r &&
 	test_when_finished "rm -f .git/$r" &&
-	echo "fatal: missing object $MISSING for $r" >missing-err &&
+	echo "fatal: $MISSING missing" >missing-err &&
 	test_must_fail git for-each-ref 2>err &&
 	test_cmp missing-err err &&
 	(
-- 
gitgitgadget
Previous: ZheNing Hu via GitGitGadgetNext: ZheNing Hu via GitGitGadget
Message 19 of 39 in “[GSOC] cat-file: reuse ref-filter logic”
  1. 00/15 [GSOC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jul 1, 2021
  2. 01/15 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jul 1, 2021
  3. 03/15 [GSOC] ref-filter: --format=%(raw) re-support --perlZheNing Hu via GitGitGadget, Jul 1, 2021
  4. Ævar Arnfjörð BjarmasonJul 2, 2021
  5. ZheNing HuJul 3, 2021
  6. 02/15 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jul 1, 2021
  7. Ævar Arnfjörð BjarmasonJul 2, 2021
  8. ZheNing HuJul 3, 2021
  9. 05/15 [GSOC] ref-filter: add %(rest) atomZheNing Hu via GitGitGadget, Jul 1, 2021
  10. 04/15 [GSOC] ref-filter: use non-const ref_format in *_atom_parser()ZheNing Hu via GitGitGadget, Jul 1, 2021
  11. 06/15 [GSOC] ref-filter: pass get_object() return value to their callersZheNing Hu via GitGitGadget, Jul 1, 2021
  12. 08/15 [GSOC] ref-filter: add cat_file_mode in struct ref_formatZheNing Hu via GitGitGadget, Jul 1, 2021
  13. Ævar Arnfjörð BjarmasonJul 2, 2021
  14. Eric SunshineJul 2, 2021
  15. Christian CouderJul 2, 2021
  16. ZheNing HuJul 3, 2021
  17. Ævar Arnfjörð BjarmasonJul 5, 2021
  18. 07/15 [GSOC] ref-filter: introduce free_ref_array_item_value() functionZheNing Hu via GitGitGadget, Jul 1, 2021
  19. 09/15 [GSOC] ref-filter: modify the error message and value in get_objectZheNing Hu via GitGitGadget, Jul 1, 2021
  20. 11/15 [GSOC] cat-file: change batch_objects parameter nameZheNing Hu via GitGitGadget, Jul 1, 2021
  21. 12/15 [GSOC] cat-file: reuse ref-filter logicZheNing Hu via GitGitGadget, Jul 1, 2021
  22. Ævar Arnfjörð BjarmasonJul 2, 2021
  23. Christian CouderJul 2, 2021
  24. ZheNing HuJul 3, 2021
  25. ZheNing HuJul 3, 2021
  26. Ævar Arnfjörð BjarmasonJul 3, 2021
  27. ZheNing HuJul 4, 2021
  28. Ævar Arnfjörð BjarmasonJul 5, 2021
  29. 10/15 [GSOC] cat-file: add has_object_file() checkZheNing Hu via GitGitGadget, Jul 1, 2021
  30. Ævar Arnfjörð BjarmasonJul 2, 2021
  31. ZheNing HuJul 3, 2021
  32. 13/15 [GSOC] cat-file: reuse err buf in batch_object_write()ZheNing Hu via GitGitGadget, Jul 1, 2021
  33. 14/15 [GSOC] cat-file: re-implement --textconv, --filters optionsZheNing Hu via GitGitGadget, Jul 1, 2021
  34. Junio C HamanoJul 1, 2021
  35. Junio C HamanoJul 1, 2021
  36. ZheNing HuJul 2, 2021
  37. Junio C HamanoJul 2, 2021
  38. ZheNing HuJul 3, 2021
  39. 15/15 [GSOC] ref-filter: remove grab_oid() functionZheNing Hu via GitGitGadget, Jul 1, 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.