All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: Junio C Hamano <gitster@pobox.com>, Johannes Sixt <j6t@kdbg.org>,
	Michael Blume <blume.mike@gmail.com>,
	Git List <git@vger.kernel.org>
Subject: [PATCH 3/3] read_packed_refs: use skip_prefix instead of static array
Date: Wed, 10 Dec 2014 05:40:36 -0500	[thread overview]
Message-ID: <20141210104035.GC24514@peff.net> (raw)
In-Reply-To: <20141210103907.GA22186@peff.net>

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>
---
 refs.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/refs.c b/refs.c
index 10f8247..c71553f 100644
--- a/refs.c
+++ b/refs.c
@@ -1135,10 +1135,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 "))
-- 
2.2.0.454.g7eca6b7

  parent reply	other threads:[~2014-12-10 10:40 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-09 17:49 [RFC/PATCH] pkt-line: allow writing of LARGE_PACKET_MAX buffers Jeff King
2014-12-09 18:09 ` Jeff King
2014-12-09 22:41   ` Junio C Hamano
2014-12-10  4:36     ` Michael Blume
2014-12-10  7:34     ` [PATCH v3] " Jeff King
2014-12-10  8:36       ` Eric Sunshine
2014-12-10  9:42         ` Eric Sunshine
2014-12-10  9:49           ` Eric Sunshine
2014-12-10  9:53             ` Jeff King
2014-12-10 10:39               ` [PATCH 0/3] convert read_packed_refs to use strbuf Jeff King
2014-12-10 10:40                 ` [PATCH 1/3] read_packed_refs: use a strbuf for reading lines Jeff King
2014-12-10 10:40                 ` [PATCH 2/3] read_packed_refs: pass strbuf to parse_ref_line Jeff King
2014-12-10 10:40                 ` Jeff King [this message]
2014-12-10 17:43                 ` [PATCH 0/3] convert read_packed_refs to use strbuf Junio C Hamano
2014-12-10  9:47         ` [PATCH v4] pkt-line: allow writing of LARGE_PACKET_MAX buffers Jeff King
2014-12-10  9:56           ` Eric Sunshine
2014-12-10 20:14           ` Eric Sunshine
2014-12-10 21:06             ` Jeff King
2014-12-09 19:58 ` [RFC/PATCH] " Johannes Sixt
2014-12-09 20:00   ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141210104035.GC24514@peff.net \
    --to=peff@peff.net \
    --cc=blume.mike@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.