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

Re: [PATCH v2 1/4] refs: add function to translate errors to strings

From
Karthik Nayak <karthik.188@gmail.com>
Date
May 16, 2025, 09:11 UTC
Message-ID
<CAOLa=ZQHR5Xt3yP4FM4gAbFVRM-dXVPpQHS0tObeoz45T89X7w@mail.gmail.com>
In-Reply-To
<20250515191153.GB3309052@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 36 quoted lines
> On Thu, May 15, 2025 at 04:07:25PM +0200, Karthik Nayak wrote:
>
>> +char *ref_transaction_error_msg(enum ref_transaction_error err)
>> +{
>> +	const char *reason = "";
>> +
>> +	switch (err) {
>> +	case REF_TRANSACTION_ERROR_NAME_CONFLICT:
>> +		reason = "refname conflict";
>> +		break;
>> +	case REF_TRANSACTION_ERROR_CREATE_EXISTS:
>> +		reason = "reference already exists";
>> +		break;
>> +	case REF_TRANSACTION_ERROR_NONEXISTENT_REF:
>> +		reason = "reference does not exist";
>> +		break;
>> +	case REF_TRANSACTION_ERROR_INCORRECT_OLD_VALUE:
>> +		reason = "incorrect old value provided";
>> +		break;
>> +	case REF_TRANSACTION_ERROR_INVALID_NEW_VALUE:
>> +		reason = "invalid new value provided";
>> +		break;
>> +	case REF_TRANSACTION_ERROR_EXPECTED_SYMREF:
>> +		reason = "expected symref but found regular ref";
>> +		break;
>> +	default:
>> +		reason = "unkown failure";
>> +	}
>> +
>> +	return xstrdup(reason);
>> +}
>
> The assignment of "" is dead code, I think? We will always assign
> "unknown failure" as a last resort. Not a big deal, but just something I
> noticed while reading this related to what's going on in patch 4.
>

Yeah, I mostly moved the code without much thought into it. This can be cleaned up. Specifically because we can avoid all the memory allocation and directly return the string as a 'const char *' as Junio mentioned.

> Also, s/unkown/unknown/, but that is present in the pre-image. I hope we
> don't need to retain it for bug-for-bug plumbing compatibility. :)
>
Thanks, will change.
Show 8 quoted lines
> (I guess the dead store of "" was present in the original, too, for that
> matter).
>
> -Peff
>
> PS Sorry for all the nit-picky comments. I was just going down the
>    Coverity rabbit hole and didn't really review the rest of the series.
>    But I wanted to say that the numbers you are seeing are very cool!
I think all these points have good value. I'm happy to address them :)
Previous: Jeff KingNext: Junio C Hamano
Message 18 of 30 in “fetch/receive: use batched reference updates”
  1. 0/3 fetch/receive: use batched reference updatesKarthik Nayak, May 14, 2025
  2. 1/3 fetch: use batched reference updatesKarthik Nayak, May 14, 2025
  3. Patrick SteinhardtMay 14, 2025
  4. Karthik NayakMay 15, 2025
  5. Patrick SteinhardtMay 15, 2025
  6. Karthik NayakMay 15, 2025
  7. Junio C HamanoMay 14, 2025
  8. 3/3 receive-pack: use batched reference updatesKarthik Nayak, May 14, 2025
  9. Patrick SteinhardtMay 14, 2025
  10. Junio C HamanoMay 14, 2025
  11. Karthik NayakMay 15, 2025
  12. 2/3 send-pack: fix memory leak around duplicate refsKarthik Nayak, May 14, 2025
  13. Junio C HamanoMay 14, 2025
  14. Karthik NayakMay 15, 2025
  15. 0/4 fetch/receive: use batched reference updatesKarthik Nayak, May 15, 2025
  16. 1/4 refs: add function to translate errors to stringsKarthik Nayak, May 15, 2025
  17. Jeff KingMay 15, 2025
  18. Karthik NayakMay 16, 2025
  19. Junio C HamanoMay 15, 2025
  20. Karthik NayakMay 16, 2025
  21. 2/4 fetch: use batched reference updatesKarthik Nayak, May 15, 2025
  22. Patrick SteinhardtMay 16, 2025
  23. Karthik NayakMay 16, 2025
  24. Patrick SteinhardtMay 16, 2025
  25. Karthik NayakMay 18, 2025
  26. 3/4 send-pack: fix memory leak around duplicate refsKarthik Nayak, May 15, 2025
  27. 4/4 receive-pack: use batched reference updatesKarthik Nayak, May 15, 2025
  28. Jeff KingMay 15, 2025
  29. Jeff KingMay 15, 2025
  30. Karthik NayakMay 16, 2025

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.