Skip to content

Commit 2a1ae64

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fc5e90b commit 2a1ae64

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

read-cache.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,19 @@ struct cache_entry *make_empty_transient_cache_entry(size_t len)
844844
return xcalloc(1, cache_entry_size(len));
845845
}
846846

847+
enum verify_path_result {
848+
PATH_OK,
849+
PATH_INVALID,
850+
PATH_DIR_WITH_SEP,
851+
};
852+
853+
static enum verify_path_result verify_path_internal(const char *, unsigned);
854+
855+
int verify_path(const char *path, unsigned mode)
856+
{
857+
return verify_path_internal(path, mode) != PATH_INVALID;
858+
}
859+
847860
struct cache_entry *make_cache_entry(struct index_state *istate,
848861
unsigned int mode,
849862
const struct object_id *oid,
@@ -985,60 +998,62 @@ static int verify_dotfile(const char *rest, unsigned mode)
985998
return 1;
986999
}
9871000

988-
int verify_path(const char *path, unsigned mode)
1001+
static enum verify_path_result verify_path_internal(const char *path,
1002+
unsigned mode)
9891003
{
9901004
char c = 0;
9911005

9921006
if (has_dos_drive_prefix(path))
993-
return 0;
1007+
return PATH_INVALID;
9941008

9951009
if (!is_valid_path(path))
996-
return 0;
1010+
return PATH_INVALID;
9971011

9981012
goto inside;
9991013
for (;;) {
10001014
if (!c)
1001-
return 1;
1015+
return PATH_OK;
10021016
if (is_dir_sep(c)) {
10031017
inside:
10041018
if (protect_hfs) {
10051019

10061020
if (is_hfs_dotgit(path))
1007-
return 0;
1021+
return PATH_INVALID;
10081022
if (S_ISLNK(mode)) {
10091023
if (is_hfs_dotgitmodules(path))
1010-
return 0;
1024+
return PATH_INVALID;
10111025
}
10121026
}
10131027
if (protect_ntfs) {
10141028
#ifdef GIT_WINDOWS_NATIVE
10151029
if (c == '\\')
1016-
return 0;
1030+
return PATH_INVALID;
10171031
#endif
10181032
if (is_ntfs_dotgit(path))
1019-
return 0;
1033+
return PATH_INVALID;
10201034
if (S_ISLNK(mode)) {
10211035
if (is_ntfs_dotgitmodules(path))
1022-
return 0;
1036+
return PATH_INVALID;
10231037
}
10241038
}
10251039

10261040
c = *path++;
10271041
if ((c == '.' && !verify_dotfile(path, mode)) ||
10281042
is_dir_sep(c))
1029-
return 0;
1043+
return PATH_INVALID;
10301044
/*
10311045
* allow terminating directory separators for
10321046
* sparse directory entries.
10331047
*/
10341048
if (c == '\0')
1035-
return S_ISDIR(mode);
1049+
return S_ISDIR(mode) ? PATH_DIR_WITH_SEP :
1050+
PATH_INVALID;
10361051
} else if (c == '\\' && protect_ntfs) {
10371052
if (is_ntfs_dotgit(path))
1038-
return 0;
1053+
return PATH_INVALID;
10391054
if (S_ISLNK(mode)) {
10401055
if (is_ntfs_dotgitmodules(path))
1041-
return 0;
1056+
return PATH_INVALID;
10421057
}
10431058
}
10441059

0 commit comments

Comments
 (0)