@@ -1180,6 +1180,18 @@ static void files_reflog_path(struct files_ref_store *refs,
1180
1180
strbuf_git_path (sb , "logs/%s" , refname );
1181
1181
}
1182
1182
1183
+ static void files_ref_path (struct files_ref_store * refs ,
1184
+ struct strbuf * sb ,
1185
+ const char * refname )
1186
+ {
1187
+ if (refs -> submodule ) {
1188
+ strbuf_git_path_submodule (sb , refs -> submodule , "%s" , refname );
1189
+ return ;
1190
+ }
1191
+
1192
+ strbuf_git_path (sb , "%s" , refname );
1193
+ }
1194
+
1183
1195
/*
1184
1196
* Get the packed_ref_cache for the specified files_ref_store,
1185
1197
* creating it if necessary.
@@ -1249,19 +1261,10 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
1249
1261
struct strbuf refname ;
1250
1262
struct strbuf path = STRBUF_INIT ;
1251
1263
size_t path_baselen ;
1252
- int err = 0 ;
1253
1264
1254
- if (refs -> submodule )
1255
- err = strbuf_git_path_submodule (& path , refs -> submodule , "%s" , dirname );
1256
- else
1257
- strbuf_git_path (& path , "%s" , dirname );
1265
+ files_ref_path (refs , & path , dirname );
1258
1266
path_baselen = path .len ;
1259
1267
1260
- if (err ) {
1261
- strbuf_release (& path );
1262
- return ;
1263
- }
1264
-
1265
1268
d = opendir (path .buf );
1266
1269
if (!d ) {
1267
1270
strbuf_release (& path );
@@ -1396,10 +1399,7 @@ static int files_read_raw_ref(struct ref_store *ref_store,
1396
1399
* type = 0 ;
1397
1400
strbuf_reset (& sb_path );
1398
1401
1399
- if (refs -> submodule )
1400
- strbuf_git_path_submodule (& sb_path , refs -> submodule , "%s" , refname );
1401
- else
1402
- strbuf_git_path (& sb_path , "%s" , refname );
1402
+ files_ref_path (refs , & sb_path , refname );
1403
1403
1404
1404
path = sb_path .buf ;
1405
1405
@@ -1587,7 +1587,7 @@ static int lock_raw_ref(struct files_ref_store *refs,
1587
1587
* lock_p = lock = xcalloc (1 , sizeof (* lock ));
1588
1588
1589
1589
lock -> ref_name = xstrdup (refname );
1590
- strbuf_git_path ( & ref_file , "%s" , refname );
1590
+ files_ref_path ( refs , & ref_file , refname );
1591
1591
1592
1592
retry :
1593
1593
switch (safe_create_leading_directories (ref_file .buf )) {
@@ -2056,7 +2056,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
2056
2056
if (flags & REF_DELETING )
2057
2057
resolve_flags |= RESOLVE_REF_ALLOW_BAD_NAME ;
2058
2058
2059
- strbuf_git_path ( & ref_file , "%s" , refname );
2059
+ files_ref_path ( refs , & ref_file , refname );
2060
2060
resolved = !!resolve_ref_unsafe (refname , resolve_flags ,
2061
2061
lock -> old_oid .hash , type );
2062
2062
if (!resolved && errno == EISDIR ) {
@@ -2355,7 +2355,7 @@ static void try_remove_empty_parents(struct files_ref_store *refs,
2355
2355
strbuf_setlen (& buf , q - buf .buf );
2356
2356
2357
2357
strbuf_reset (& sb );
2358
- strbuf_git_path ( & sb , "%s" , buf .buf );
2358
+ files_ref_path ( refs , & sb , buf .buf );
2359
2359
if ((flags & REMOVE_EMPTY_PARENTS_REF ) && rmdir (sb .buf ))
2360
2360
flags &= ~REMOVE_EMPTY_PARENTS_REF ;
2361
2361
@@ -2672,7 +2672,7 @@ static int files_rename_ref(struct ref_store *ref_store,
2672
2672
struct strbuf path = STRBUF_INIT ;
2673
2673
int result ;
2674
2674
2675
- strbuf_git_path ( & path , "%s" , newrefname );
2675
+ files_ref_path ( refs , & path , newrefname );
2676
2676
result = remove_empty_directories (& path );
2677
2677
strbuf_release (& path );
2678
2678
@@ -3906,7 +3906,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
3906
3906
update -> type & REF_ISSYMREF ) {
3907
3907
/* It is a loose reference. */
3908
3908
strbuf_reset (& sb );
3909
- strbuf_git_path ( & sb , "%s" , lock -> ref_name );
3909
+ files_ref_path ( refs , & sb , lock -> ref_name );
3910
3910
if (unlink_or_msg (sb .buf , err )) {
3911
3911
ret = TRANSACTION_GENERIC_ERROR ;
3912
3912
goto cleanup ;
@@ -4206,19 +4206,18 @@ static int files_reflog_expire(struct ref_store *ref_store,
4206
4206
4207
4207
static int files_init_db (struct ref_store * ref_store , struct strbuf * err )
4208
4208
{
4209
+ struct files_ref_store * refs =
4210
+ files_downcast (ref_store , 0 , "init_db" );
4209
4211
struct strbuf sb = STRBUF_INIT ;
4210
4212
4211
- /* Check validity (but we don't need the result): */
4212
- files_downcast (ref_store , 0 , "init_db" );
4213
-
4214
4213
/*
4215
4214
* Create .git/refs/{heads,tags}
4216
4215
*/
4217
- strbuf_git_path ( & sb , "refs/heads" );
4216
+ files_ref_path ( refs , & sb , "refs/heads" );
4218
4217
safe_create_dir (sb .buf , 1 );
4219
4218
4220
4219
strbuf_reset (& sb );
4221
- strbuf_git_path ( & sb , "refs/tags" );
4220
+ files_ref_path ( refs , & sb , "refs/tags" );
4222
4221
safe_create_dir (sb .buf , 1 );
4223
4222
4224
4223
strbuf_release (& sb );
0 commit comments