Skip to content

Commit

Permalink
refs.c: make ref_update_reject_duplicates take a strbuf argument for …
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
Ronnie Sahlberg authored and Junio C Hamano committed Jul 14, 2014
1 parent dc615de commit 038d005
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3488,13 +3488,17 @@ static int ref_update_compare(const void *r1, const void *r2)
}

static int ref_update_reject_duplicates(struct ref_update **updates, int n,
struct strbuf *err,
enum action_on_err onerr)
{
int i;
for (i = 1; i < n; i++)
if (!strcmp(updates[i - 1]->refname, updates[i]->refname)) {
const char *str =
"Multiple updates for ref '%s' not allowed.";
if (err)
strbuf_addf(err, str, updates[i]->refname);

switch (onerr) {
case UPDATE_REFS_MSG_ON_ERR:
error(str, updates[i]->refname); break;
Expand Down Expand Up @@ -3525,7 +3529,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,

/* Copy, sort, and reject duplicate refs */
qsort(updates, n, sizeof(*updates), ref_update_compare);
ret = ref_update_reject_duplicates(updates, n, onerr);
ret = ref_update_reject_duplicates(updates, n, err, onerr);
if (ret)
goto cleanup;

Expand Down

0 comments on commit 038d005

Please sign in to comment.