@@ -67,7 +67,6 @@ struct files_ref_store {
67
67
struct ref_store base ;
68
68
unsigned int store_flags ;
69
69
70
- char * gitdir ;
71
70
char * gitcommondir ;
72
71
73
72
struct ref_cache * loose ;
@@ -94,18 +93,17 @@ static struct ref_store *files_ref_store_create(const char *gitdir,
94
93
struct ref_store * ref_store = (struct ref_store * )refs ;
95
94
struct strbuf sb = STRBUF_INIT ;
96
95
96
+ ref_store -> gitdir = xstrdup (gitdir );
97
97
base_ref_store_init (ref_store , & refs_be_files );
98
98
refs -> store_flags = flags ;
99
99
100
- refs -> gitdir = xstrdup (gitdir );
101
100
get_common_dir_noenv (& sb , gitdir );
102
101
refs -> gitcommondir = strbuf_detach (& sb , NULL );
103
102
strbuf_addf (& sb , "%s/packed-refs" , refs -> gitcommondir );
104
103
refs -> packed_ref_store = packed_ref_store_create (sb .buf , flags );
105
104
strbuf_release (& sb );
106
105
107
- chdir_notify_reparent ("files-backend $GIT_DIR" ,
108
- & refs -> gitdir );
106
+ chdir_notify_reparent ("files-backend $GIT_DIR" , & refs -> base .gitdir );
109
107
chdir_notify_reparent ("files-backend $GIT_COMMONDIR" ,
110
108
& refs -> gitcommondir );
111
109
@@ -176,7 +174,7 @@ static void files_reflog_path(struct files_ref_store *refs,
176
174
switch (ref_type (refname )) {
177
175
case REF_TYPE_PER_WORKTREE :
178
176
case REF_TYPE_PSEUDOREF :
179
- strbuf_addf (sb , "%s/logs/%s" , refs -> gitdir , refname );
177
+ strbuf_addf (sb , "%s/logs/%s" , refs -> base . gitdir , refname );
180
178
break ;
181
179
case REF_TYPE_OTHER_PSEUDOREF :
182
180
case REF_TYPE_MAIN_PSEUDOREF :
@@ -198,7 +196,7 @@ static void files_ref_path(struct files_ref_store *refs,
198
196
switch (ref_type (refname )) {
199
197
case REF_TYPE_PER_WORKTREE :
200
198
case REF_TYPE_PSEUDOREF :
201
- strbuf_addf (sb , "%s/%s" , refs -> gitdir , refname );
199
+ strbuf_addf (sb , "%s/%s" , refs -> base . gitdir , refname );
202
200
break ;
203
201
case REF_TYPE_MAIN_PSEUDOREF :
204
202
if (!skip_prefix (refname , "main-worktree/" , & refname ))
@@ -360,7 +358,6 @@ static int files_read_raw_ref(struct ref_store *ref_store,
360
358
struct strbuf sb_path = STRBUF_INIT ;
361
359
const char * path ;
362
360
const char * buf ;
363
- const char * p ;
364
361
struct stat st ;
365
362
int fd ;
366
363
int ret = -1 ;
@@ -465,36 +462,41 @@ static int files_read_raw_ref(struct ref_store *ref_store,
465
462
close (fd );
466
463
strbuf_rtrim (& sb_contents );
467
464
buf = sb_contents .buf ;
465
+
466
+ ret = parse_loose_ref_contents (buf , oid , referent , type );
467
+
468
+ out :
469
+ save_errno = errno ;
470
+ strbuf_release (& sb_path );
471
+ strbuf_release (& sb_contents );
472
+ errno = save_errno ;
473
+ return ret ;
474
+ }
475
+
476
+ int parse_loose_ref_contents (const char * buf , struct object_id * oid ,
477
+ struct strbuf * referent , unsigned int * type )
478
+ {
479
+ const char * p ;
468
480
if (skip_prefix (buf , "ref:" , & buf )) {
469
481
while (isspace (* buf ))
470
482
buf ++ ;
471
483
472
484
strbuf_reset (referent );
473
485
strbuf_addstr (referent , buf );
474
486
* type |= REF_ISSYMREF ;
475
- ret = 0 ;
476
- goto out ;
487
+ return 0 ;
477
488
}
478
489
479
490
/*
480
- * Please note that FETCH_HEAD has additional
481
- * data after the sha.
491
+ * FETCH_HEAD has additional data after the sha.
482
492
*/
483
493
if (parse_oid_hex (buf , oid , & p ) ||
484
494
(* p != '\0' && !isspace (* p ))) {
485
495
* type |= REF_ISBROKEN ;
486
496
errno = EINVAL ;
487
- goto out ;
497
+ return -1 ;
488
498
}
489
-
490
- ret = 0 ;
491
-
492
- out :
493
- save_errno = errno ;
494
- strbuf_release (& sb_path );
495
- strbuf_release (& sb_contents );
496
- errno = save_errno ;
497
- return ret ;
499
+ return 0 ;
498
500
}
499
501
500
502
static void unlock_ref (struct ref_lock * lock )
@@ -2199,12 +2201,11 @@ static struct ref_iterator *files_reflog_iterator_begin(struct ref_store *ref_st
2199
2201
files_downcast (ref_store , REF_STORE_READ ,
2200
2202
"reflog_iterator_begin" );
2201
2203
2202
- if (!strcmp (refs -> gitdir , refs -> gitcommondir )) {
2204
+ if (!strcmp (refs -> base . gitdir , refs -> gitcommondir )) {
2203
2205
return reflog_iterator_begin (ref_store , refs -> gitcommondir );
2204
2206
} else {
2205
2207
return merge_ref_iterator_begin (
2206
- 0 ,
2207
- reflog_iterator_begin (ref_store , refs -> gitdir ),
2208
+ 0 , reflog_iterator_begin (ref_store , refs -> base .gitdir ),
2208
2209
reflog_iterator_begin (ref_store , refs -> gitcommondir ),
2209
2210
reflog_iterator_select , refs );
2210
2211
}
0 commit comments