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>
René Scharfe committed
Oct 7, 2021 at 22:31 UTC
2a1ae649a4c485b833d75cd5bb14b53ff9bae2c6
1 file changed
+28
-13
read-cache.c
+28
-13
@@ -844,6 +844,19 @@ struct cache_entry *make_empty_transient_cache_entry(size_t len)
844
return xcalloc(1, cache_entry_size(len));
845
}
846
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
+
860
struct cache_entry *make_cache_entry(struct index_state *istate,
861
unsigned int mode,
862
const struct object_id *oid,
@@ -985,60 +998,62 @@ static int verify_dotfile(const char *rest, unsigned mode)
998
return 1;
999
}
1000
988
-int verify_path(const char *path, unsigned mode)
1001
+static enum verify_path_result verify_path_internal(const char *path,
1002
+ unsigned mode)
1003
{
1004
char c = 0;
1005
1006
if (has_dos_drive_prefix(path))
993
- return 0;
1007
+ return PATH_INVALID;
1008
1009
if (!is_valid_path(path))
996
- return 0;
1010
+ return PATH_INVALID;
1011
1012
goto inside;
1013
for (;;) {
1014
if (!c)
1001
- return 1;
1015
+ return PATH_OK;
1016
if (is_dir_sep(c)) {
1017
inside:
1018
if (protect_hfs) {
1019
1020
if (is_hfs_dotgit(path))
1007
- return 0;
1021
+ return PATH_INVALID;
1022
if (S_ISLNK(mode)) {
1023
if (is_hfs_dotgitmodules(path))
1010
- return 0;
1024
+ return PATH_INVALID;
1025
}
1026
}
1027
if (protect_ntfs) {
1028
#ifdef GIT_WINDOWS_NATIVE
1029
if (c == '\\')
1016
- return 0;
1030
+ return PATH_INVALID;
1031
#endif
1032
if (is_ntfs_dotgit(path))
1019
- return 0;
1033
+ return PATH_INVALID;
1034
if (S_ISLNK(mode)) {
1035
if (is_ntfs_dotgitmodules(path))
1022
- return 0;
1036
+ return PATH_INVALID;
1037
}
1038
}
1039
1040
c = *path++;
1041
if ((c == '.' && !verify_dotfile(path, mode)) ||
1042
is_dir_sep(c))
1029
- return 0;
1043
+ return PATH_INVALID;
1044
/*
1045
* allow terminating directory separators for
1046
* sparse directory entries.
1047
*/
1048
if (c == '\0')
1035
- return S_ISDIR(mode);
1049
+ return S_ISDIR(mode) ? PATH_DIR_WITH_SEP :
1050
+ PATH_INVALID;
1051
} else if (c == '\\' && protect_ntfs) {
1052
if (is_ntfs_dotgit(path))
1038
- return 0;
1053
+ return PATH_INVALID;
1054
if (S_ISLNK(mode)) {
1055
if (is_ntfs_dotgitmodules(path))
1041
- return 0;
1056
+ return PATH_INVALID;
1057
}
1058
}
1059