packed_ref_cache: remember the file-wide peeling state
Rather than store the peeling state (i.e., the one defined by traits in the `packed-refs` file header line) in a local variable in `read_packed_refs()`, store it permanently in `packed_ref_cache`. This will be needed when we stop reading all packed refs at once. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Sep 25, 2017 at 10:00 UTC
daa45408c12053d608d86f0c1daa23b79815624f
1 file changed
+12
-5
refs/packed-backend.c
+12
-5
@@ -18,6 +18,12 @@ struct packed_ref_cache {
18
19
struct ref_cache *cache;
20
21
+ /*
22
+ * What is the peeled state of this cache? (This is usually
23
+ * determined from the header of the "packed-refs" file.)
24
+ */
25
+ enum { PEELED_NONE, PEELED_TAGS, PEELED_FULLY } peeled;
26
+
27
/*
28
* Count of references to the data structure in this instance,
29
* including the pointer from files_ref_store::packed if any.
@@ -195,13 +201,13 @@ static struct packed_ref_cache *read_packed_refs(struct packed_ref_store *refs)
201
char *buf;
202
const char *pos, *eol, *eof;
203
struct strbuf tmp = STRBUF_INIT;
198
- enum { PEELED_NONE, PEELED_TAGS, PEELED_FULLY } peeled = PEELED_NONE;
204
struct ref_dir *dir;
205
206
packed_refs->refs = refs;
207
acquire_packed_ref_cache(packed_refs);
208
packed_refs->cache = create_ref_cache(NULL, NULL);
209
packed_refs->cache->root->flag &= ~REF_INCOMPLETE;
210
+ packed_refs->peeled = PEELED_NONE;
211
212
fd = open(refs->path, O_RDONLY);
213
if (fd < 0) {
@@ -244,9 +250,9 @@ static struct packed_ref_cache *read_packed_refs(struct packed_ref_store *refs)
250
string_list_split_in_place(&traits, p, ' ', -1);
251
252
if (unsorted_string_list_has_string(&traits, "fully-peeled"))
247
- peeled = PEELED_FULLY;
253
+ packed_refs->peeled = PEELED_FULLY;
254
else if (unsorted_string_list_has_string(&traits, "peeled"))
249
- peeled = PEELED_TAGS;
255
+ packed_refs->peeled = PEELED_TAGS;
256
/* perhaps other traits later as well */
257
258
/* The "+ 1" is for the LF character. */
@@ -282,8 +288,9 @@ static struct packed_ref_cache *read_packed_refs(struct packed_ref_store *refs)
288
oidclr(&oid);
289
flag |= REF_BAD_NAME | REF_ISBROKEN;
290
}
285
- if (peeled == PEELED_FULLY ||
286
- (peeled == PEELED_TAGS && starts_with(refname, "refs/tags/")))
291
+ if (packed_refs->peeled == PEELED_FULLY ||
292
+ (packed_refs->peeled == PEELED_TAGS &&
293
+ starts_with(refname, "refs/tags/")))
294
flag |= REF_KNOWS_PEELED;
295
entry = create_ref_entry(refname, &oid, flag);
296
add_ref_entry(dir, entry);