public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Tanay Abhra <tanayabh@gmail•com>
Cc: git@vger•kernel.org, mhagger@alum•mit.edu, max@quendi•de
Subject: Re: [PATCH v3] commit.c: use skip_prefix() instead of starts_with()
Date: Tue, 04 Mar 2014 11:33:46 -0800	[thread overview]
Message-ID: <xmqqppm1kbc5.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1393922540-13156-1-git-send-email-tanayabh@gmail.com> (Tanay Abhra's message of "Tue, 4 Mar 2014 00:42:20 -0800")

Tanay Abhra <tanayabh@gmail•com> writes:

> In record_author_date() & parse_gpg_output() ,using skip_prefix() instead of
> starts_with() is a more suitable abstraction.

Thanks.  Will queue with a reworded message to clarify what exactly
"A more suitable" means.

Here is what I tentatively came up with.

-- >8 --
From: Tanay Abhra <tanayabh@gmail•com>
Date: Tue, 4 Mar 2014 00:42:20 -0800
Subject: [PATCH] commit.c: use skip_prefix() instead of starts_with()

In record_author_date() & parse_gpg_output(), the callers of
starts_with() not just want to know if the string starts with the
prefix, but also can benefit from knowing the string that follows
the prefix.

By using skip_prefix(), we can do both at the same time.

Helped-by: Max Horn <max@quendi•de>
Helped-by: Junio C Hamano <gitster@pobox•com>
Helped-by: Michael Haggerty <mhagger@alum•mit.edu>
Signed-off-by: Tanay Abhra <tanayabh@gmail•com>
Signed-off-by: Junio C Hamano <gitster@pobox•com>
---
 commit.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/commit.c b/commit.c
index 6bf4fe0..6c92acb 100644
--- a/commit.c
+++ b/commit.c
@@ -548,7 +548,7 @@ define_commit_slab(author_date_slab, unsigned long);
 static void record_author_date(struct author_date_slab *author_date,
 			       struct commit *commit)
 {
-	const char *buf, *line_end;
+	const char *buf, *line_end, *ident_line;
 	char *buffer = NULL;
 	struct ident_split ident;
 	char *date_end;
@@ -566,14 +566,16 @@ static void record_author_date(struct author_date_slab *author_date,
 	     buf;
 	     buf = line_end + 1) {
 		line_end = strchrnul(buf, '\n');
-		if (!starts_with(buf, "author ")) {
+		ident_line = skip_prefix(buf, "author ");
+		if (!ident_line) {
 			if (!line_end[0] || line_end[1] == '\n')
 				return; /* end of header */
 			continue;
 		}
+		buf = ident_line;
 		if (split_ident_line(&ident,
-				     buf + strlen("author "),
-				     line_end - (buf + strlen("author "))) ||
+				     buf,
+				     line_end - buf) ||
 		    !ident.date_begin || !ident.date_end)
 			goto fail_exit; /* malformed "author" line */
 		break;
@@ -1193,10 +1195,9 @@ static void parse_gpg_output(struct signature_check *sigc)
 	for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
 		const char *found, *next;
 
-		if (starts_with(buf, sigcheck_gpg_status[i].check + 1)) {
-			/* At the very beginning of the buffer */
-			found = buf + strlen(sigcheck_gpg_status[i].check + 1);
-		} else {
+		found = skip_prefix(buf, sigcheck_gpg_status[i].check + 1);
+		/* At the very beginning of the buffer */
+		if(!found) {
 			found = strstr(buf, sigcheck_gpg_status[i].check);
 			if (!found)
 				continue;
-- 
1.9.0-186-gd464cb7

      parent reply	other threads:[~2014-03-04 19:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-04  8:42 [PATCH v3] commit.c: use skip_prefix() instead of starts_with() Tanay Abhra
2014-03-04 19:16 ` Max Horn
2014-03-04 20:38   ` Junio C Hamano
2014-03-04 19:33 ` Junio C Hamano [this message]

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=xmqqppm1kbc5.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=max@quendi$(echo .)de \
    --cc=mhagger@alum$(echo .)mit.edu \
    --cc=tanayabh@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox