Skip to content

Commit 25d90d1

Browse files
committed
Merge branch 'tb/use-common-win32-pathfuncs-on-cygwin'
Cygwin update. * tb/use-common-win32-pathfuncs-on-cygwin: git clone <url> C:\cygwin\home\USER\repo' is working (again)
2 parents d95f610 + 1cadad6 commit 25d90d1

File tree

9 files changed

+54
-72
lines changed

9 files changed

+54
-72
lines changed

compat/cygwin.c

Lines changed: 0 additions & 19 deletions
This file was deleted.

compat/cygwin.h

Lines changed: 0 additions & 2 deletions
This file was deleted.

compat/mingw.c

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ static inline int needs_hiding(const char *path)
350350
return 0;
351351

352352
/* We cannot use basename(), as it would remove trailing slashes */
353-
mingw_skip_dos_drive_prefix((char **)&path);
353+
win32_skip_dos_drive_prefix((char **)&path);
354354
if (!*path)
355355
return 0;
356356

@@ -2275,33 +2275,6 @@ pid_t waitpid(pid_t pid, int *status, int options)
22752275
return -1;
22762276
}
22772277

2278-
int mingw_skip_dos_drive_prefix(char **path)
2279-
{
2280-
int ret = has_dos_drive_prefix(*path);
2281-
*path += ret;
2282-
return ret;
2283-
}
2284-
2285-
int mingw_offset_1st_component(const char *path)
2286-
{
2287-
char *pos = (char *)path;
2288-
2289-
/* unc paths */
2290-
if (!skip_dos_drive_prefix(&pos) &&
2291-
is_dir_sep(pos[0]) && is_dir_sep(pos[1])) {
2292-
/* skip server name */
2293-
pos = strpbrk(pos + 2, "\\/");
2294-
if (!pos)
2295-
return 0; /* Error: malformed unc path */
2296-
2297-
do {
2298-
pos++;
2299-
} while (*pos && !is_dir_sep(*pos));
2300-
}
2301-
2302-
return pos + is_dir_sep(*pos) - path;
2303-
}
2304-
23052278
int xutftowcsn(wchar_t *wcs, const char *utfs, size_t wcslen, int utflen)
23062279
{
23072280
int upos = 0, wpos = 0;

compat/mingw.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -443,32 +443,12 @@ HANDLE winansi_get_osfhandle(int fd);
443443
* git specific compatibility
444444
*/
445445

446-
#define has_dos_drive_prefix(path) \
447-
(isalpha(*(path)) && (path)[1] == ':' ? 2 : 0)
448-
int mingw_skip_dos_drive_prefix(char **path);
449-
#define skip_dos_drive_prefix mingw_skip_dos_drive_prefix
450-
static inline int mingw_is_dir_sep(int c)
451-
{
452-
return c == '/' || c == '\\';
453-
}
454-
#define is_dir_sep mingw_is_dir_sep
455-
static inline char *mingw_find_last_dir_sep(const char *path)
456-
{
457-
char *ret = NULL;
458-
for (; *path; ++path)
459-
if (is_dir_sep(*path))
460-
ret = (char *)path;
461-
return ret;
462-
}
463446
static inline void convert_slashes(char *path)
464447
{
465448
for (; *path; path++)
466449
if (*path == '\\')
467450
*path = '/';
468451
}
469-
#define find_last_dir_sep mingw_find_last_dir_sep
470-
int mingw_offset_1st_component(const char *path);
471-
#define offset_1st_component mingw_offset_1st_component
472452
#define PATH_SEP ';'
473453
extern char *mingw_query_user_email(void);
474454
#define query_user_email mingw_query_user_email

compat/win32/path-utils.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "../../git-compat-util.h"
2+
3+
int win32_skip_dos_drive_prefix(char **path)
4+
{
5+
int ret = has_dos_drive_prefix(*path);
6+
*path += ret;
7+
return ret;
8+
}
9+
10+
int win32_offset_1st_component(const char *path)
11+
{
12+
char *pos = (char *)path;
13+
14+
/* unc paths */
15+
if (!skip_dos_drive_prefix(&pos) &&
16+
is_dir_sep(pos[0]) && is_dir_sep(pos[1])) {
17+
/* skip server name */
18+
pos = strpbrk(pos + 2, "\\/");
19+
if (!pos)
20+
return 0; /* Error: malformed unc path */
21+
22+
do {
23+
pos++;
24+
} while (*pos && !is_dir_sep(*pos));
25+
}
26+
27+
return pos + is_dir_sep(*pos) - path;
28+
}

compat/win32/path-utils.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#define has_dos_drive_prefix(path) \
2+
(isalpha(*(path)) && (path)[1] == ':' ? 2 : 0)
3+
int win32_skip_dos_drive_prefix(char **path);
4+
#define skip_dos_drive_prefix win32_skip_dos_drive_prefix
5+
static inline int win32_is_dir_sep(int c)
6+
{
7+
return c == '/' || c == '\\';
8+
}
9+
#define is_dir_sep win32_is_dir_sep
10+
static inline char *win32_find_last_dir_sep(const char *path)
11+
{
12+
char *ret = NULL;
13+
for (; *path; ++path)
14+
if (is_dir_sep(*path))
15+
ret = (char *)path;
16+
return ret;
17+
}
18+
#define find_last_dir_sep win32_find_last_dir_sep
19+
int win32_offset_1st_component(const char *path);
20+
#define offset_1st_component win32_offset_1st_component

config.mak.uname

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ ifeq ($(uname_O),Cygwin)
187187
UNRELIABLE_FSTAT = UnfortunatelyYes
188188
OBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo
189189
MMAP_PREVENTS_DELETE = UnfortunatelyYes
190-
COMPAT_OBJS += compat/cygwin.o
190+
COMPAT_OBJS += compat/win32/path-utils.o
191191
FREAD_READS_DIRECTORIES = UnfortunatelyYes
192192
endif
193193
ifeq ($(uname_S),FreeBSD)
@@ -528,6 +528,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
528528
COMPAT_CFLAGS += -DNOGDI -Icompat -Icompat/win32
529529
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
530530
COMPAT_OBJS += compat/mingw.o compat/winansi.o \
531+
compat/win32/path-utils.o \
531532
compat/win32/pthread.o compat/win32/syslog.o \
532533
compat/win32/dirent.o
533534
BASIC_CFLAGS += -DWIN32 -DPROTECT_NTFS_DEFAULT=1

git-compat-util.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,11 @@
193193
#endif
194194

195195
#if defined(__CYGWIN__)
196-
#include "compat/cygwin.h"
196+
#include "compat/win32/path-utils.h"
197197
#endif
198198
#if defined(__MINGW32__)
199199
/* pull in Windows compatibility stuff */
200+
#include "compat/win32/path-utils.h"
200201
#include "compat/mingw.h"
201202
#elif defined(_MSC_VER)
202203
#include "compat/msvc.h"

t/t5601-clone.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ test_clone_url () {
487487
expect_ssh "$@"
488488
}
489489

490-
test_expect_success !MINGW 'clone c:temp is ssl' '
490+
test_expect_success !MINGW,!CYGWIN 'clone c:temp is ssl' '
491491
test_clone_url c:temp c temp
492492
'
493493

0 commit comments

Comments
 (0)