From: Karthik Nayak Date: Fri, 16 May 2025 09:12:36 GMT Subject: Re: [PATCH v2 1/4] refs: add function to translate errors to strings Message-ID: In-Reply-To: Junio C Hamano writes: [snip] >> +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); >> +} > > Why can't this return "const char *", without xstrdup()? Yeah I think that is much better, string literals are anyways not on the stack and can be passed around. Will change, this would make it much simpler.