@@ -1766,14 +1766,14 @@ static bool verify_component(
17661766 if (flags & GIT_PATH_REJECT_DOT_GIT_HFS ) {
17671767 if (!verify_dotgit_hfs (component , len ))
17681768 return false;
1769- if (S_ISLNK (mode ) && git_path_is_hfs_dotgit_modules (component , len ))
1769+ if (S_ISLNK (mode ) && git_path_is_gitfile (component , len , GIT_PATH_GITFILE_GITMODULES , GIT_PATH_FS_HFS ))
17701770 return false;
17711771 }
17721772
17731773 if (flags & GIT_PATH_REJECT_DOT_GIT_NTFS ) {
17741774 if (!verify_dotgit_ntfs (repo , component , len ))
17751775 return false;
1776- if (S_ISLNK (mode ) && git_path_is_ntfs_dotgit_modules (component , len ))
1776+ if (S_ISLNK (mode ) && git_path_is_gitfile (component , len , GIT_PATH_GITFILE_GITMODULES , GIT_PATH_FS_NTFS ))
17771777 return false;
17781778 }
17791779
@@ -1872,64 +1872,40 @@ int git_path_normalize_slashes(git_buf *out, const char *path)
18721872 return 0 ;
18731873}
18741874
1875- static int verify_dotgit_generic (const char * name , size_t len , const char * dotgit_name , size_t dotgit_len , const char * shortname_pfix )
1876- {
1877- if (!verify_dotgit_ntfs_generic (name , len , dotgit_name , dotgit_len , shortname_pfix ))
1878- return false;
1879-
1880- return verify_dotgit_hfs_generic (name , len , dotgit_name , dotgit_len );
1881- }
1882-
1883- int git_path_is_ntfs_dotgit_modules (const char * name , size_t len )
1884- {
1885- return !verify_dotgit_ntfs_generic (name , len , "gitmodules" , CONST_STRLEN ("gitmodules" ), "gi7eba" );
1886- }
1887-
1888- int git_path_is_hfs_dotgit_modules (const char * name , size_t len )
1889- {
1890- return !verify_dotgit_hfs_generic (name , len , "gitmodules" , CONST_STRLEN ("gitmodules" ));
1891- }
1892-
1893- int git_path_is_dotgit_modules (const char * name , size_t len )
1894- {
1895- if (git_path_is_hfs_dotgit_modules (name , len ))
1896- return 1 ;
1897-
1898- return git_path_is_ntfs_dotgit_modules (name , len );
1899- }
1900-
1901- int git_path_is_ntfs_dotgit_ignore (const char * name , size_t len )
1902- {
1903- return !verify_dotgit_ntfs_generic (name , len , "gitignore" , CONST_STRLEN ("gitignore" ), "gi250a" );
1904- }
1875+ static const struct {
1876+ const char * file ;
1877+ const char * hash ;
1878+ size_t filelen ;
1879+ } gitfiles [] = {
1880+ { "gitignore" , "gi250a" , CONST_STRLEN ("gitignore" ) },
1881+ { "gitmodules" , "gi7eba" , CONST_STRLEN ("gitmodules" ) },
1882+ { "gitattributes" , "gi7d29" , CONST_STRLEN ("gitattributes" ) }
1883+ };
19051884
1906- int git_path_is_hfs_dotgit_ignore (const char * name , size_t len )
1885+ extern int git_path_is_gitfile (const char * path , size_t pathlen , git_path_gitfile gitfile , git_path_fs fs )
19071886{
1908- return !verify_dotgit_hfs_generic (name , len , "gitignore" , CONST_STRLEN ("gitignore" ));
1909- }
1910-
1911- int git_path_is_dotgit_ignore (const char * name , size_t len )
1912- {
1913- if (git_path_is_hfs_dotgit_ignore (name , len ))
1914- return 1 ;
1915-
1916- return git_path_is_ntfs_dotgit_ignore (name , len );
1917- }
1887+ const char * file , * hash ;
1888+ size_t filelen ;
19181889
1919- int git_path_is_hfs_dotgit_attributes (const char * name , size_t len )
1920- {
1921- return !verify_dotgit_hfs_generic (name , len , "gitattributes" , CONST_STRLEN ("gitattributes" ));
1922- }
1923-
1924- int git_path_is_ntfs_dotgit_attributes (const char * name , size_t len )
1925- {
1926- return !verify_dotgit_ntfs_generic (name , len , "gitattributes" , CONST_STRLEN ("gitattributes" ), "gi7d29" );
1927- }
1928-
1929- int git_path_is_dotgit_attributes (const char * name , size_t len )
1930- {
1931- if (git_path_is_hfs_dotgit_attributes (name , len ))
1932- return 1 ;
1890+ if (gitfile < 0 && gitfile >= ARRAY_SIZE (gitfiles )) {
1891+ giterr_set (GITERR_OS , "invalid gitfile for path validation" );
1892+ return -1 ;
1893+ }
19331894
1934- return git_path_is_ntfs_dotgit_attributes (name , len );
1895+ file = gitfiles [gitfile ].file ;
1896+ filelen = gitfiles [gitfile ].filelen ;
1897+ hash = gitfiles [gitfile ].hash ;
1898+
1899+ switch (fs ) {
1900+ case GIT_PATH_FS_GENERIC :
1901+ return !verify_dotgit_ntfs_generic (path , pathlen , file , filelen , hash ) ||
1902+ !verify_dotgit_hfs_generic (path , pathlen , file , filelen );
1903+ case GIT_PATH_FS_NTFS :
1904+ return !verify_dotgit_ntfs_generic (path , pathlen , file , filelen , hash );
1905+ case GIT_PATH_FS_HFS :
1906+ return !verify_dotgit_hfs_generic (path , pathlen , file , filelen );
1907+ default :
1908+ giterr_set (GITERR_OS , "invalid filesystem for path validation" );
1909+ return -1 ;
1910+ }
19351911}
0 commit comments