2378
*/
2379
static int split_head_update(struct ref_update *update,
2380
struct ref_transaction *transaction,
2381
- const char *head_ref,
2382
- struct string_list *affected_refnames,
2383
- struct strbuf *err)
2381
+ const char *head_ref, struct strbuf *err)
2382
{
2383
struct ref_update *new_update;
2384
2396
* transaction. This check is O(lg N) in the transaction
2397
* size, but it happens at most once per transaction.
2398
*/
2401
- if (string_list_has_string(affected_refnames, "HEAD")) {
2399
+ if (string_list_has_string(&transaction->refnames, "HEAD")) {
2400
/* An entry already existed */
2401
strbuf_addf(err,
2402
"multiple updates for 'HEAD' (including one "
2418
*/
2419
if (strcmp(new_update->refname, "HEAD"))
2420
BUG("%s unexpectedly not 'HEAD'", new_update->refname);
2423
- string_list_insert(affected_refnames, new_update->refname);
2421
2422
return 0;
2423
}
2433
static int split_symref_update(struct ref_update *update,
2434
const char *referent,
2435
struct ref_transaction *transaction,
2439
- struct string_list *affected_refnames,
2436
struct strbuf *err)
2437
{
2438
struct ref_update *new_update;
2444
* size, but it happens at most once per symref in a
2445
* transaction.
2446
*/
2451
- if (string_list_has_string(affected_refnames, referent)) {
2447
+ if (string_list_has_string(&transaction->refnames, referent)) {
2448
/* An entry already exists */
2449
strbuf_addf(err,
2450
"multiple updates for '%s' (including one "
2482
update->flags |= REF_LOG_ONLY | REF_NO_DEREF;
2483
update->flags &= ~REF_HAVE_OLD;
2484
2489
- /*
2490
- * Add the referent. This insertion is O(N) in the transaction
2491
- * size, but it happens at most once per symref in a
2492
- * transaction. Make sure to add new_update->refname, which will
2493
- * be valid as long as affected_refnames is in use, and NOT
2494
- * referent, which might soon be freed by our caller.
2495
- */
2496
- string_list_insert(affected_refnames, new_update->refname);
2497
-
2485
return 0;
2486
}
2487
2545
struct ref_transaction *transaction,
2546
const char *head_ref,
2547
struct string_list *refnames_to_check,
2561
- struct string_list *affected_refnames,
2548
struct strbuf *err)
2549
{
2550
struct strbuf referent = STRBUF_INIT;
2561
update->flags |= REF_DELETING;
2562
2563
if (head_ref) {
2578
- ret = split_head_update(update, transaction, head_ref,
2579
- affected_refnames, err);
2564
+ ret = split_head_update(update, transaction, head_ref, err);
2565
if (ret)
2566
goto out;
2567
}
2571
lock->count++;
2572
} else {
2573
ret = lock_raw_ref(refs, update->refname, mustexist,
2589
- refnames_to_check, affected_refnames,
2590
- &lock, &referent,
2591
- &update->type, err);
2574
+ refnames_to_check, &transaction->refnames,
2575
+ &lock, &referent, &update->type, err);
2576
if (ret) {
2577
char *reason;
2578
2626
* of processing the split-off update, so we
2627
* don't have to do it here.
2628
*/
2645
- ret = split_symref_update(update,
2646
- referent.buf, transaction,
2647
- affected_refnames, err);
2629
+ ret = split_symref_update(update, referent.buf,
2630
+ transaction, err);
2631
if (ret)
2632
goto out;
2633
}
2782
"ref_transaction_prepare");
2783
size_t i;
2784
int ret = 0;
2802
- struct string_list affected_refnames = STRING_LIST_INIT_NODUP;
2785
struct string_list refnames_to_check = STRING_LIST_INIT_NODUP;
2786
char *head_ref = NULL;
2787
int head_type;
2800
transaction->backend_data = backend_data;
2801
2802
/*
2821
- * Fail if a refname appears more than once in the
2822
- * transaction. (If we end up splitting up any updates using
2823
- * split_symref_update() or split_head_update(), those
2824
- * functions will check that the new updates don't have the
2825
- * same refname as any existing ones.) Also fail if any of the
2826
- * updates use REF_IS_PRUNING without REF_NO_DEREF.
2803
+ * Fail if any of the updates use REF_IS_PRUNING without REF_NO_DEREF.
2804
*/
2805
for (i = 0; i < transaction->nr; i++) {
2806
struct ref_update *update = transaction->updates[i];
2808
if ((update->flags & REF_IS_PRUNING) &&
2809
!(update->flags & REF_NO_DEREF))
2810
BUG("REF_IS_PRUNING set without REF_NO_DEREF");
2834
-
2835
- if (update->flags & REF_LOG_ONLY)
2836
- continue;
2837
-
2838
- string_list_append(&affected_refnames, update->refname);
2839
- }
2840
- string_list_sort(&affected_refnames);
2841
- if (ref_update_reject_duplicates(&affected_refnames, err)) {
2842
- ret = TRANSACTION_GENERIC_ERROR;
2843
- goto cleanup;
2811
}
2812
2813
/*
2849
2850
ret = lock_ref_for_update(refs, update, transaction,
2851
head_ref, &refnames_to_check,
2885
- &affected_refnames, err);
2852
+ err);
2853
if (ret)
2854
goto cleanup;
2855
2896
* So instead, we accept the race for now.
2897
*/
2898
if (refs_verify_refnames_available(refs->packed_ref_store, &refnames_to_check,
2932
- &affected_refnames, NULL, 0, err)) {
2899
+ &transaction->refnames, NULL, 0, err)) {
2900
ret = TRANSACTION_NAME_CONFLICT;
2901
goto cleanup;
2902
}
2942
2943
cleanup:
2944
free(head_ref);
2978
- string_list_clear(&affected_refnames, 0);
2945
string_list_clear(&refnames_to_check, 0);
2946
2947
if (ret)
3016
if (transaction->state != REF_TRANSACTION_PREPARED)
3017
BUG("commit called for transaction that is not prepared");
3018
3053
- /* Fail if a refname appears more than once in the transaction: */
3054
- for (i = 0; i < transaction->nr; i++)
3055
- if (!(transaction->updates[i]->flags & REF_LOG_ONLY))
3056
- string_list_append(&affected_refnames,
3057
- transaction->updates[i]->refname);
3058
- string_list_sort(&affected_refnames);
3059
- if (ref_update_reject_duplicates(&affected_refnames, err)) {
3019
+ string_list_sort(&transaction->refnames);
3020
+ if (ref_update_reject_duplicates(&transaction->refnames, err)) {
3021
ret = TRANSACTION_GENERIC_ERROR;
3022
goto cleanup;
3023
}
3035
* that we are creating already exists.
3036
*/
3037
if (refs_for_each_rawref(&refs->base, ref_present,
3077
- &affected_refnames))
3038
+ &transaction->refnames))
3039
BUG("initial ref transaction called with existing refs");
3040
3041
packed_transaction = ref_store_transaction_begin(refs->packed_ref_store,