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

Re: [PATCH v4 1/2] cat-file: extract printing batch error message into function

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 3, 2023, 20:26 UTC
Message-ID
<xmqqcz5peg3v.fsf@gitster.g>
In-Reply-To
<20230303191708.77894-2-toon@iotcl.com>
Toon Claes <toon@iotcl.com> writes:
Show 12 quoted lines
> There are two callsites that were formatting an error message in batch
> mode if an object could not be found. We're about to make changes to
> that and to avoid doing that twice, we extract this into a separate
> function.
>
> Signed-off-by: Toon Claes <toon@iotcl.com>
> ...
> +static void batch_print_error(const char *obj_name,
> +			      enum get_oid_result result,
> +			      struct batch_options* opt)
> +{
> +		switch (result) {

The body of this function is indented way too deep. You should lose one HT at the beginning from all its lines.

> +		case MISSING_OBJECT:
> +			printf("%s missing\n", obj_name);
> +			break;
This one expects that obj_name is always usable as a string.
Show 7 quoted lines
> @@ -455,9 +486,7 @@ static void batch_object_write(const char *obj_name,
>  						       &data->oid, &data->info,
>  						       OBJECT_INFO_LOOKUP_REPLACE);
>  		if (ret < 0) {
> -			printf("%s missing\n",
> -			       obj_name ? obj_name : oid_to_hex(&data->oid));
> -			fflush(stdout);

This caller used to be prepared for the case where obj_name is NULL and used the hexadecimal object name stored in data->oid in such a case, but now ...

> +			batch_print_error(obj_name, MISSING_OBJECT, opt);

... the updated caller assumes that obj_name is always safe to feed to printf("%s") above.

Maybe obj_name is always not-NULL when the control reaches this point in which case the new code would be safe, but if that is the case, the proposed log message should explain how that is true to justify this change.

As batch_object_cb() makes a call to batch_object_write() with obj_name set to NULL, I do not think this change is defensible, though.

Previous: Toon ClaesNext: Junio C Hamano
Message 22 of 32 in “cat-file: quote-format name in error when using -z”
  1. 0/1 cat-file: quote-format name in error when using -zToon Claes, Dec 9, 2022
  2. 1/1 cat-file: quote-format name in error when using -zToon Claes, Dec 9, 2022
  3. Phillip WoodDec 9, 2022
  4. Junio C HamanoDec 9, 2022
  5. Phillip WoodDec 11, 2022
  6. Junio C HamanoDec 12, 2022
  7. Toon ClaesDec 12, 2022
  8. Junio C HamanoDec 12, 2022
  9. Phillip WoodDec 13, 2022
  10. Junio C HamanoDec 14, 2022
  11. Toon ClaesDec 20, 2022
  12. Phillip WoodDec 20, 2022
  13. Toon ClaesDec 21, 2022
  14. 0/1 cat-file: quote-format name in error when using -zToon Claes, Jan 5, 2023
  15. 1/1 cat-file: quote-format name in error when using -zToon Claes, Jan 5, 2023
  16. 0/1 cat-file: quote-format name in error when using -zToon Claes, Jan 16, 2023
  17. 1/1 cat-file: quote-format name in error when using -zToon Claes, Jan 16, 2023
  18. Phillip WoodJan 17, 2023
  19. 0/2 cat-file: quote-format name in error when using -zToon Claes, Mar 3, 2023
  20. 2/2 cat-file: quote-format name in error when using -zToon Claes, Mar 3, 2023
  21. 1/2 cat-file: extract printing batch error message into functionToon Claes, Mar 3, 2023
  22. Junio C HamanoMar 3, 2023
  23. Junio C HamanoMar 3, 2023
  24. 0/1 cat-file: quote-format name in error when using -zToon Claes, May 10, 2023
  25. 1/1 cat-file: quote-format name in error when using -zToon Claes, May 10, 2023
  26. Junio C HamanoMay 10, 2023
  27. Toon ClaesMay 12, 2023
  28. Junio C HamanoMay 12, 2023
  29. Phillip WoodMay 15, 2023
  30. Junio C HamanoMay 15, 2023
  31. Phillip WoodJun 2, 2023
  32. Junio C HamanoMar 3, 2023

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.