[PATCH v16 15/48] refs.c: make ref_update_reject_duplicates take a strbuf argument for errors
- From
Ronnie Sahlberg <sahlberg@google.com>
- Date
- Jun 12, 2014, 17:21 UTC
- Message-ID
- <1402593699-13983-16-git-send-email-sahlberg@google.com>
- In-Reply-To
- <1402593699-13983-1-git-send-email-sahlberg@google.com>
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> --- refs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/refs.c b/refs.c index 31ae63e..81d3605 100644 --- a/refs.c +++ b/refs.c @@ -3463,6 +3463,7 @@ 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; @@ -3470,6 +3471,9 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n, 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; @@ -3500,7 +3504,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;
-- 2.0.0.599.g83ced0e