On 04/17/2014 09:46 PM, Ronnie Sahlberg wrote:
> Change ref_transaction_delete() to do basic error checking and return
> status. Update all callers to check the return for ref_transaction_delete()
>
> Signed-off-by: Ronnie Sahlberg
> ---
> builtin/update-ref.c | 5 +++--
> refs.c | 15 ++-
> refs.h | 8
> 3 files changed, 17 insertions(+), 11 deletions(-)
>
> diff --git a/builtin/update-ref.c b/builtin/update-ref.c
> index 1b8a087..6ff8b86 100644
> --- a/builtin/update-ref.c
> +++ b/builtin/update-ref.c
> @@ -258,8 +258,9 @@ static const char *parse_cmd_delete(struct strbuf *input,
> const char *next)
> if (*next != line_termination)
> die("delete %s: extra input: %s", refname, next);
>
> - ref_transaction_delete(transaction, refname, old_sha1,
> -update_flags, have_old);
> + if (ref_transaction_delete(transaction, refname, old_sha1,
> +update_flags, have_old))
> + die("failed transaction delete for %s", refname);
>
> update_flags = 0;
> free(refname);
> diff --git a/refs.c b/refs.c
> index c46249f..9cbcffa 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -3366,19 +3366,24 @@ int ref_transaction_create(struct ref_transaction
> *transaction,
> return 0;
> }
>
> -void ref_transaction_delete(struct ref_transaction *transaction,
> - const char *refname,
> - const unsigned char *old_sha1,
> - int flags, int have_old)
> +int ref_transaction_delete(struct ref_transaction *transaction,
> +const char *refname,
> +const unsigned char *old_sha1,
> +int flags, int have_old)
> {
> - struct ref_update *update = add_update(transaction, refname);
> + struct ref_update *update;
>
> + if (have_old && !old_sha1)
> + return error("have_old is true but old_sha1 is NULL");
Ditto.
> +
> + update = add_update(transaction, refname);
> update->flags = flags;
> update->have_old = have_old;
> if (have_old) {
> assert(!is_null_sha1(old_sha1));
> hashcpy(update->old_sha1, old_sha1);
> }
> + return 0;
> }
>
> int update_ref(const char *action, const char *refname,
> diff --git a/refs.h b/refs.h
> index 8799e15..7050da2 100644
> --- a/refs.h
> +++ b/refs.h
> @@ -259,10 +259,10 @@ int ref_transaction_create(struct ref_transaction
> *transaction,
> * old_sha1 holds the value that the reference should have had before
> * the update (which must not be the null SHA-1).
> */
> -void ref_transaction_delete(struct ref_transaction *transaction,
> - const char *refname,
> - const unsigned char *old_sha1,
> - int flags, int have_old);
> +int ref_transaction_delete(struct ref_transaction *transaction,
> +const char *refname,
> +const unsigned char *old_sha1,
> +int flags, int have_old);
>
> /*
> * Commit all of the changes that have been queued in transaction, as
>
Michael
--
Michael Haggerty
mhag...@alum.mit.edu
http://softwareswirl.blogspot.com/
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html