dir API: add a generalized path_match_flags() function
Add a path_match_flags() function and have the two sets of
starts_with_dot_{,dot_}slash() functions added in
63e95beb08 (submodule: port resolve_relative_url from shell to C,
2016-04-15) and a2b26ffb1a (fsck: convert gitmodules url to URL
passed to curl, 2020-04-18) be thin wrappers for it.
As the latter of those notes the fsck version was copied from the
initial builtin/submodule--helper.c version.
Since the code added in a2b26ffb1a was doing really doing the same as
win32_is_dir_sep() added in 1cadad6f65 (git clone <url>
C:\cygwin\home\USER\repo' is working (again), 2018-12-15) let's move
the latter to git-compat-util.h is a is_xplatform_dir_sep(). We can
then call either it or the platform-specific is_dir_sep() from this
new function.
Let's likewise change code in various other places that was hardcoding
checks for "'/' || '\\'" with the new is_xplatform_dir_sep(). As can
be seen in those callers some of them still concern themselves with
':' (Mac OS classic?), but let's leave the question of whether that
should be consolidated for some other time.
As we expect to make wider use of the "native" case in the future,
define and use two starts_with_dot_{,dot_}slash_native() convenience
wrappers. This makes the diff in builtin/submodule--helper.c much
smaller.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
86f4e31298
commit
9fd512c8d6
@ -204,17 +204,17 @@ int check_submodule_name(const char *name)
|
||||
return -1;
|
||||
|
||||
/*
|
||||
* Look for '..' as a path component. Check both '/' and '\\' as
|
||||
* Look for '..' as a path component. Check is_xplatform_dir_sep() as
|
||||
* separators rather than is_dir_sep(), because we want the name rules
|
||||
* to be consistent across platforms.
|
||||
*/
|
||||
goto in_component; /* always start inside component */
|
||||
while (*name) {
|
||||
char c = *name++;
|
||||
if (c == '/' || c == '\\') {
|
||||
if (is_xplatform_dir_sep(c)) {
|
||||
in_component:
|
||||
if (name[0] == '.' && name[1] == '.' &&
|
||||
(!name[2] || name[2] == '/' || name[2] == '\\'))
|
||||
(!name[2] || is_xplatform_dir_sep(name[2])))
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user