Skip to content

Commit ea41783

Browse files
peffgitster
authored andcommitted
read_packed_refs: use skip_prefix instead of static array
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6a49870 commit ea41783

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

refs.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,10 +1040,9 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
10401040
while (strbuf_getwholeline(&line, f, '\n') != EOF) {
10411041
unsigned char sha1[20];
10421042
const char *refname;
1043-
static const char header[] = "# pack-refs with:";
1043+
const char *traits;
10441044

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

0 commit comments

Comments
 (0)