diff options
author | Michael Haggerty <mhagger@alum.mit.edu> | 2017-09-13 19:16:00 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-09-14 15:19:07 +0900 |
commit | 36f23534aef58f747048ffea5addb0367406896d (patch) | |
tree | 613feeb61c68c7b39f219747e9cccbffbab059e5 /refs/packed-backend.c | |
parent | 49a03ef46667ad5074f1e602e392b7763c686205 (diff) | |
download | git-36f23534aef58f747048ffea5addb0367406896d.tar.gz |
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>
Diffstat (limited to 'refs/packed-backend.c')
-rw-r--r-- | refs/packed-backend.c | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 154abbd83a..141f02b9c8 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -255,11 +255,34 @@ static struct packed_ref_cache *read_packed_refs(struct packed_ref_store *refs) pos = buf; eof = buf + size; + /* If the file has a header line, process it: */ + if (pos < eof && *pos == '#') { + const char *traits; + + eol = memchr(pos, '\n', eof - pos); + if (!eol) + die_unterminated_line(refs->path, pos, eof - pos); + + strbuf_add(&line, pos, eol + 1 - pos); + + if (!skip_prefix(line.buf, "# pack-refs with:", &traits)) + die_invalid_line(refs->path, pos, eof - pos); + + if (strstr(traits, " fully-peeled ")) + peeled = PEELED_FULLY; + else if (strstr(traits, " peeled ")) + peeled = PEELED_TAGS; + /* perhaps other traits later as well */ + + /* The "+ 1" is for the LF character. */ + pos = eol + 1; + strbuf_reset(&line); + } + dir = get_ref_dir(packed_refs->cache->root); while (pos < eof) { struct object_id oid; const char *refname; - const char *traits; eol = memchr(pos, '\n', eof - pos); if (!eol) @@ -267,15 +290,6 @@ static struct packed_ref_cache *read_packed_refs(struct packed_ref_store *refs) strbuf_add(&line, pos, eol + 1 - pos); - if (skip_prefix(line.buf, "# pack-refs with:", &traits)) { - if (strstr(traits, " fully-peeled ")) - peeled = PEELED_FULLY; - else if (strstr(traits, " peeled ")) - peeled = PEELED_TAGS; - /* perhaps other traits later as well */ - goto next_line; - } - refname = parse_ref_line(&line, &oid); if (refname) { int flag = REF_ISPACKED; @@ -307,7 +321,6 @@ static struct packed_ref_cache *read_packed_refs(struct packed_ref_store *refs) die_invalid_line(refs->path, line.buf, line.len); } - next_line: /* The "+ 1" is for the LF character. */ pos = eol + 1; strbuf_reset(&line); |