Allow using UNC path for git repository

[efl: moved MinGW-specific part to compat/]

[jes: fixed compilation on non-Windows]

Signed-off-by: Cezary Zawadka <czawadka@gmail.com>
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Cezary Zawadka
2010-07-13 16:17:43 +02:00
committed by Pat Thoyts
parent 12ac16c63f
commit dba7984b59
5 changed files with 29 additions and 8 deletions

View File

@@ -751,7 +751,6 @@ int normalize_path_copy(char *dst, const char *src);
int longest_ancestor_length(const char *path, const char *prefix_list);
char *strip_path_suffix(const char *path, const char *suffix);
int daemon_avoid_alias(const char *path);
int offset_1st_component(const char *path);
/* Read and unpack a sha1 file into memory, write memory to a sha1 file */
extern int sha1_object_info(const unsigned char *, unsigned long *);

View File

@@ -1815,3 +1815,26 @@ const char *get_windows_home_directory()
return home_directory;
}
int mingw_offset_1st_component(const char *path)
{
if (has_dos_drive_prefix(path))
return 2 + is_dir_sep(path[2]);
/* unc paths */
if (is_dir_sep(path[0]) && is_dir_sep(path[1])) {
/* skip server name */
char *pos = strpbrk(path + 2, "\\/");
if (!pos)
return 0;
do {
pos++;
} while (*pos && !is_dir_sep(*pos));
return pos - path;
}
return is_dir_sep(path[0]);
}

View File

@@ -300,6 +300,8 @@ 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) == '\\')
int mingw_offset_1st_component(const char *path);
#define offset_1st_component mingw_offset_1st_component
#define PATH_SEP ';'
#define PRIuMAX "I64u"

View File

@@ -211,6 +211,10 @@ extern char *gitbasename(char *);
#define has_dos_drive_prefix(path) 0
#endif
#ifndef offset_1st_component
#define offset_1st_component(path) (is_dir_sep((path)[0]))
#endif
#ifndef is_dir_sep
#define is_dir_sep(c) ((c) == '/')
#endif

7
path.c
View File

@@ -655,10 +655,3 @@ int daemon_avoid_alias(const char *p)
}
}
}
int offset_1st_component(const char *path)
{
if (has_dos_drive_prefix(path))
return 2 + is_dir_sep(path[2]);
return is_dir_sep(path[0]);
}