initial_ref_transaction_commit(): check for duplicate refs
Error out if the ref_transaction includes more than one update for any refname. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Jun 22, 2015 at 16:03 UTC
fb802b312961f49d0aa35f50e72a9a2d17fde9aa
1 file changed
+11
refs.c
+11
@@ -4099,12 +4099,22 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
4099
int ret = 0, i;
4100
int n = transaction->nr;
4101
struct ref_update **updates = transaction->updates;
4102
+ struct string_list affected_refnames = STRING_LIST_INIT_NODUP;
4103
4104
assert(err);
4105
4106
if (transaction->state != REF_TRANSACTION_OPEN)
4107
die("BUG: commit called for transaction that is not open");
4108
4109
+ /* Fail if a refname appears more than once in the transaction: */
4110
+ for (i = 0; i < n; i++)
4111
+ string_list_append(&affected_refnames, updates[i]->refname);
4112
+ string_list_sort(&affected_refnames);
4113
+ if (ref_update_reject_duplicates(&affected_refnames, err)) {
4114
+ ret = TRANSACTION_GENERIC_ERROR;
4115
+ goto cleanup;
4116
+ }
4117
+
4118
for (i = 0; i < n; i++) {
4119
struct ref_update *update = updates[i];
4120
@@ -4137,6 +4147,7 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
4147
4148
cleanup:
4149
transaction->state = REF_TRANSACTION_CLOSED;
4150
+ string_list_clear(&affected_refnames, 0);
4151
return ret;
4152
}
4153