Merge branch 'jc/maint-simpler-common-prefix'
* jc/maint-simpler-common-prefix: common_prefix: simplify and fix scanning for prefixes
This commit is contained in:
commit
2c177a1ca1
26
dir.c
26
dir.c
@ -31,22 +31,22 @@ static int common_prefix(const char **pathspec)
|
|||||||
if (!slash)
|
if (!slash)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The first 'prefix' characters of 'path' are common leading
|
||||||
|
* path components among the pathspecs we have seen so far,
|
||||||
|
* including the trailing slash.
|
||||||
|
*/
|
||||||
prefix = slash - path + 1;
|
prefix = slash - path + 1;
|
||||||
while ((next = *++pathspec) != NULL) {
|
while ((next = *++pathspec) != NULL) {
|
||||||
int len = strlen(next);
|
int len, last_matching_slash = -1;
|
||||||
if (len >= prefix && !memcmp(path, next, prefix))
|
for (len = 0; len < prefix && next[len] == path[len]; len++)
|
||||||
|
if (next[len] == '/')
|
||||||
|
last_matching_slash = len;
|
||||||
|
if (len == prefix)
|
||||||
continue;
|
continue;
|
||||||
len = prefix - 1;
|
if (last_matching_slash < 0)
|
||||||
for (;;) {
|
return 0;
|
||||||
if (!len)
|
prefix = last_matching_slash + 1;
|
||||||
return 0;
|
|
||||||
if (next[--len] != '/')
|
|
||||||
continue;
|
|
||||||
if (memcmp(path, next, len+1))
|
|
||||||
continue;
|
|
||||||
prefix = len + 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return prefix;
|
return prefix;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user