Skip to content

Commit 1c1a3b3

Browse files
committed
Merge pull request #1 from dscho/git-for-windows
Assorted fixes for Git for windows
2 parents b7ebee4 + aea08ef commit 1c1a3b3

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
@@ -38,7 +38,7 @@ _DEFUN (__ascii_mbtowc, (r, pwc, s, n, state),
3838
if (n == 0)
3939
return -2;
4040

41-
#ifdef __CYGWIN__
41+
#ifdef STRICTLY_7BIT_ASCII
4242
if ((wchar_t)*t >= 0x80)
4343
{
4444
r->_errno = EILSEQ;

newlib/libc/stdlib/wctomb_r.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ _DEFUN (__ascii_wctomb, (r, s, wchar, state),
3131
if (s == NULL)
3232
return 0;
3333

34-
#ifdef __CYGWIN__
34+
#ifdef STRICTLY_7BIT_ASCII
3535
if ((size_t)wchar >= 0x80)
3636
#else
3737
if ((size_t)wchar >= 0x100)

winsup/cygwin/environ.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,15 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
11471147
{
11481148
/* Don't pass timezone environment to non-msys applications */
11491149
if (ascii_strncasematch(*srcp, "TZ=", 3))
1150-
goto next1;
1150+
{
1151+
const char *v = *srcp + 3;
1152+
if (*v == ':')
1153+
goto next1;
1154+
for (; *v; v++)
1155+
if (!isalpha(*v) && !isdigit(*v) &&
1156+
*v != '-' && *v != '+' && *v != ':')
1157+
goto next1;
1158+
}
11511159
else if (ascii_strncasematch(*srcp, "MSYS2_ENV_CONV_EXCL=", 20))
11521160
{
11531161
msys2_env_conv_excl_env = (char*)alloca (strlen(&(*srcp)[20])+1);
@@ -1259,7 +1267,7 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
12591267
Note that this doesn't stop invalid strings without '=' in it
12601268
etc., but we're opting for speed here for now. Adding complete
12611269
checking would be pretty expensive. */
1262-
if (len == 1 || !*rest)
1270+
if (len == 1)
12631271
continue;
12641272

12651273
/* 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
@@ -632,7 +632,11 @@ sys_cp_mbstowcs (mbtowc_p f_mbtowc, wchar_t *dst, size_t dlen,
632632
to store them in a symmetric way. */
633633
bytes = 1;
634634
if (dst)
635+
#ifdef STRICTLY_7BIT_ASCII
635636
*ptr = L'\xf000' | *pmbs;
637+
#else
638+
*ptr = *pmbs;
639+
#endif
636640
memset (&ps, 0, sizeof ps);
637641
}
638642

0 commit comments

Comments
 (0)