create_snapshot(): use `xmemdupz()` rather than a strbuf

It's lighter weight. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Jan 24, 2018 at 12:14 UTC 27a41841ec7f83b3b1078c400f149bc536e796a4
1 file changed +4 -5
refs/packed-backend.c
+4 -5
@@ -620,8 +620,7 @@ static struct snapshot *create_snapshot(struct packed_ref_store *refs)
620
621 /* If the file has a header line, process it: */
622 if (snapshot->buf < snapshot->eof && *snapshot->buf == '#') {
623 - struct strbuf tmp = STRBUF_INIT;
624 - char *p, *eol;
623 + char *tmp, *p, *eol;
624 struct string_list traits = STRING_LIST_INIT_NODUP;
625
626 eol = memchr(snapshot->buf, '\n',
@@ -631,9 +630,9 @@ static struct snapshot *create_snapshot(struct packed_ref_store *refs)
630 snapshot->buf,
631 snapshot->eof - snapshot->buf);
632
634 - strbuf_add(&tmp, snapshot->buf, eol - snapshot->buf);
633 + tmp = xmemdupz(snapshot->buf, eol - snapshot->buf);
634
636 - if (!skip_prefix(tmp.buf, "# pack-refs with:", (const char **)&p))
635 + if (!skip_prefix(tmp, "# pack-refs with:", (const char **)&p))
636 die_invalid_line(refs->path,
637 snapshot->buf,
638 snapshot->eof - snapshot->buf);
@@ -653,7 +652,7 @@ static struct snapshot *create_snapshot(struct packed_ref_store *refs)
652 snapshot->start = eol + 1;
653
654 string_list_clear(&traits, 0);
656 - strbuf_release(&tmp);
655 + free(tmp);
656 }
657
658 verify_buffer_safe(snapshot);