@@ -279,7 +279,7 @@ struct ref_dir {
279
279
* presence of an empty subdirectory does not block the creation of a
280
280
* similarly-named reference. (The fact that reference names with the
281
281
* same leading components can conflict *with each other* is a
282
- * separate issue that is regulated by verify_refname_available_dir ().)
282
+ * separate issue that is regulated by verify_refname_available ().)
283
283
*
284
284
* Please note that the name field contains the fully-qualified
285
285
* reference (or subdirectory) name. Space could be saved by only
@@ -897,19 +897,7 @@ static int nonmatching_ref_fn(struct ref_entry *entry, void *vdata)
897
897
/*
898
898
* Return 0 if a reference named refname could be created without
899
899
* conflicting with the name of an existing reference in dir.
900
- * Otherwise, return a negative value and write an explanation to err.
901
- * If extras is non-NULL, it is a list of additional refnames with
902
- * which refname is not allowed to conflict. If skip is non-NULL,
903
- * ignore potential conflicts with refs in skip (e.g., because they
904
- * are scheduled for deletion in the same operation). Behavior is
905
- * undefined if the same name is listed in both extras and skip.
906
- *
907
- * Two reference names conflict if one of them exactly matches the
908
- * leading components of the other; e.g., "refs/foo/bar" conflicts
909
- * with both "refs/foo" and with "refs/foo/bar/baz" but not with
910
- * "refs/foo/bar" or "refs/foo/barbados".
911
- *
912
- * extras and skip must be sorted.
900
+ * See verify_refname_available for more information.
913
901
*/
914
902
static int verify_refname_available_dir (const char * refname ,
915
903
const struct string_list * extras ,
@@ -3120,17 +3108,48 @@ static int rename_tmp_log(const char *newrefname)
3120
3108
return ret ;
3121
3109
}
3122
3110
3111
+ /*
3112
+ * Return 0 if a reference named refname could be created without
3113
+ * conflicting with the name of an existing reference. Otherwise,
3114
+ * return a negative value and write an explanation to err. If extras
3115
+ * is non-NULL, it is a list of additional refnames with which refname
3116
+ * is not allowed to conflict. If skip is non-NULL, ignore potential
3117
+ * conflicts with refs in skip (e.g., because they are scheduled for
3118
+ * deletion in the same operation). Behavior is undefined if the same
3119
+ * name is listed in both extras and skip.
3120
+ *
3121
+ * Two reference names conflict if one of them exactly matches the
3122
+ * leading components of the other; e.g., "foo/bar" conflicts with
3123
+ * both "foo" and with "foo/bar/baz" but not with "foo/bar" or
3124
+ * "foo/barbados".
3125
+ *
3126
+ * extras and skip must be sorted.
3127
+ */
3128
+ static int verify_refname_available (const char * newname ,
3129
+ struct string_list * extras ,
3130
+ struct string_list * skip ,
3131
+ struct strbuf * err )
3132
+ {
3133
+ struct ref_dir * packed_refs = get_packed_refs (& ref_cache );
3134
+ struct ref_dir * loose_refs = get_loose_refs (& ref_cache );
3135
+
3136
+ if (verify_refname_available_dir (newname , extras , skip ,
3137
+ packed_refs , err ) ||
3138
+ verify_refname_available_dir (newname , extras , skip ,
3139
+ loose_refs , err ))
3140
+ return -1 ;
3141
+
3142
+ return 0 ;
3143
+ }
3144
+
3123
3145
static int rename_ref_available (const char * oldname , const char * newname )
3124
3146
{
3125
3147
struct string_list skip = STRING_LIST_INIT_NODUP ;
3126
3148
struct strbuf err = STRBUF_INIT ;
3127
3149
int ret ;
3128
3150
3129
3151
string_list_insert (& skip , oldname );
3130
- ret = !verify_refname_available_dir (newname , NULL , & skip ,
3131
- get_packed_refs (& ref_cache ), & err )
3132
- && !verify_refname_available_dir (newname , NULL , & skip ,
3133
- get_loose_refs (& ref_cache ), & err );
3152
+ ret = !verify_refname_available (newname , NULL , & skip , & err );
3134
3153
if (!ret )
3135
3154
error ("%s" , err .buf );
3136
3155
@@ -4334,8 +4353,6 @@ static int ref_present(const char *refname,
4334
4353
int initial_ref_transaction_commit (struct ref_transaction * transaction ,
4335
4354
struct strbuf * err )
4336
4355
{
4337
- struct ref_dir * loose_refs = get_loose_refs (& ref_cache );
4338
- struct ref_dir * packed_refs = get_packed_refs (& ref_cache );
4339
4356
int ret = 0 , i ;
4340
4357
int n = transaction -> nr ;
4341
4358
struct ref_update * * updates = transaction -> updates ;
@@ -4376,12 +4393,9 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
4376
4393
if ((update -> flags & REF_HAVE_OLD ) &&
4377
4394
!is_null_sha1 (update -> old_sha1 ))
4378
4395
die ("BUG: initial ref transaction with old_sha1 set" );
4379
- if (verify_refname_available_dir (update -> refname ,
4380
- & affected_refnames , NULL ,
4381
- loose_refs , err ) ||
4382
- verify_refname_available_dir (update -> refname ,
4383
- & affected_refnames , NULL ,
4384
- packed_refs , err )) {
4396
+ if (verify_refname_available (update -> refname ,
4397
+ & affected_refnames , NULL ,
4398
+ err )) {
4385
4399
ret = TRANSACTION_NAME_CONFLICT ;
4386
4400
goto cleanup ;
4387
4401
}
0 commit comments