mirror of
https://github.com/git/git.git
synced 2026-02-27 18:29:43 +00:00
Merge branch 'ps/simplify-normalize-path-copy-len' into jch
Code clean-up. * ps/simplify-normalize-path-copy-len: path: factor out skip_slashes() in normalize_path_copy_len()
This commit is contained in:
19
path.c
19
path.c
@@ -1111,6 +1111,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;
|
||||
@@ -1128,8 +1136,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;
|
||||
@@ -1149,8 +1156,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]) {
|
||||
@@ -1160,8 +1166,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;
|
||||
}
|
||||
}
|
||||
@@ -1181,6 +1186,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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user