git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC 01/13] check_refname_component(): iterate via index rather than via pointer

From
mhagger@alum.mit.edu <mhagger@alum.mit.edu>
Date
Oct 19, 2011, 20:55 UTC
Message-ID
<1319057716-28094-2-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1319057716-28094-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 |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/refs.c b/refs.c
index 0d74d70..3b41252 100644
--- a/refs.c
+++ b/refs.c
@@ -912,11 +912,11 @@ static inline int bad_ref_char(int ch)
  */
 static int check_refname_component(const char *ref, int flags)
 {
-	const char *cp;
+	int i, len = strlen(ref);
 	char last = '\0';
 
-	for (cp = ref; ; cp++) {
-		char ch = *cp;
+	for (i = 0; i < len; i++) {
+		char ch = ref[i];
 		if (ch == '\0' || ch == '/')
 			break;
 		if (bad_ref_char(ch))
@@ -927,7 +927,7 @@ static int check_refname_component(const char *ref, int flags)
 			return -1; /* Refname contains "@{". */
 		last = ch;
 	}
-	if (cp == ref)
+	if (i == 0)
 		return -1; /* Component has zero length. */
 	if (ref[0] == '.') {
 		if (!(flags & REFNAME_DOT_COMPONENT))
@@ -936,12 +936,12 @@ static int check_refname_component(const char *ref, int flags)
 		 * Even if leading dots are allowed, don't allow "."
 		 * as a component (".." is prevented by a rule above).
 		 */
-		if (ref[1] == '\0')
+		if (i == 1)
 			return -1; /* Component equals ".". */
 	}
-	if (cp - ref >= 5 && !memcmp(cp - 5, ".lock", 5))
+	if (i >= 5 && !memcmp(&ref[i - 5], ".lock", 5))
 		return -1; /* Refname ends with ".lock". */
-	return cp - ref;
+	return i;
 }
 
 int check_refname_format(const char *ref, int flags)
-- 
1.7.7
Previous: mhagger@alum.mit.eduNext: mhagger@alum.mit.edu
Message 2 of 17 in “[RFC 00/13] Checking full vs. partial refnames”
  1. mhagger@alum.mit.eduOct 19, 2011
  2. 01/13 check_refname_component(): iterate via index rather than via pointermhagger@alum.mit.edu, Oct 19, 2011
  3. 02/13 parse_refname_prefix(): new functionmhagger@alum.mit.edu, Oct 19, 2011
  4. 03/13 Teach check_refname_format() to check full refnamesmhagger@alum.mit.edu, Oct 19, 2011
  5. 04/13 add_ref(): move the call of check_refname_format() to callersmhagger@alum.mit.edu, Oct 19, 2011
  6. Junio C HamanoOct 19, 2011
  7. Michael HaggertyOct 19, 2011
  8. 05/13 receive-pack::update(): use check_refname_format(..., REFNAME_FULL)mhagger@alum.mit.edu, Oct 19, 2011
  9. 06/13 strbuf_check_branch_ref(): use check_refname_format(..., REFNAME_FULL)mhagger@alum.mit.edu, Oct 19, 2011
  10. 07/13 one_local_ref(): use check_refname_format(..., REFNAME_FULL)mhagger@alum.mit.edu, Oct 19, 2011
  11. 08/13 expand_namespace(): the refname is full, so use REFNAME_FULL optionmhagger@alum.mit.edu, Oct 19, 2011
  12. 09/13 new_branch(): verify that new branch name is a valid full refnamemhagger@alum.mit.edu, Oct 19, 2011
  13. Junio C HamanoOct 19, 2011
  14. 10/13 strbuf_check_tag_ref(): the refname is full, so use REFNAME_FULL optionmhagger@alum.mit.edu, Oct 19, 2011
  15. 11/13 replace_object(): the refname is full, so use REFNAME_FULL optionmhagger@alum.mit.edu, Oct 19, 2011
  16. 12/13 resolve_ref: use check_refname_format(..., REFNAME_FULL)mhagger@alum.mit.edu, Oct 19, 2011
  17. 13/13 filter_refs(): the refname is full, so use REFNAME_FULL optionmhagger@alum.mit.edu, Oct 19, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.