diff options
| author | Karthik Nayak <karthik.188@gmail.com> | 2025-05-19 11:58:06 +0200 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-05-19 11:06:31 -0700 |
| commit | b3de3832ce7497d6567d2d8270c829585b9fbf61 (patch) | |
| tree | bdf04d940d9d9236a3d70e447a97a9a21c6f85db /builtin | |
| parent | 1a8a4971cc6c179c4dd711f4a7f5d7178f4b3ab7 (diff) | |
| download | git-b3de3832ce7497d6567d2d8270c829585b9fbf61.tar.xz | |
refs: add function to translate errors to strings
The commit 76e760b999 (refs: introduce enum-based transaction error
types, 2025-04-08) introduced enum-based transaction error types. The
refs transaction logic was also modified to propagate these errors. For
clients of the ref transaction system, it would be beneficial to provide
human readable messages for these errors.
There is already an existing mapping in 'builtin/update-ref.c', move it
to 'refs.c' as `ref_transaction_error_msg()` and use the same within the
'builtin/update-ref.c'.
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
| -rw-r--r-- | builtin/update-ref.c | 25 |
1 files changed, 1 insertions, 24 deletions
diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 2b1e336ba1..1e6131e04a 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -575,30 +575,7 @@ static void print_rejected_refs(const char *refname, void *cb_data UNUSED) { struct strbuf sb = STRBUF_INIT; - 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"; - } + const char *reason = ref_transaction_error_msg(err); strbuf_addf(&sb, "rejected %s %s %s %s\n", refname, new_oid ? oid_to_hex(new_oid) : new_target, |
