Skip to content

Commit 2313e14

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
Merge pull request #1 from dscho/git-for-windows
Assorted fixes for Git for windows
2 parents 11f1b63 + dcdda6e commit 2313e14

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
@@ -200,7 +200,7 @@ void ppl_convert(const char** from, const char* to, char** dst, const char* dste
200200

201201

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

206206
if (**to == *in_string) {
@@ -237,6 +237,7 @@ void find_end_of_rooted_path(const char** from, const char** to, int* in_string)
237237
void sub_convert(const char** from, const char** to, char** dst, const char* dstend, int* in_string) {
238238
const char* copy_from = *from;
239239
path_type type = find_path_start_and_type(from, false, *to);
240+
debug_printf("found type %d for path %s", type, copy_from);
240241

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

311306
sub_convert(&srcbeg, &srcit, &dstit, dstend, &in_string);
@@ -345,8 +340,67 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
345340

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

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

352406
path_type result = NONE;
@@ -408,6 +462,8 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
408462

409463
int starts_with_minus = 0;
410464
int starts_with_minus_alpha = 0;
465+
int only_dots = *it == '.';
466+
int has_slashes = 0;
411467
if (*it == '-') {
412468
starts_with_minus = 1;
413469
it += 1;
@@ -451,11 +507,17 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
451507
if (ch == '/' && *(it2 + 1) == '/') {
452508
return URL;
453509
} else {
510+
if (!only_dots && !has_slashes)
511+
goto skip_p2w;
454512
return POSIX_PATH_LIST;
455513
}
456514
} else if (memchr(it2, '=', end - it) == NULL) {
457515
return SIMPLE_WINDOWS_PATH;
458516
}
517+
} else if (ch != '.') {
518+
only_dots = 0;
519+
if (ch == '/' || ch == '\\')
520+
has_slashes = 1;
459521
}
460522
}
461523

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)