Skip to content

Commit daa4540

Browse files
mhaggergitster
authored andcommitted
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>
1 parent 6a9bc40 commit daa4540

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

refs/packed-backend.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ struct packed_ref_cache {
1818

1919
struct ref_cache *cache;
2020

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+
2127
/*
2228
* Count of references to the data structure in this instance,
2329
* 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)
195201
char *buf;
196202
const char *pos, *eol, *eof;
197203
struct strbuf tmp = STRBUF_INIT;
198-
enum { PEELED_NONE, PEELED_TAGS, PEELED_FULLY } peeled = PEELED_NONE;
199204
struct ref_dir *dir;
200205

201206
packed_refs->refs = refs;
202207
acquire_packed_ref_cache(packed_refs);
203208
packed_refs->cache = create_ref_cache(NULL, NULL);
204209
packed_refs->cache->root->flag &= ~REF_INCOMPLETE;
210+
packed_refs->peeled = PEELED_NONE;
205211

206212
fd = open(refs->path, O_RDONLY);
207213
if (fd < 0) {
@@ -244,9 +250,9 @@ static struct packed_ref_cache *read_packed_refs(struct packed_ref_store *refs)
244250
string_list_split_in_place(&traits, p, ' ', -1);
245251

246252
if (unsorted_string_list_has_string(&traits, "fully-peeled"))
247-
peeled = PEELED_FULLY;
253+
packed_refs->peeled = PEELED_FULLY;
248254
else if (unsorted_string_list_has_string(&traits, "peeled"))
249-
peeled = PEELED_TAGS;
255+
packed_refs->peeled = PEELED_TAGS;
250256
/* perhaps other traits later as well */
251257

252258
/* The "+ 1" is for the LF character. */
@@ -282,8 +288,9 @@ static struct packed_ref_cache *read_packed_refs(struct packed_ref_store *refs)
282288
oidclr(&oid);
283289
flag |= REF_BAD_NAME | REF_ISBROKEN;
284290
}
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/")))
287294
flag |= REF_KNOWS_PEELED;
288295
entry = create_ref_entry(refname, &oid, flag);
289296
add_ref_entry(dir, entry);

0 commit comments

Comments
 (0)