mirror of
https://github.com/git/git.git
synced 2026-03-15 03:00:07 +01:00
Merge branch 'ef/maint-win-verify-path' into next
* ef/maint-win-verify-path: verify_path: consider dos drive prefix real_path: do not assume '/' is the path seperator A Windows path starting with a backslash is absolute
This commit is contained in:
@@ -40,7 +40,7 @@ const char *real_path(const char *path)
|
||||
|
||||
while (depth--) {
|
||||
if (!is_directory(buf)) {
|
||||
char *last_slash = strrchr(buf, '/');
|
||||
char *last_slash = find_last_dir_sep(buf);
|
||||
if (last_slash) {
|
||||
*last_slash = '\0';
|
||||
last_elem = xstrdup(last_slash + 1);
|
||||
@@ -65,7 +65,7 @@ const char *real_path(const char *path)
|
||||
if (len + strlen(last_elem) + 2 > PATH_MAX)
|
||||
die ("Too long path name: '%s/%s'",
|
||||
buf, last_elem);
|
||||
if (len && buf[len-1] != '/')
|
||||
if (len && !is_dir_sep(buf[len-1]))
|
||||
buf[len++] = '/';
|
||||
strcpy(buf + len, last_elem);
|
||||
free(last_elem);
|
||||
|
||||
2
cache.h
2
cache.h
@@ -747,7 +747,7 @@ extern char *expand_user_path(const char *path);
|
||||
char *enter_repo(char *path, int strict);
|
||||
static inline int is_absolute_path(const char *path)
|
||||
{
|
||||
return path[0] == '/' || has_dos_drive_prefix(path);
|
||||
return is_dir_sep(path[0]) || has_dos_drive_prefix(path);
|
||||
}
|
||||
int is_directory(const char *);
|
||||
const char *real_path(const char *path);
|
||||
|
||||
@@ -300,6 +300,15 @@ int winansi_fprintf(FILE *stream, const char *format, ...) __attribute__((format
|
||||
|
||||
#define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':')
|
||||
#define is_dir_sep(c) ((c) == '/' || (c) == '\\')
|
||||
static inline char *mingw_find_last_dir_sep(const char *path)
|
||||
{
|
||||
char *ret = NULL;
|
||||
for (; *path; ++path)
|
||||
if (is_dir_sep(*path))
|
||||
ret = (char *)path;
|
||||
return ret;
|
||||
}
|
||||
#define find_last_dir_sep mingw_find_last_dir_sep
|
||||
#define PATH_SEP ';'
|
||||
#define PRIuMAX "I64u"
|
||||
|
||||
|
||||
@@ -215,6 +215,10 @@ extern char *gitbasename(char *);
|
||||
#define is_dir_sep(c) ((c) == '/')
|
||||
#endif
|
||||
|
||||
#ifndef find_last_dir_sep
|
||||
#define find_last_dir_sep(path) strrchr(path, '/')
|
||||
#endif
|
||||
|
||||
#if __HP_cc >= 61000
|
||||
#define NORETURN __attribute__((noreturn))
|
||||
#define NORETURN_PTR
|
||||
|
||||
@@ -753,11 +753,14 @@ int verify_path(const char *path)
|
||||
{
|
||||
char c;
|
||||
|
||||
if (has_dos_drive_prefix(path))
|
||||
return 0;
|
||||
|
||||
goto inside;
|
||||
for (;;) {
|
||||
if (!c)
|
||||
return 1;
|
||||
if (c == '/') {
|
||||
if (is_dir_sep(c)) {
|
||||
inside:
|
||||
c = *path++;
|
||||
switch (c) {
|
||||
|
||||
Reference in New Issue
Block a user