read-cache: add verify_path_internal()
Turn verify_path() into an internal function that distinguishes between valid paths and those with trailing directory separators and rename it to verify_path_internal(). Provide a wrapper with the old behavior under the old name. No functional change intended. The new function will be used in the next patch. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
fc5e90b848
commit
2a1ae649a4
41
read-cache.c
41
read-cache.c
|
@ -844,6 +844,19 @@ struct cache_entry *make_empty_transient_cache_entry(size_t len)
|
||||||
return xcalloc(1, cache_entry_size(len));
|
return xcalloc(1, cache_entry_size(len));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum verify_path_result {
|
||||||
|
PATH_OK,
|
||||||
|
PATH_INVALID,
|
||||||
|
PATH_DIR_WITH_SEP,
|
||||||
|
};
|
||||||
|
|
||||||
|
static enum verify_path_result verify_path_internal(const char *, unsigned);
|
||||||
|
|
||||||
|
int verify_path(const char *path, unsigned mode)
|
||||||
|
{
|
||||||
|
return verify_path_internal(path, mode) != PATH_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
struct cache_entry *make_cache_entry(struct index_state *istate,
|
struct cache_entry *make_cache_entry(struct index_state *istate,
|
||||||
unsigned int mode,
|
unsigned int mode,
|
||||||
const struct object_id *oid,
|
const struct object_id *oid,
|
||||||
|
@ -985,60 +998,62 @@ static int verify_dotfile(const char *rest, unsigned mode)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int verify_path(const char *path, unsigned mode)
|
static enum verify_path_result verify_path_internal(const char *path,
|
||||||
|
unsigned mode)
|
||||||
{
|
{
|
||||||
char c = 0;
|
char c = 0;
|
||||||
|
|
||||||
if (has_dos_drive_prefix(path))
|
if (has_dos_drive_prefix(path))
|
||||||
return 0;
|
return PATH_INVALID;
|
||||||
|
|
||||||
if (!is_valid_path(path))
|
if (!is_valid_path(path))
|
||||||
return 0;
|
return PATH_INVALID;
|
||||||
|
|
||||||
goto inside;
|
goto inside;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (!c)
|
if (!c)
|
||||||
return 1;
|
return PATH_OK;
|
||||||
if (is_dir_sep(c)) {
|
if (is_dir_sep(c)) {
|
||||||
inside:
|
inside:
|
||||||
if (protect_hfs) {
|
if (protect_hfs) {
|
||||||
|
|
||||||
if (is_hfs_dotgit(path))
|
if (is_hfs_dotgit(path))
|
||||||
return 0;
|
return PATH_INVALID;
|
||||||
if (S_ISLNK(mode)) {
|
if (S_ISLNK(mode)) {
|
||||||
if (is_hfs_dotgitmodules(path))
|
if (is_hfs_dotgitmodules(path))
|
||||||
return 0;
|
return PATH_INVALID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (protect_ntfs) {
|
if (protect_ntfs) {
|
||||||
#ifdef GIT_WINDOWS_NATIVE
|
#ifdef GIT_WINDOWS_NATIVE
|
||||||
if (c == '\\')
|
if (c == '\\')
|
||||||
return 0;
|
return PATH_INVALID;
|
||||||
#endif
|
#endif
|
||||||
if (is_ntfs_dotgit(path))
|
if (is_ntfs_dotgit(path))
|
||||||
return 0;
|
return PATH_INVALID;
|
||||||
if (S_ISLNK(mode)) {
|
if (S_ISLNK(mode)) {
|
||||||
if (is_ntfs_dotgitmodules(path))
|
if (is_ntfs_dotgitmodules(path))
|
||||||
return 0;
|
return PATH_INVALID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c = *path++;
|
c = *path++;
|
||||||
if ((c == '.' && !verify_dotfile(path, mode)) ||
|
if ((c == '.' && !verify_dotfile(path, mode)) ||
|
||||||
is_dir_sep(c))
|
is_dir_sep(c))
|
||||||
return 0;
|
return PATH_INVALID;
|
||||||
/*
|
/*
|
||||||
* allow terminating directory separators for
|
* allow terminating directory separators for
|
||||||
* sparse directory entries.
|
* sparse directory entries.
|
||||||
*/
|
*/
|
||||||
if (c == '\0')
|
if (c == '\0')
|
||||||
return S_ISDIR(mode);
|
return S_ISDIR(mode) ? PATH_DIR_WITH_SEP :
|
||||||
|
PATH_INVALID;
|
||||||
} else if (c == '\\' && protect_ntfs) {
|
} else if (c == '\\' && protect_ntfs) {
|
||||||
if (is_ntfs_dotgit(path))
|
if (is_ntfs_dotgit(path))
|
||||||
return 0;
|
return PATH_INVALID;
|
||||||
if (S_ISLNK(mode)) {
|
if (S_ISLNK(mode)) {
|
||||||
if (is_ntfs_dotgitmodules(path))
|
if (is_ntfs_dotgitmodules(path))
|
||||||
return 0;
|
return PATH_INVALID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue