refs.c: make ref_update_reject_duplicates take a strbuf argument for errors
Make ref_update_reject_duplicates return any error that occurs through a new strbuf argument. This means that when a transaction commit fails in this function we will now be able to pass a helpful error message back to the caller. Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Michael Haggerty <mhagger@alum.mit.edu>
Ronnie Sahlberg committed
Jun 20, 2014 at 07:42 UTC
038d005129467a514189e8cc1321022f71f6a51e
1 file changed
+5
-1
refs.c
+5
-1
@@ -3488,6 +3488,7 @@ static int ref_update_compare(const void *r1, const void *r2)
3488
}
3489
3490
static int ref_update_reject_duplicates(struct ref_update **updates, int n,
3491
+ struct strbuf *err,
3492
enum action_on_err onerr)
3493
{
3494
int i;
@@ -3495,6 +3496,9 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n,
3496
if (!strcmp(updates[i - 1]->refname, updates[i]->refname)) {
3497
const char *str =
3498
"Multiple updates for ref '%s' not allowed.";
3499
+ if (err)
3500
+ strbuf_addf(err, str, updates[i]->refname);
3501
+
3502
switch (onerr) {
3503
case UPDATE_REFS_MSG_ON_ERR:
3504
error(str, updates[i]->refname); break;
@@ -3525,7 +3529,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3529
3530
/* Copy, sort, and reject duplicate refs */
3531
qsort(updates, n, sizeof(*updates), ref_update_compare);
3528
- ret = ref_update_reject_duplicates(updates, n, onerr);
3532
+ ret = ref_update_reject_duplicates(updates, n, err, onerr);
3533
if (ret)
3534
goto cleanup;
3535