public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Pushkar Singh <pushkarkumarsingh1970@gmail.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, peff@peff.net, pushkarkumarsingh1970@gmail.com
Subject: [PATCH v2] path: factor out skip_slashes() in normalize_path_copy_len()
Date: Fri, 30 Jan 2026 14:01:44 +0000	[thread overview]
Message-ID: <20260130140143.5579-2-pushkarkumarsingh1970@gmail.com> (raw)
In-Reply-To: <xmqqh5s4b66w.fsf@gitster.g>

Hi Junio,

Thanks for the detailed feedback.

This version keeps skip_slashes(), but drops handle_dot_component() and
restores the original control flow around the four dot-component cases.
The up_one logic is kept inline, with a short explanatory comment as
suggested.

Changes since v1:
  - Keep skip_slashes() helper.
  - Restore inline dot-component handling.
  - Remove handle_dot_component() helper.
  - Keep up_one logic inline and add a brief comment.

Thanks for the review.

Pushkar
---
 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


  reply	other threads:[~2026-01-30 14:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-29 14:54 [PATCH] path: refactor normalize_path_copy_len() Pushkar Singh
2026-01-29 18:54 ` Junio C Hamano
2026-01-30 14:01   ` Pushkar Singh [this message]
2026-02-14  9:13     ` [PATCH v2] path: factor out skip_slashes() in normalize_path_copy_len() Pushkar Singh
2026-02-17 18:27       ` Junio C Hamano
2026-02-21 11:05         ` [PATCH v3] " Pushkar Singh

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=20260130140143.5579-2-pushkarkumarsingh1970@gmail.com \
    --to=pushkarkumarsingh1970@gmail.com \
    --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