aboutsummaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-03-03 11:08:12 -0800
committerJunio C Hamano <gitster@pobox.com>2026-03-03 11:08:12 -0800
commit07ecbfa8fee1bc0eaca9ab5fdd09337b4692910c (patch)
treeb63eea258f18b383b4427f516d82edd461258857 /path.c
parentd455602a4d43be6117a7fc45c4729e24b4ed6903 (diff)
parent40b30f245d57f89215f89c29b72e8b557f09b82a (diff)
downloadgit-07ecbfa8fee1bc0eaca9ab5fdd09337b4692910c.tar.xz
Merge branch 'ps/simplify-normalize-path-copy-len'
Code clean-up. * ps/simplify-normalize-path-copy-len: path: factor out skip_slashes() in normalize_path_copy_len()
Diffstat (limited to 'path.c')
-rw-r--r--path.c19
1 files 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.
*/