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

[PATCH v3] path: factor out skip_slashes() in normalize_path_copy_len()

From
Pushkar Singh <pushkarkumarsingh1970@gmail.com>
Date
Feb 21, 2026, 11:05 UTC
Message-ID
<20260221110511.1592-2-pushkarkumarsingh1970@gmail.com>
In-Reply-To
<xmqqms17cjjj.fsf@gitster.g>

Extract skip_slashes() to avoid repeating the same is_dir_sep() loop in multiple places inside normalize_path_copy_len().

Keep the dot-component handling inline to preserve the original control flow and readability, as suggested in review.

No functional changes. Behavior verified with t0060-path-utils.sh.
Signed-off-by: Pushkar Singh <pushkarkumarsingh1970@gmail.com>
---
Changes since v2:
- Clarify commit message to reflect reduced scope.
- Make intent explicit and ready for application.
 path.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/path.c b/path.c
index d726537622..1772fcb21c 100644
--- a/path.c
+++ b/path.c
@@ -1112,6 +1112,14 @@ const char *remove_leading_path(const char *in, const char *prefix)
  * end with a '/', then the callers need to be fixed up accordingly.
  *
  */
+
+static const char *skip_slashes(const char *p)
+{
+	while (is_dir_sep(*p))
+		p++;
+	return p;
+}
+
 int normalize_path_copy_len(char *dst, const char *src, int *prefix_len)
 {
 	char *dst0;
@@ -1129,8 +1137,7 @@ int normalize_path_copy_len(char *dst, const char *src, int *prefix_len)
 	}
 	dst0 = dst;
 
-	while (is_dir_sep(*src))
-		src++;
+	src = skip_slashes(src);
 
 	for (;;) {
 		char c = *src;
@@ -1150,8 +1157,7 @@ int normalize_path_copy_len(char *dst, const char *src, int *prefix_len)
 			} else if (is_dir_sep(src[1])) {
 				/* (2) */
 				src += 2;
-				while (is_dir_sep(*src))
-					src++;
+				src = skip_slashes(src);
 				continue;
 			} else if (src[1] == '.') {
 				if (!src[2]) {
@@ -1161,8 +1167,7 @@ int normalize_path_copy_len(char *dst, const char *src, int *prefix_len)
 				} else if (is_dir_sep(src[2])) {
 					/* (4) */
 					src += 3;
-					while (is_dir_sep(*src))
-						src++;
+					src = skip_slashes(src);
 					goto up_one;
 				}
 			}
@@ -1182,6 +1187,8 @@ int normalize_path_copy_len(char *dst, const char *src, int *prefix_len)
 
 	up_one:
 		/*
+		 * strip the last component
+		 *
 		 * dst0..dst is prefix portion, and dst[-1] is '/';
 		 * go up one level.
 		 */
-- 
2.43.0
Previous: Junio C Hamano
Message 6 of 6 in “path: refactor normalize_path_copy_len()”
  1. path: refactor normalize_path_copy_len()Pushkar Singh, Jan 29, 2026
  2. Junio C HamanoJan 29, 2026
  3. path: factor out skip_slashes() in normalize_path_copy_len()Pushkar Singh, Jan 30, 2026
  4. Pushkar SinghFeb 14, 2026
  5. Junio C HamanoFeb 17, 2026
  6. path: factor out skip_slashes() in normalize_path_copy_len()Pushkar Singh, Feb 21, 2026

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.