Skip to content

Commit 612dfe0

Browse files
committed
Merge pull request #1 from dscho/git-for-windows
Assorted fixes for Git for windows
2 parents 6165109 + 1c8c0e1 commit 612dfe0

File tree

6 files changed

+93
-13
lines changed

6 files changed

+93
-13
lines changed

newlib/libc/stdlib/mbtowc_r.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ __ascii_mbtowc (struct _reent *r,
3636
if (n == 0)
3737
return -2;
3838

39-
#ifdef __CYGWIN__
39+
#ifdef STRICTLY_7BIT_ASCII
4040
if ((wchar_t)*t >= 0x80)
4141
{
4242
r->_errno = EILSEQ;

newlib/libc/stdlib/wctomb_r.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ __ascii_wctomb (struct _reent *r,
2929
if (s == NULL)
3030
return 0;
3131

32-
#ifdef __CYGWIN__
32+
#ifdef STRICTLY_7BIT_ASCII
3333
if ((size_t)wchar >= 0x80)
3434
#else
3535
if ((size_t)wchar >= 0x100)

winsup/cygwin/environ.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,15 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
11921192
{
11931193
/* Don't pass timezone environment to non-msys applications */
11941194
if (ascii_strncasematch(*srcp, "TZ=", 3))
1195-
goto next1;
1195+
{
1196+
const char *v = *srcp + 3;
1197+
if (*v == ':')
1198+
goto next1;
1199+
for (; *v; v++)
1200+
if (!isalpha(*v) && !isdigit(*v) &&
1201+
*v != '-' && *v != '+' && *v != ':')
1202+
goto next1;
1203+
}
11961204
else if (ascii_strncasematch(*srcp, "MSYS2_ENV_CONV_EXCL=", 20))
11971205
{
11981206
msys2_env_conv_excl_env = (char*)alloca (strlen(&(*srcp)[20])+1);
@@ -1304,7 +1312,7 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
13041312
Note that this doesn't stop invalid strings without '=' in it
13051313
etc., but we're opting for speed here for now. Adding complete
13061314
checking would be pretty expensive. */
1307-
if (len == 1 || !*rest)
1315+
if (len == 1)
13081316
continue;
13091317

13101318
/* See if this entry requires posix->win32 conversion. */

winsup/cygwin/how-to-debug-cygwin.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,9 @@ set CYGWIN_DEBUG=cat.exe:gdb.exe
126126
program will crash, probably in small_printf. At that point, a 'bt'
127127
command should show you the offending call to strace_printf with the
128128
improper format string.
129+
130+
9. Debug output without strace
131+
132+
If you cannot use gdb, or if the program behaves differently using strace
133+
for whatever reason, you can still use the small_printf() function to
134+
output debugging messages directly to stderr.

winsup/cygwin/msys2_path_conv.cc

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void ppl_convert(const char** from, const char* to, char** dst, const char* dste
201201

202202

203203
void find_end_of_posix_list(const char** to, int* in_string) {
204-
for (; **to != '\0' && (in_string ? (**to != *in_string) : **to != ' '); ++*to) {
204+
for (; **to != '\0' && (!in_string || **to != *in_string); ++*to) {
205205
}
206206

207207
if (**to == *in_string) {
@@ -238,6 +238,7 @@ void find_end_of_rooted_path(const char** from, const char** to, int* in_string)
238238
void sub_convert(const char** from, const char** to, char** dst, const char* dstend, int* in_string) {
239239
const char* copy_from = *from;
240240
path_type type = find_path_start_and_type(from, false, *to);
241+
debug_printf("found type %d for path %s", type, copy_from);
241242

242243
if (type == POSIX_PATH_LIST) {
243244
find_end_of_posix_list(to, in_string);
@@ -301,12 +302,6 @@ const char* convert(char *dst, size_t dstlen, const char *src) {
301302
}
302303
continue;
303304
}
304-
305-
if (isspace(*srcit)) {
306-
//sub_convert(&srcbeg, &srcit, &dstit, dstend, &in_string);
307-
//srcbeg = srcit + 1;
308-
break;
309-
}
310305
}
311306

312307
sub_convert(&srcbeg, &srcit, &dstit, dstend, &in_string);
@@ -346,8 +341,67 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
346341

347342
if (*it == '\0' || it == end) return NONE;
348343

349-
if (!isalnum(*it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') {
350-
return find_path_start_and_type(move(src, 1), true, end);
344+
/* Let's not convert ~/.file to ~C:\msys64\.file */
345+
if (*it == '~') {
346+
skip_p2w:
347+
*src = end;
348+
return NONE;
349+
}
350+
351+
/*
352+
* Skip path mangling when environment indicates it.
353+
*/
354+
const char *no_pathconv = getenv ("MSYS_NO_PATHCONV");
355+
356+
if (no_pathconv)
357+
goto skip_p2w;
358+
359+
/*
360+
* Prevent Git's :file.txt and :/message syntax from beeing modified.
361+
*/
362+
if (*it == ':')
363+
goto skip_p2w;
364+
365+
while (it != end && *it) {
366+
switch (*it) {
367+
case '`':
368+
case '\'':
369+
case '"':
370+
case '*':
371+
case '?':
372+
case '[':
373+
case ']':
374+
goto skip_p2w;
375+
case '/':
376+
if (it + 1 < end && it[1] == '~')
377+
goto skip_p2w;
378+
break;
379+
case ':':
380+
// Avoid mangling IPv6 addresses
381+
if (it + 1 < end && it[1] == ':')
382+
goto skip_p2w;
383+
384+
// Leave Git's <rev>:./name syntax alone
385+
if (it + 1 < end && it[1] == '.') {
386+
if (it + 2 < end && it[2] == '/')
387+
goto skip_p2w;
388+
if (it + 3 < end && it[2] == '.' && it[3] == '/')
389+
goto skip_p2w;
390+
}
391+
break;
392+
case '@':
393+
// Paths do not contain '@@'
394+
if (it + 1 < end && it[1] == '@')
395+
goto skip_p2w;
396+
}
397+
++it;
398+
}
399+
it = *src;
400+
401+
while (!isalnum(*it) && !(0x80 & *it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') {
402+
recurse = true;
403+
it = ++*src;
404+
if (it == end || *it == '\0') return NONE;
351405
}
352406

353407
path_type result = NONE;
@@ -409,6 +463,8 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
409463

410464
int starts_with_minus = 0;
411465
int starts_with_minus_alpha = 0;
466+
int only_dots = *it == '.';
467+
int has_slashes = 0;
412468
if (*it == '-') {
413469
starts_with_minus = 1;
414470
it += 1;
@@ -452,11 +508,17 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
452508
if (ch == '/' && *(it2 + 1) == '/') {
453509
return URL;
454510
} else {
511+
if (!only_dots && !has_slashes)
512+
goto skip_p2w;
455513
return POSIX_PATH_LIST;
456514
}
457515
} else if (memchr(it2, '=', end - it) == NULL) {
458516
return SIMPLE_WINDOWS_PATH;
459517
}
518+
} else if (ch != '.') {
519+
only_dots = 0;
520+
if (ch == '/' || ch == '\\')
521+
has_slashes = 1;
460522
}
461523
}
462524

winsup/cygwin/strfuncs.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,11 @@ sys_cp_mbstowcs (mbtowc_p f_mbtowc, wchar_t *dst, size_t dlen,
641641
to store them in a symmetric way. */
642642
bytes = 1;
643643
if (dst)
644+
#ifdef STRICTLY_7BIT_ASCII
644645
*ptr = L'\xf000' | *pmbs;
646+
#else
647+
*ptr = *pmbs;
648+
#endif
645649
memset (&ps, 0, sizeof ps);
646650
}
647651

0 commit comments

Comments
 (0)