677
* - Generate informative error messages in the case of failure
678
*/
679
static enum ref_transaction_error lock_raw_ref(struct files_ref_store *refs,
680
- const char *refname,
680
+ struct ref_update *update,
681
+ size_t update_idx,
682
int mustexist,
683
struct string_list *refnames_to_check,
684
const struct string_list *extras,
685
struct ref_lock **lock_p,
686
struct strbuf *referent,
686
- unsigned int *type,
687
struct strbuf *err)
688
{
689
enum ref_transaction_error ret = REF_TRANSACTION_ERROR_GENERIC;
690
+ const char *refname = update->refname;
691
+ unsigned int *type = &update->type;
692
struct ref_lock *lock;
693
struct strbuf ref_file = STRBUF_INIT;
694
int attempts_remaining = 3;
787
788
if (files_read_raw_ref(&refs->base, refname, &lock->old_oid, referent,
789
type, &failure_errno)) {
790
+ struct string_list_item *item;
791
+
792
if (failure_errno == ENOENT) {
793
if (mustexist) {
794
/* Garden variety missing reference. */
868
* make sure there is no existing packed ref that conflicts
869
* with refname. This check is deferred so that we can batch it.
870
*/
867
- string_list_append(refnames_to_check, refname);
871
+ item = string_list_append(refnames_to_check, refname);
872
+ item->util = xmalloc(sizeof(update_idx));
873
+ memcpy(item->util, &update_idx, sizeof(update_idx));
874
}
875
876
ret = 0;
2553
*/
2554
static enum ref_transaction_error lock_ref_for_update(struct files_ref_store *refs,
2555
struct ref_update *update,
2556
+ size_t update_idx,
2557
struct ref_transaction *transaction,
2558
const char *head_ref,
2559
struct string_list *refnames_to_check,
2582
if (lock) {
2583
lock->count++;
2584
} else {
2578
- ret = lock_raw_ref(refs, update->refname, mustexist,
2585
+ ret = lock_raw_ref(refs, update, update_idx, mustexist,
2586
refnames_to_check, &transaction->refnames,
2580
- &lock, &referent, &update->type, err);
2587
+ &lock, &referent, err);
2588
if (ret) {
2589
char *reason;
2590
2856
for (i = 0; i < transaction->nr; i++) {
2857
struct ref_update *update = transaction->updates[i];
2858
2852
- ret = lock_ref_for_update(refs, update, transaction,
2859
+ ret = lock_ref_for_update(refs, update, i, transaction,
2860
head_ref, &refnames_to_check,
2861
err);
2862
if (ret) {
2912
* So instead, we accept the race for now.
2913
*/
2914
if (refs_verify_refnames_available(refs->packed_ref_store, &refnames_to_check,
2908
- &transaction->refnames, NULL, 0, err)) {
2915
+ &transaction->refnames, NULL, transaction,
2916
+ 0, err)) {
2917
ret = REF_TRANSACTION_ERROR_NAME_CONFLICT;
2918
goto cleanup;
2919
}
2959
2960
cleanup:
2961
free(head_ref);
2954
- string_list_clear(&refnames_to_check, 0);
2962
+ string_list_clear(&refnames_to_check, 1);
2963
2964
if (ret)
2965
files_transaction_cleanup(refs, transaction);
3105
}
3106
3107
if (refs_verify_refnames_available(&refs->base, &refnames_to_check,
3100
- &affected_refnames, NULL, 1, err)) {
3108
+ &affected_refnames, NULL, transaction,
3109
+ 1, err)) {
3110
packed_refs_unlock(refs->packed_ref_store);
3111
ret = REF_TRANSACTION_ERROR_NAME_CONFLICT;
3112
goto cleanup;