Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit b45b33f

Browse files
czawadkadscho
authored andcommitted
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 <[email protected]> Signed-off-by: Erik Faye-Lund <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 8a450db commit b45b33f

File tree

5 files changed

+30
-32
lines changed

5 files changed

+30
-32
lines changed

cache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,6 @@ int normalize_path_copy(char *dst, const char *src);
788788
int longest_ancestor_length(const char *path, struct string_list *prefixes);
789789
char *strip_path_suffix(const char *path, const char *suffix);
790790
int daemon_avoid_alias(const char *path);
791-
int offset_1st_component(const char *path);
792791

793792
/* object replacement */
794793
#define LOOKUP_REPLACE_OBJECT 1

compat/mingw.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,30 @@ const char *get_windows_home_directory(void)
19861986

19871987
return home_directory;
19881988
}
1989+
1990+
int mingw_offset_1st_component(const char *path)
1991+
{
1992+
if (has_dos_drive_prefix(path))
1993+
return 2 + is_dir_sep(path[2]);
1994+
1995+
/* unc paths */
1996+
if (is_dir_sep(path[0]) && is_dir_sep(path[1])) {
1997+
1998+
/* skip server name */
1999+
char *pos = strpbrk(path + 2, "\\/");
2000+
if (!pos)
2001+
return 0;
2002+
2003+
do {
2004+
pos++;
2005+
} while (*pos && !is_dir_sep(*pos));
2006+
2007+
return pos - path;
2008+
}
2009+
2010+
return is_dir_sep(path[0]);
2011+
}
2012+
19892013
int xutftowcsn(wchar_t *wcs, const char *utfs, size_t wcslen, int utflen)
19902014
{
19912015
int upos = 0, wpos = 0;
@@ -2175,27 +2199,3 @@ void mingw_startup()
21752199
/* initialize Unicode console */
21762200
winansi_init();
21772201
}
2178-
2179-
int mingw_offset_1st_component(const char *path)
2180-
{
2181-
int offset = 0;
2182-
if (has_dos_drive_prefix(path))
2183-
offset = 2;
2184-
2185-
/* unc paths */
2186-
else if (is_dir_sep(path[0]) && is_dir_sep(path[1])) {
2187-
2188-
/* skip server name */
2189-
char *pos = strpbrk(path + 2, "\\/");
2190-
if (!pos)
2191-
return 0; /* Error: malformed unc path */
2192-
2193-
do {
2194-
pos++;
2195-
} while (*pos && !is_dir_sep(*pos));
2196-
2197-
offset = pos - path;
2198-
}
2199-
2200-
return offset + is_dir_sep(path[offset]);
2201-
}

compat/mingw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ static inline char *mingw_find_last_dir_sep(const char *path)
348348
return ret;
349349
}
350350
#define find_last_dir_sep mingw_find_last_dir_sep
351+
int mingw_offset_1st_component(const char *path);
352+
#define offset_1st_component mingw_offset_1st_component
351353
#define PATH_SEP ';'
352354
#define PRIuMAX "I64u"
353355
#define PRId64 "I64d"

git-compat-util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ extern char *gitbasename(char *);
270270
#define has_dos_drive_prefix(path) 0
271271
#endif
272272

273+
#ifndef offset_1st_component
274+
#define offset_1st_component(path) (is_dir_sep((path)[0]))
275+
#endif
276+
273277
#ifndef is_dir_sep
274278
#define is_dir_sep(c) ((c) == '/')
275279
#endif

path.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -823,10 +823,3 @@ int daemon_avoid_alias(const char *p)
823823
}
824824
}
825825
}
826-
827-
int offset_1st_component(const char *path)
828-
{
829-
if (has_dos_drive_prefix(path))
830-
return 2 + is_dir_sep(path[2]);
831-
return is_dir_sep(path[0]);
832-
}

0 commit comments

Comments
 (0)