Do basic error checking in ref_transaction_create() and make it return status. Update all callers to check the result of ref_transaction_create() Signed-off-by: Ronnie Sahlberg <sahlberg@xxxxxxxxxx> --- builtin/update-ref.c | 4 +++- refs.c | 17 +++++++++++------ refs.h | 8 ++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 13d094d..5f7dfc1 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -225,7 +225,9 @@ static const char *parse_cmd_create(struct strbuf *input, const char *next) if (*next != line_termination) die("create %s: extra input: %s", refname, next); - ref_transaction_create(transaction, refname, new_sha1, update_flags); + if (ref_transaction_create(transaction, refname, new_sha1, + update_flags)) + die("failed transaction create for %s", refname); update_flags = 0; free(refname); diff --git a/refs.c b/refs.c index 65cf407..762be85 100644 --- a/refs.c +++ b/refs.c @@ -3354,18 +3354,23 @@ int ref_transaction_update(struct ref_transaction *transaction, return 0; } -void ref_transaction_create(struct ref_transaction *transaction, - const char *refname, - const unsigned char *new_sha1, - int flags) +int ref_transaction_create(struct ref_transaction *transaction, + const char *refname, + const unsigned char *new_sha1, + int flags) { - struct ref_update *update = add_update(transaction, refname); + struct ref_update *update; + + if (!new_sha1 || is_null_sha1(new_sha1)) + die("create ref with null new_sha1"); + + update = add_update(transaction, refname); - assert(!is_null_sha1(new_sha1)); hashcpy(update->new_sha1, new_sha1); hashclr(update->old_sha1); update->flags = flags; update->have_old = 1; + return 0; } void ref_transaction_delete(struct ref_transaction *transaction, diff --git a/refs.h b/refs.h index 6a361d7..e984267 100644 --- a/refs.h +++ b/refs.h @@ -249,10 +249,10 @@ int ref_transaction_update(struct ref_transaction *transaction, * null SHA-1. It is verified that the reference does not exist * already. */ -void ref_transaction_create(struct ref_transaction *transaction, - const char *refname, - const unsigned char *new_sha1, - int flags); +int ref_transaction_create(struct ref_transaction *transaction, + const char *refname, + const unsigned char *new_sha1, + int flags); /* * Add a reference deletion to transaction. If have_old is true, then -- 1.9.1.521.g5dc89fa -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html