Skip to content

Commit 63f341b

Browse files
committed
Merge pull request #1 from dscho/git-for-windows
Assorted fixes for Git for windows
2 parents 4c9cfaf + c1be899 commit 63f341b

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
@@ -1147,9 +1147,17 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
11471147
{
11481148
bool calc_tl = !no_envblock;
11491149
#ifdef __MSYS__
1150-
/* Don't pass timezone environment to non-msys applications */
1150+
/* Don't pass non-standard timezone to non-msys applications */
11511151
if (!keep_posix && ascii_strncasematch(*srcp, "TZ=", 3))
1152-
goto next1;
1152+
{
1153+
const char *v = *srcp + 3;
1154+
if (*v == ':')
1155+
goto next1;
1156+
for (; *v; v++)
1157+
if (!isalpha(*v) && !isdigit(*v) &&
1158+
*v != '-' && *v != '+' && *v != ':')
1159+
goto next1;
1160+
}
11531161
#endif
11541162
/* Look for entries that require special attention */
11551163
for (unsigned i = 0; i < SPENVS_SIZE; i++)
@@ -1254,7 +1262,7 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
12541262
Note that this doesn't stop invalid strings without '=' in it
12551263
etc., but we're opting for speed here for now. Adding complete
12561264
checking would be pretty expensive. */
1257-
if (len == 1 || !*rest)
1265+
if (len == 1)
12581266
continue;
12591267

12601268
/* 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);
@@ -299,12 +300,6 @@ const char* convert(char *dst, size_t dstlen, const char *src) {
299300
}
300301
continue;
301302
}
302-
303-
if (isspace(*srcit)) {
304-
//sub_convert(&srcbeg, &srcit, &dstit, dstend, &in_string);
305-
//srcbeg = srcit + 1;
306-
break;
307-
}
308303
}
309304

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

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

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

347401
path_type result = NONE;
@@ -403,6 +457,8 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
403457

404458
int starts_with_minus = 0;
405459
int starts_with_minus_alpha = 0;
460+
int only_dots = *it == '.';
461+
int has_slashes = 0;
406462
if (*it == '-') {
407463
starts_with_minus = 1;
408464
it += 1;
@@ -443,11 +499,17 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
443499
if (ch == '/' && *(it2 + 1) == '/') {
444500
return URL;
445501
} else {
502+
if (!only_dots && !has_slashes)
503+
goto skip_p2w;
446504
return POSIX_PATH_LIST;
447505
}
448506
} else if (memchr(it2, '=', end - it) == NULL) {
449507
return SIMPLE_WINDOWS_PATH;
450508
}
509+
} else if (ch != '.') {
510+
only_dots = 0;
511+
if (ch == '/' || ch == '\\')
512+
has_slashes = 1;
451513
}
452514
}
453515

winsup/cygwin/path.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,11 +728,11 @@ path_conv::check (const char *src, unsigned opt,
728728
need_directory = 1;
729729
*--tail = '\0';
730730
}
731-
/* Special case for "/" must set need_directory, without removing
731+
/* Special case for "/" must not set need_directory, neither remove
732732
trailing slash */
733733
else if (tail == path_copy + 1 && isslash (tail[-1]))
734734
{
735-
need_directory = 1;
735+
need_directory = 0;
736736
}
737737
path_end = tail;
738738

winsup/cygwin/strfuncs.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,11 @@ sys_cp_mbstowcs (mbtowc_p f_mbtowc, const char *charset, wchar_t *dst,
618618
to store them in a symmetric way. */
619619
bytes = 1;
620620
if (dst)
621+
#ifdef STRICTLY_7BIT_ASCII
621622
*ptr = L'\xf000' | *pmbs;
623+
#else
624+
*ptr = *pmbs;
625+
#endif
622626
memset (&ps, 0, sizeof ps);
623627
}
624628

0 commit comments

Comments
 (0)