@@ -919,7 +919,7 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,
919919 struct ref_transaction * transaction ;
920920 struct strbuf err = STRBUF_INIT ;
921921
922- transaction = ref_store_transaction_begin (refs , & err );
922+ transaction = ref_store_transaction_begin (refs , 0 , & err );
923923 if (!transaction ||
924924 ref_transaction_delete (transaction , refname , old_oid ,
925925 NULL , flags , msg , & err ) ||
@@ -1117,13 +1117,15 @@ int read_ref_at(struct ref_store *refs, const char *refname,
11171117}
11181118
11191119struct ref_transaction * ref_store_transaction_begin (struct ref_store * refs ,
1120+ unsigned int flags ,
11201121 struct strbuf * err )
11211122{
11221123 struct ref_transaction * tr ;
11231124 assert (err );
11241125
11251126 CALLOC_ARRAY (tr , 1 );
11261127 tr -> ref_store = refs ;
1128+ tr -> flags = flags ;
11271129 return tr ;
11281130}
11291131
@@ -1187,8 +1189,9 @@ struct ref_update *ref_transaction_add_update(
11871189 oidcpy (& update -> new_oid , new_oid );
11881190 if ((flags & REF_HAVE_OLD ) && old_oid )
11891191 oidcpy (& update -> old_oid , old_oid );
1192+ if (!(flags & REF_SKIP_CREATE_REFLOG ))
1193+ update -> msg = normalize_reflog_message (msg );
11901194
1191- update -> msg = normalize_reflog_message (msg );
11921195 return update ;
11931196}
11941197
@@ -1310,7 +1313,7 @@ int refs_update_ref(struct ref_store *refs, const char *msg,
13101313 struct strbuf err = STRBUF_INIT ;
13111314 int ret = 0 ;
13121315
1313- t = ref_store_transaction_begin (refs , & err );
1316+ t = ref_store_transaction_begin (refs , 0 , & err );
13141317 if (!t ||
13151318 ref_transaction_update (t , refname , new_oid , old_oid , NULL , NULL ,
13161319 flags , msg , & err ) ||
@@ -2128,7 +2131,7 @@ int refs_update_symref_extended(struct ref_store *refs, const char *ref,
21282131 struct strbuf err = STRBUF_INIT ;
21292132 int ret = 0 , prepret = 0 ;
21302133
2131- transaction = ref_store_transaction_begin (refs , & err );
2134+ transaction = ref_store_transaction_begin (refs , 0 , & err );
21322135 if (!transaction ) {
21332136 error_return :
21342137 ret = error ("%s" , err .buf );
@@ -2353,7 +2356,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
23532356 }
23542357
23552358 ret = refs -> be -> transaction_finish (refs , transaction , err );
2356- if (!ret )
2359+ if (!ret && !( transaction -> flags & REF_TRANSACTION_FLAG_INITIAL ) )
23572360 run_transaction_hook (transaction , "committed" );
23582361 return ret ;
23592362}
@@ -2362,6 +2365,7 @@ int refs_verify_refname_available(struct ref_store *refs,
23622365 const char * refname ,
23632366 const struct string_list * extras ,
23642367 const struct string_list * skip ,
2368+ int initial_transaction ,
23652369 struct strbuf * err )
23662370{
23672371 const char * slash ;
@@ -2370,8 +2374,6 @@ int refs_verify_refname_available(struct ref_store *refs,
23702374 struct strbuf referent = STRBUF_INIT ;
23712375 struct object_id oid ;
23722376 unsigned int type ;
2373- struct ref_iterator * iter ;
2374- int ok ;
23752377 int ret = -1 ;
23762378
23772379 /*
@@ -2401,7 +2403,8 @@ int refs_verify_refname_available(struct ref_store *refs,
24012403 if (skip && string_list_has_string (skip , dirname .buf ))
24022404 continue ;
24032405
2404- if (!refs_read_raw_ref (refs , dirname .buf , & oid , & referent ,
2406+ if (!initial_transaction &&
2407+ !refs_read_raw_ref (refs , dirname .buf , & oid , & referent ,
24052408 & type , & ignore_errno )) {
24062409 strbuf_addf (err , _ ("'%s' exists; cannot create '%s'" ),
24072410 dirname .buf , refname );
@@ -2426,21 +2429,26 @@ int refs_verify_refname_available(struct ref_store *refs,
24262429 strbuf_addstr (& dirname , refname + dirname .len );
24272430 strbuf_addch (& dirname , '/' );
24282431
2429- iter = refs_ref_iterator_begin (refs , dirname .buf , NULL , 0 ,
2430- DO_FOR_EACH_INCLUDE_BROKEN );
2431- while ((ok = ref_iterator_advance (iter )) == ITER_OK ) {
2432- if (skip &&
2433- string_list_has_string (skip , iter -> refname ))
2434- continue ;
2432+ if (!initial_transaction ) {
2433+ struct ref_iterator * iter ;
2434+ int ok ;
24352435
2436- strbuf_addf (err , _ ("'%s' exists; cannot create '%s'" ),
2437- iter -> refname , refname );
2438- ref_iterator_abort (iter );
2439- goto cleanup ;
2440- }
2436+ iter = refs_ref_iterator_begin (refs , dirname .buf , NULL , 0 ,
2437+ DO_FOR_EACH_INCLUDE_BROKEN );
2438+ while ((ok = ref_iterator_advance (iter )) == ITER_OK ) {
2439+ if (skip &&
2440+ string_list_has_string (skip , iter -> refname ))
2441+ continue ;
24412442
2442- if (ok != ITER_DONE )
2443- BUG ("error while iterating over references" );
2443+ strbuf_addf (err , _ ("'%s' exists; cannot create '%s'" ),
2444+ iter -> refname , refname );
2445+ ref_iterator_abort (iter );
2446+ goto cleanup ;
2447+ }
2448+
2449+ if (ok != ITER_DONE )
2450+ BUG ("error while iterating over references" );
2451+ }
24442452
24452453 extra_refname = find_descendant_ref (dirname .buf , extras , skip );
24462454 if (extra_refname )
@@ -2524,14 +2532,6 @@ int refs_reflog_expire(struct ref_store *refs,
25242532 cleanup_fn , policy_cb_data );
25252533}
25262534
2527- int initial_ref_transaction_commit (struct ref_transaction * transaction ,
2528- struct strbuf * err )
2529- {
2530- struct ref_store * refs = transaction -> ref_store ;
2531-
2532- return refs -> be -> initial_transaction_commit (refs , transaction , err );
2533- }
2534-
25352535void ref_transaction_for_each_queued_update (struct ref_transaction * transaction ,
25362536 ref_transaction_for_each_queued_update_fn cb ,
25372537 void * cb_data )
@@ -2567,7 +2567,7 @@ int refs_delete_refs(struct ref_store *refs, const char *logmsg,
25672567 * individual updates can't fail, so we can pack all of the
25682568 * updates into a single transaction.
25692569 */
2570- transaction = ref_store_transaction_begin (refs , & err );
2570+ transaction = ref_store_transaction_begin (refs , 0 , & err );
25712571 if (!transaction ) {
25722572 ret = error ("%s" , err .buf );
25732573 goto out ;
@@ -2873,7 +2873,8 @@ int repo_migrate_ref_storage_format(struct repository *repo,
28732873 if (ret < 0 )
28742874 goto done ;
28752875
2876- transaction = ref_store_transaction_begin (new_refs , errbuf );
2876+ transaction = ref_store_transaction_begin (new_refs , REF_TRANSACTION_FLAG_INITIAL ,
2877+ errbuf );
28772878 if (!transaction )
28782879 goto done ;
28792880
@@ -2898,13 +2899,6 @@ int repo_migrate_ref_storage_format(struct repository *repo,
28982899 if (ret < 0 )
28992900 goto done ;
29002901
2901- /*
2902- * TODO: we might want to migrate to `initial_ref_transaction_commit()`
2903- * here, which is more efficient for the files backend because it would
2904- * write new refs into the packed-refs file directly. At this point,
2905- * the files backend doesn't handle pseudo-refs and symrefs correctly
2906- * though, so this requires some more work.
2907- */
29082902 ret = ref_transaction_commit (transaction , errbuf );
29092903 if (ret < 0 )
29102904 goto done ;
0 commit comments