Skip to content

Commit 36f2353

Browse files
mhaggergitster
authored andcommitted
read_packed_refs(): only check for a header at the top of the file
This tightens up the parsing a bit; previously, stray header-looking lines would have been processed. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 49a03ef commit 36f2353

1 file changed

Lines changed: 24 additions & 11 deletions

File tree

refs/packed-backend.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,27 +255,41 @@ static struct packed_ref_cache *read_packed_refs(struct packed_ref_store *refs)
255255
pos = buf;
256256
eof = buf + size;
257257

258+
/* If the file has a header line, process it: */
259+
if (pos < eof && *pos == '#') {
260+
const char *traits;
261+
262+
eol = memchr(pos, '\n', eof - pos);
263+
if (!eol)
264+
die_unterminated_line(refs->path, pos, eof - pos);
265+
266+
strbuf_add(&line, pos, eol + 1 - pos);
267+
268+
if (!skip_prefix(line.buf, "# pack-refs with:", &traits))
269+
die_invalid_line(refs->path, pos, eof - pos);
270+
271+
if (strstr(traits, " fully-peeled "))
272+
peeled = PEELED_FULLY;
273+
else if (strstr(traits, " peeled "))
274+
peeled = PEELED_TAGS;
275+
/* perhaps other traits later as well */
276+
277+
/* The "+ 1" is for the LF character. */
278+
pos = eol + 1;
279+
strbuf_reset(&line);
280+
}
281+
258282
dir = get_ref_dir(packed_refs->cache->root);
259283
while (pos < eof) {
260284
struct object_id oid;
261285
const char *refname;
262-
const char *traits;
263286

264287
eol = memchr(pos, '\n', eof - pos);
265288
if (!eol)
266289
die_unterminated_line(refs->path, pos, eof - pos);
267290

268291
strbuf_add(&line, pos, eol + 1 - pos);
269292

270-
if (skip_prefix(line.buf, "# pack-refs with:", &traits)) {
271-
if (strstr(traits, " fully-peeled "))
272-
peeled = PEELED_FULLY;
273-
else if (strstr(traits, " peeled "))
274-
peeled = PEELED_TAGS;
275-
/* perhaps other traits later as well */
276-
goto next_line;
277-
}
278-
279293
refname = parse_ref_line(&line, &oid);
280294
if (refname) {
281295
int flag = REF_ISPACKED;
@@ -307,7 +321,6 @@ static struct packed_ref_cache *read_packed_refs(struct packed_ref_store *refs)
307321
die_invalid_line(refs->path, line.buf, line.len);
308322
}
309323

310-
next_line:
311324
/* The "+ 1" is for the LF character. */
312325
pos = eol + 1;
313326
strbuf_reset(&line);

0 commit comments

Comments
 (0)