packed_ref_cache: add a backlink to the associated `packed_ref_store`

It will prove convenient in upcoming patches. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Sep 13, 2017 at 19:15 UTC f0a7dc86d2919a2b91e46503f1df173e58977ef2
1 file changed +16 -7
refs/packed-backend.c
+16 -7
@@ -7,7 +7,15 @@
7 #include "../iterator.h"
8 #include "../lockfile.h"
9
10 +struct packed_ref_store;
11 +
12 struct 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 +
19 struct ref_cache *cache;
20
21 /*
@@ -154,7 +162,7 @@ static const char *parse_ref_line(struct strbuf *line, struct object_id *oid)
162 }
163
164 /*
157 - * Read from `packed_refs_file` into a newly-allocated
165 + * Read from the `packed-refs` file into a newly-allocated
166 * `packed_ref_cache` and return it. The return value will already
167 * have its reference count incremented.
168 *
@@ -182,7 +190,7 @@ static const char *parse_ref_line(struct strbuf *line, struct object_id *oid)
190 * compatibility with older clients, but we do not require it
191 * (i.e., "peeled" is a no-op if "fully-peeled" is set).
192 */
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)
194 {
195 FILE *f;
196 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)
199 enum { PEELED_NONE, PEELED_TAGS, PEELED_FULLY } peeled = PEELED_NONE;
200 struct ref_dir *dir;
201
202 + packed_refs->refs = refs;
203 acquire_packed_ref_cache(packed_refs);
204 packed_refs->cache = create_ref_cache(NULL, NULL);
205 packed_refs->cache->root->flag &= ~REF_INCOMPLETE;
206
198 - f = fopen(packed_refs_file, "r");
207 + f = fopen(refs->path, "r");
208 if (!f) {
209 if (errno == ENOENT) {
210 /*
@@ -205,7 +214,7 @@ static struct packed_ref_cache *read_packed_refs(const char *packed_refs_file)
214 */
215 return packed_refs;
216 } else {
208 - die_errno("couldn't read %s", packed_refs_file);
217 + die_errno("couldn't read %s", refs->path);
218 }
219 }
220
@@ -218,7 +227,7 @@ static struct packed_ref_cache *read_packed_refs(const char *packed_refs_file)
227 const char *traits;
228
229 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);
231
232 if (skip_prefix(line.buf, "# pack-refs with:", &traits)) {
233 if (strstr(traits, " fully-peeled "))
@@ -258,7 +267,7 @@ static struct packed_ref_cache *read_packed_refs(const char *packed_refs_file)
267 last->flag |= REF_KNOWS_PEELED;
268 } else {
269 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);
271 }
272 }
273
@@ -293,7 +302,7 @@ static struct packed_ref_cache *get_packed_ref_cache(struct packed_ref_store *re
302 validate_packed_ref_cache(refs);
303
304 if (!refs->cache)
296 - refs->cache = read_packed_refs(refs->path);
305 + refs->cache = read_packed_refs(refs);
306
307 return refs->cache;
308 }