refs.c: update ref_transaction_delete to check for error and return status
Change ref_transaction_delete() to do basic error checking and return non-zero on error. Update all callers to check the return for ref_transaction_delete(). There are currently no conditions in _delete that will return error but there will be in the future. Add an err argument that will be updated on failure. Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ronnie Sahlberg committed
Apr 16, 2014 at 15:27 UTC
8c8bdc0d3582e42c13815a191344b1aa3e06c792
3 files changed
+22
-11
builtin/update-ref.c
+3
-2
@@ -258,8 +258,9 @@ static const char *parse_cmd_delete(struct strbuf *input, const char *next)
258
if (*next != line_termination)
259
die("delete %s: extra input: %s", refname, next);
260
261
- ref_transaction_delete(transaction, refname, old_sha1,
262
- update_flags, have_old);
261
+ if (ref_transaction_delete(transaction, refname, old_sha1,
262
+ update_flags, have_old, &err))
263
+ die("%s", err.buf);
264
265
update_flags = 0;
266
free(refname);
refs.c
+11
-5
@@ -3469,19 +3469,25 @@ int ref_transaction_create(struct ref_transaction *transaction,
3469
return 0;
3470
}
3471
3472
-void ref_transaction_delete(struct ref_transaction *transaction,
3473
- const char *refname,
3474
- const unsigned char *old_sha1,
3475
- int flags, int have_old)
3472
+int ref_transaction_delete(struct ref_transaction *transaction,
3473
+ const char *refname,
3474
+ const unsigned char *old_sha1,
3475
+ int flags, int have_old,
3476
+ struct strbuf *err)
3477
{
3477
- struct ref_update *update = add_update(transaction, refname);
3478
+ struct ref_update *update;
3479
3480
+ if (have_old && !old_sha1)
3481
+ die("BUG: have_old is true but old_sha1 is NULL");
3482
+
3483
+ update = add_update(transaction, refname);
3484
update->flags = flags;
3485
update->have_old = have_old;
3486
if (have_old) {
3487
assert(!is_null_sha1(old_sha1));
3488
hashcpy(update->old_sha1, old_sha1);
3489
}
3490
+ return 0;
3491
}
3492
3493
int update_ref(const char *action, const char *refname,
refs.h
+8
-4
@@ -308,11 +308,15 @@ int ref_transaction_create(struct ref_transaction *transaction,
308
* Add a reference deletion to transaction. If have_old is true, then
309
* old_sha1 holds the value that the reference should have had before
310
* the update (which must not be the null SHA-1).
311
+ * Function returns 0 on success and non-zero on failure. A failure to delete
312
+ * means that the transaction as a whole has failed and will need to be
313
+ * rolled back.
314
*/
312
-void ref_transaction_delete(struct ref_transaction *transaction,
313
- const char *refname,
314
- const unsigned char *old_sha1,
315
- int flags, int have_old);
315
+int ref_transaction_delete(struct ref_transaction *transaction,
316
+ const char *refname,
317
+ const unsigned char *old_sha1,
318
+ int flags, int have_old,
319
+ struct strbuf *err);
320
321
/*
322
* Commit all of the changes that have been queued in transaction, as