Skip to content

Commit c2369bd

Browse files
czawadkagitster
authored andcommitted
Windows: allow using UNC path for git repository
[efl: moved MinGW-specific part to compat/] [jes: fixed compilation on non-Windows] Eric Sunshine fixed mingw_offset_1st_component() to return consistently "foo" for UNC "//machine/share/foo", cf http://groups.google.com/group/msysgit/browse_thread/thread/c0af578549b5dda0 Author: Eric Sunshine <[email protected]> Signed-off-by: Cezary Zawadka <[email protected]> Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Erik Faye-Lund <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Stepan Kasal <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eea5913 commit c2369bd

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

cache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,6 @@ int normalize_path_copy(char *dst, const char *src);
781781
int longest_ancestor_length(const char *path, struct string_list *prefixes);
782782
char *strip_path_suffix(const char *path, const char *suffix);
783783
int daemon_avoid_alias(const char *path);
784-
int offset_1st_component(const char *path);
785784

786785
/* object replacement */
787786
#define LOOKUP_REPLACE_OBJECT 1

compat/mingw.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,3 +1823,27 @@ pid_t waitpid(pid_t pid, int *status, int options)
18231823
errno = EINVAL;
18241824
return -1;
18251825
}
1826+
1827+
int mingw_offset_1st_component(const char *path)
1828+
{
1829+
int offset = 0;
1830+
if (has_dos_drive_prefix(path))
1831+
offset = 2;
1832+
1833+
/* unc paths */
1834+
else if (is_dir_sep(path[0]) && is_dir_sep(path[1])) {
1835+
1836+
/* skip server name */
1837+
char *pos = strpbrk(path + 2, "\\/");
1838+
if (!pos)
1839+
return 0; /* Error: malformed unc path */
1840+
1841+
do {
1842+
pos++;
1843+
} while (*pos && !is_dir_sep(*pos));
1844+
1845+
offset = pos - path;
1846+
}
1847+
1848+
return offset + is_dir_sep(path[offset]);
1849+
}

compat/mingw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ static inline char *mingw_find_last_dir_sep(const char *path)
339339
return ret;
340340
}
341341
#define find_last_dir_sep mingw_find_last_dir_sep
342+
int mingw_offset_1st_component(const char *path);
343+
#define offset_1st_component mingw_offset_1st_component
342344
#define PATH_SEP ';'
343345
#define PRIuMAX "I64u"
344346
#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)