git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: mhagger@alum.mit.edu
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>,
	Michael Haggerty <mhagger@alum.mit.edu>
Subject: [RFC 1/7] check_refname_component(): iterate via index rather than via pointer
Date: Tue,  1 May 2012 01:02:49 +0200	[thread overview]
Message-ID: <1335826975-3093-2-git-send-email-mhagger@alum.mit.edu> (raw)
In-Reply-To: <1335826975-3093-1-git-send-email-mhagger@alum.mit.edu>

From: Michael Haggerty <mhagger@alum.mit.edu>

This will make later changes easier.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 refs.c |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/refs.c b/refs.c
index 09322fe..927d36c 100644
--- a/refs.c
+++ b/refs.c
@@ -35,12 +35,12 @@ static inline int bad_ref_char(int ch)
  */
 static int check_refname_component(const char *refname, int flags)
 {
-	const char *cp;
+	int i, len = strlen(refname);
 	char last = '\0';
 
-	for (cp = refname; ; cp++) {
-		char ch = *cp;
-		if (ch == '\0' || ch == '/')
+	for (i = 0; i < len; i++) {
+		char ch = refname[i];
+		if (ch == '/')
 			break;
 		if (bad_ref_char(ch))
 			return -1; /* Illegal character in refname. */
@@ -50,7 +50,7 @@ static int check_refname_component(const char *refname, int flags)
 			return -1; /* Refname contains "@{". */
 		last = ch;
 	}
-	if (cp == refname)
+	if (i == 0)
 		return 0; /* Component has zero length. */
 	if (refname[0] == '.') {
 		if (!(flags & REFNAME_DOT_COMPONENT))
@@ -59,12 +59,12 @@ static int check_refname_component(const char *refname, int flags)
 		 * Even if leading dots are allowed, don't allow "."
 		 * as a component (".." is prevented by a rule above).
 		 */
-		if (refname[1] == '\0')
+		if (len == 1)
 			return -1; /* Component equals ".". */
 	}
-	if (cp - refname >= 5 && !memcmp(cp - 5, ".lock", 5))
+	if (i >= 5 && !memcmp(&refname[i - 5], ".lock", 5))
 		return -1; /* Refname ends with ".lock". */
-	return cp - refname;
+	return i;
 }
 
 int check_refname_format(const char *refname, int flags)
-- 
1.7.10

  reply	other threads:[~2012-04-30 23:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-30 23:02 [RFC 0/7] Make check_refname_format() more flexible mhagger
2012-04-30 23:02 ` mhagger [this message]
2012-04-30 23:02 ` [RFC 2/7] check_refname_component(): fix check with REFNAME_DOT_COMPONENT mhagger
2012-04-30 23:02 ` [RFC 3/7] parse_refname_component(): accept a length parameter mhagger
2012-04-30 23:02 ` [RFC 4/7] parse_refname_component(): parse until terminator mhagger
2012-04-30 23:02 ` [RFC 5/7] parse_refname_prefix(): new function mhagger
2012-04-30 23:02 ` [RFC 6/7] check_refname_format(): add REFNAME_FULL option mhagger
2012-04-30 23:02 ` [RFC 7/7] check_refname_format(): implement REFNAME_RELAXED option mhagger

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=1335826975-3093-2-git-send-email-mhagger@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).