Skip to content

Commit 6ee34cc

Browse files
committed
Merge pull request #1 from dscho/git-for-windows
Assorted fixes for Git for windows
2 parents d9cfaae + 5ae81b2 commit 6ee34cc

File tree

7 files changed

+96
-16
lines changed

7 files changed

+96
-16
lines changed

newlib/libc/stdlib/mbtowc_r.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ _DEFUN (__ascii_mbtowc, (r, pwc, s, n, charset, state),
4848
if (n == 0)
4949
return -2;
5050

51-
#ifdef __CYGWIN__
51+
#ifdef STRICTLY_7BIT_ASCII
5252
if ((wchar_t)*t >= 0x80)
5353
{
5454
r->_errno = EILSEQ;

newlib/libc/stdlib/wctomb_r.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ _DEFUN (__ascii_wctomb, (r, s, wchar, charset, state),
4141
if (s == NULL)
4242
return 0;
4343

44-
#ifdef __CYGWIN__
44+
#ifdef STRICTLY_7BIT_ASCII
4545
if ((size_t)wchar >= 0x80)
4646
#else
4747
if ((size_t)wchar >= 0x100)

winsup/cygwin/environ.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,9 +1142,17 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
11421142
{
11431143
bool calc_tl = !no_envblock;
11441144
#ifdef __MSYS__
1145-
/* Don't pass timezone environment to non-msys applications */
1145+
/* Don't pass non-standard timezone to non-msys applications */
11461146
if (!keep_posix && ascii_strncasematch(*srcp, "TZ=", 3))
1147-
goto next1;
1147+
{
1148+
const char *v = *srcp + 3;
1149+
if (*v == ':')
1150+
goto next1;
1151+
for (; *v; v++)
1152+
if (!isalpha(*v) && !isdigit(*v) &&
1153+
*v != '-' && *v != '+' && *v != ':')
1154+
goto next1;
1155+
}
11481156
#endif
11491157
/* Look for entries that require special attention */
11501158
for (unsigned i = 0; i < SPENVS_SIZE; i++)
@@ -1249,7 +1257,7 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
12491257
Note that this doesn't stop invalid strings without '=' in it
12501258
etc., but we're opting for speed here for now. Adding complete
12511259
checking would be pretty expensive. */
1252-
if (len == 1 || !*rest)
1260+
if (len == 1)
12531261
continue;
12541262

12551263
/* 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);
@@ -341,8 +336,67 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
341336

342337
if (*it == '\0' || it == end) return NONE;
343338

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

348402
path_type result = NONE;
@@ -404,6 +458,8 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
404458

405459
int starts_with_minus = 0;
406460
int starts_with_minus_alpha = 0;
461+
int only_dots = *it == '.';
462+
int has_slashes = 0;
407463
if (*it == '-') {
408464
starts_with_minus = 1;
409465
it += 1;
@@ -447,11 +503,17 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
447503
if (ch == '/' && *(it2 + 1) == '/') {
448504
return URL;
449505
} else {
506+
if (!only_dots && !has_slashes)
507+
goto skip_p2w;
450508
return POSIX_PATH_LIST;
451509
}
452510
} else if (memchr(it2, '=', end - it) == NULL) {
453511
return SIMPLE_WINDOWS_PATH;
454512
}
513+
} else if (ch != '.') {
514+
only_dots = 0;
515+
if (ch == '/' || ch == '\\')
516+
has_slashes = 1;
455517
}
456518
}
457519

winsup/cygwin/path.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,11 +733,11 @@ path_conv::check (const char *src, unsigned opt,
733733
need_directory = 1;
734734
*--tail = '\0';
735735
}
736-
/* Special case for "/" must set need_directory, without removing
736+
/* Special case for "/" must not set need_directory, neither remove
737737
trailing slash */
738738
else if (tail == path_copy + 1 && isslash (tail[-1]))
739739
{
740-
need_directory = 1;
740+
need_directory = 0;
741741
}
742742
path_end = tail;
743743

winsup/cygwin/strfuncs.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,11 @@ sys_cp_mbstowcs (mbtowc_p f_mbtowc, const char *charset, wchar_t *dst,
639639
to store them in a symmetric way. */
640640
bytes = 1;
641641
if (dst)
642+
#ifdef STRICTLY_7BIT_ASCII
642643
*ptr = L'\xf000' | *pmbs;
644+
#else
645+
*ptr = *pmbs;
646+
#endif
643647
memset (&ps, 0, sizeof ps);
644648
}
645649

0 commit comments

Comments
 (0)