mirror of
https://github.com/git/git
synced 2024-09-13 13:24:41 +00:00
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>
This commit is contained in:
parent
49a03ef466
commit
36f23534ae
|
@ -255,10 +255,8 @@ static struct packed_ref_cache *read_packed_refs(struct packed_ref_store *refs)
|
||||||
pos = buf;
|
pos = buf;
|
||||||
eof = buf + size;
|
eof = buf + size;
|
||||||
|
|
||||||
dir = get_ref_dir(packed_refs->cache->root);
|
/* If the file has a header line, process it: */
|
||||||
while (pos < eof) {
|
if (pos < eof && *pos == '#') {
|
||||||
struct object_id oid;
|
|
||||||
const char *refname;
|
|
||||||
const char *traits;
|
const char *traits;
|
||||||
|
|
||||||
eol = memchr(pos, '\n', eof - pos);
|
eol = memchr(pos, '\n', eof - pos);
|
||||||
|
@ -267,14 +265,30 @@ static struct packed_ref_cache *read_packed_refs(struct packed_ref_store *refs)
|
||||||
|
|
||||||
strbuf_add(&line, pos, eol + 1 - pos);
|
strbuf_add(&line, pos, eol + 1 - pos);
|
||||||
|
|
||||||
if (skip_prefix(line.buf, "# pack-refs with:", &traits)) {
|
if (!skip_prefix(line.buf, "# pack-refs with:", &traits))
|
||||||
if (strstr(traits, " fully-peeled "))
|
die_invalid_line(refs->path, pos, eof - pos);
|
||||||
peeled = PEELED_FULLY;
|
|
||||||
else if (strstr(traits, " peeled "))
|
if (strstr(traits, " fully-peeled "))
|
||||||
peeled = PEELED_TAGS;
|
peeled = PEELED_FULLY;
|
||||||
/* perhaps other traits later as well */
|
else if (strstr(traits, " peeled "))
|
||||||
goto next_line;
|
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;
|
||||||
|
|
||||||
|
eol = memchr(pos, '\n', eof - pos);
|
||||||
|
if (!eol)
|
||||||
|
die_unterminated_line(refs->path, pos, eof - pos);
|
||||||
|
|
||||||
|
strbuf_add(&line, pos, eol + 1 - pos);
|
||||||
|
|
||||||
refname = parse_ref_line(&line, &oid);
|
refname = parse_ref_line(&line, &oid);
|
||||||
if (refname) {
|
if (refname) {
|
||||||
|
@ -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);
|
die_invalid_line(refs->path, line.buf, line.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
next_line:
|
|
||||||
/* The "+ 1" is for the LF character. */
|
/* The "+ 1" is for the LF character. */
|
||||||
pos = eol + 1;
|
pos = eol + 1;
|
||||||
strbuf_reset(&line);
|
strbuf_reset(&line);
|
||||||
|
|
Loading…
Reference in a new issue