mirror of
https://github.com/git/git.git
synced 2026-05-25 11:25:06 +02:00
refs: return ref_transaction_error from ref_transaction_update()
The `ref_transaction_update()` function is used to add updates to a given reference transactions. In the following commit, we'll add more validation to this function. As such, it would be beneficial if the function returns specific error types, so callers can differentiate between different errors. To facilitate this, return `enum ref_transaction_error` from the function and covert the existing '-1' returns to 'REF_TRANSACTION_ERROR_GENERIC'. Since this retains the existing behavior, no changes are made to any of the callers but this sets the necessary infrastructure for introduction of other errors. Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
cc42c88945
commit
e99e98e600
@@ -1383,25 +1383,25 @@ static int transaction_refname_valid(const char *refname,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ref_transaction_update(struct ref_transaction *transaction,
|
||||
const char *refname,
|
||||
const struct object_id *new_oid,
|
||||
const struct object_id *old_oid,
|
||||
const char *new_target,
|
||||
const char *old_target,
|
||||
unsigned int flags, const char *msg,
|
||||
struct strbuf *err)
|
||||
enum ref_transaction_error ref_transaction_update(struct ref_transaction *transaction,
|
||||
const char *refname,
|
||||
const struct object_id *new_oid,
|
||||
const struct object_id *old_oid,
|
||||
const char *new_target,
|
||||
const char *old_target,
|
||||
unsigned int flags, const char *msg,
|
||||
struct strbuf *err)
|
||||
{
|
||||
assert(err);
|
||||
|
||||
if ((flags & REF_FORCE_CREATE_REFLOG) &&
|
||||
(flags & REF_SKIP_CREATE_REFLOG)) {
|
||||
strbuf_addstr(err, _("refusing to force and skip creation of reflog"));
|
||||
return -1;
|
||||
return REF_TRANSACTION_ERROR_GENERIC;
|
||||
}
|
||||
|
||||
if (!transaction_refname_valid(refname, new_oid, flags, err))
|
||||
return -1;
|
||||
return REF_TRANSACTION_ERROR_GENERIC;
|
||||
|
||||
if (flags & ~REF_TRANSACTION_UPDATE_ALLOWED_FLAGS)
|
||||
BUG("illegal flags 0x%x passed to ref_transaction_update()", flags);
|
||||
|
||||
@@ -905,14 +905,14 @@ struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
|
||||
* See the above comment "Reference transaction updates" for more
|
||||
* information.
|
||||
*/
|
||||
int ref_transaction_update(struct ref_transaction *transaction,
|
||||
const char *refname,
|
||||
const struct object_id *new_oid,
|
||||
const struct object_id *old_oid,
|
||||
const char *new_target,
|
||||
const char *old_target,
|
||||
unsigned int flags, const char *msg,
|
||||
struct strbuf *err);
|
||||
enum ref_transaction_error ref_transaction_update(struct ref_transaction *transaction,
|
||||
const char *refname,
|
||||
const struct object_id *new_oid,
|
||||
const struct object_id *old_oid,
|
||||
const char *new_target,
|
||||
const char *old_target,
|
||||
unsigned int flags, const char *msg,
|
||||
struct strbuf *err);
|
||||
|
||||
/*
|
||||
* Similar to `ref_transaction_update`, but this function is only for adding
|
||||
|
||||
Reference in New Issue
Block a user