77#include "../iterator.h"
88#include "../lockfile.h"
99
10+ struct packed_ref_store ;
11+
1012struct packed_ref_cache {
13+ /*
14+ * A back-pointer to the packed_ref_store with which this
15+ * cache is associated:
16+ */
17+ struct packed_ref_store * refs ;
18+
1119 struct ref_cache * cache ;
1220
1321 /*
@@ -154,7 +162,7 @@ static const char *parse_ref_line(struct strbuf *line, struct object_id *oid)
154162}
155163
156164/*
157- * Read from `packed_refs_file` into a newly-allocated
165+ * Read from the `packed-refs` file into a newly-allocated
158166 * `packed_ref_cache` and return it. The return value will already
159167 * have its reference count incremented.
160168 *
@@ -182,7 +190,7 @@ static const char *parse_ref_line(struct strbuf *line, struct object_id *oid)
182190 * compatibility with older clients, but we do not require it
183191 * (i.e., "peeled" is a no-op if "fully-peeled" is set).
184192 */
185- static struct packed_ref_cache * read_packed_refs (const char * packed_refs_file )
193+ static struct packed_ref_cache * read_packed_refs (struct packed_ref_store * refs )
186194{
187195 FILE * f ;
188196 struct packed_ref_cache * packed_refs = xcalloc (1 , sizeof (* packed_refs ));
@@ -191,11 +199,12 @@ static struct packed_ref_cache *read_packed_refs(const char *packed_refs_file)
191199 enum { PEELED_NONE , PEELED_TAGS , PEELED_FULLY } peeled = PEELED_NONE ;
192200 struct ref_dir * dir ;
193201
202+ packed_refs -> refs = refs ;
194203 acquire_packed_ref_cache (packed_refs );
195204 packed_refs -> cache = create_ref_cache (NULL , NULL );
196205 packed_refs -> cache -> root -> flag &= ~REF_INCOMPLETE ;
197206
198- f = fopen (packed_refs_file , "r" );
207+ f = fopen (refs -> path , "r" );
199208 if (!f ) {
200209 if (errno == ENOENT ) {
201210 /*
@@ -205,7 +214,7 @@ static struct packed_ref_cache *read_packed_refs(const char *packed_refs_file)
205214 */
206215 return packed_refs ;
207216 } else {
208- die_errno ("couldn't read %s" , packed_refs_file );
217+ die_errno ("couldn't read %s" , refs -> path );
209218 }
210219 }
211220
@@ -218,7 +227,7 @@ static struct packed_ref_cache *read_packed_refs(const char *packed_refs_file)
218227 const char * traits ;
219228
220229 if (!line .len || line .buf [line .len - 1 ] != '\n' )
221- die ("unterminated line in %s: %s" , packed_refs_file , line .buf );
230+ die ("unterminated line in %s: %s" , refs -> path , line .buf );
222231
223232 if (skip_prefix (line .buf , "# pack-refs with:" , & traits )) {
224233 if (strstr (traits , " fully-peeled " ))
@@ -258,7 +267,7 @@ static struct packed_ref_cache *read_packed_refs(const char *packed_refs_file)
258267 last -> flag |= REF_KNOWS_PEELED ;
259268 } else {
260269 strbuf_setlen (& line , line .len - 1 );
261- die ("unexpected line in %s: %s" , packed_refs_file , line .buf );
270+ die ("unexpected line in %s: %s" , refs -> path , line .buf );
262271 }
263272 }
264273
@@ -293,7 +302,7 @@ static struct packed_ref_cache *get_packed_ref_cache(struct packed_ref_store *re
293302 validate_packed_ref_cache (refs );
294303
295304 if (!refs -> cache )
296- refs -> cache = read_packed_refs (refs -> path );
305+ refs -> cache = read_packed_refs (refs );
297306
298307 return refs -> cache ;
299308}
0 commit comments