Skip to content

Commit

Permalink
read_packed_refs: use skip_prefix instead of static array
Browse files Browse the repository at this point in the history
We want to recognize the packed-refs header and skip to the
"traits" part of the line. We currently do it by feeding
sizeof() a static const array to strncmp. However, it's a
bit simpler to just skip_prefix, which expresses the
intention more directly, and without remembering to account
for the NUL-terminator in each sizeof() call.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Dec 10, 2014
1 parent 6a49870 commit ea41783
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1040,10 +1040,9 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
while (strbuf_getwholeline(&line, f, '\n') != EOF) {
unsigned char sha1[20];
const char *refname;
static const char header[] = "# pack-refs with:";
const char *traits;

if (!strncmp(line.buf, header, sizeof(header)-1)) {
const char *traits = line.buf + sizeof(header) - 1;
if (skip_prefix(line.buf, "# pack-refs with:", &traits)) {
if (strstr(traits, " fully-peeled "))
peeled = PEELED_FULLY;
else if (strstr(traits, " peeled "))
Expand Down

0 comments on commit ea41783

Please sign in to comment.