Skip to content

Commit 9c6b306

Browse files
committed
Merge pull request #1 from dscho/git-for-windows
Assorted fixes for Git for windows
2 parents 99e5afb + cf987ca commit 9c6b306

File tree

7 files changed

+88
-16
lines changed

7 files changed

+88
-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
@@ -1138,9 +1138,17 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
11381138
{
11391139
bool calc_tl = !no_envblock;
11401140
#ifdef __MSYS__
1141-
/* Don't pass timezone environment to non-msys applications */
1141+
/* Don't pass non-standard timezone to non-msys applications */
11421142
if (!keep_posix && ascii_strncasematch(*srcp, "TZ=", 3))
1143-
goto next1;
1143+
{
1144+
const char *v = *srcp + 3;
1145+
if (*v == ':')
1146+
goto next1;
1147+
for (; *v; v++)
1148+
if (!isalpha(*v) && !isdigit(*v) &&
1149+
*v != '-' && *v != '+' && *v != ':')
1150+
goto next1;
1151+
}
11441152
#endif
11451153
/* Look for entries that require special attention */
11461154
for (unsigned i = 0; i < SPENVS_SIZE; i++)
@@ -1245,7 +1253,7 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
12451253
Note that this doesn't stop invalid strings without '=' in it
12461254
etc., but we're opting for speed here for now. Adding complete
12471255
checking would be pretty expensive. */
1248-
if (len == 1 || !*rest)
1256+
if (len == 1)
12491257
continue;
12501258

12511259
/* 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: 63 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,59 @@ 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+
* Prevent Git's :file.txt and :/message syntax from beeing modified.
347+
*/
348+
if (*it == ':')
349+
goto skip_p2w;
350+
351+
while (it != end && *it) {
352+
switch (*it) {
353+
case '`':
354+
case '\'':
355+
case '"':
356+
case '*':
357+
case '?':
358+
case '[':
359+
case ']':
360+
goto skip_p2w;
361+
case '/':
362+
if (it + 1 < end && it[1] == '~')
363+
goto skip_p2w;
364+
break;
365+
case ':':
366+
// Avoid mangling IPv6 addresses
367+
if (it + 1 < end && it[1] == ':')
368+
goto skip_p2w;
369+
370+
// Leave Git's <rev>:./name syntax alone
371+
if (it + 1 < end && it[1] == '.') {
372+
if (it + 2 < end && it[2] == '/')
373+
goto skip_p2w;
374+
if (it + 3 < end && it[2] == '.' && it[3] == '/')
375+
goto skip_p2w;
376+
}
377+
break;
378+
case '@':
379+
// Paths do not contain '@@'
380+
if (it + 1 < end && it[1] == '@')
381+
goto skip_p2w;
382+
}
383+
++it;
384+
}
385+
it = *src;
386+
387+
while (!isalnum(*it) && !(0x80 & *it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') {
388+
recurse = true;
389+
it = ++*src;
390+
if (it == end || *it == '\0') return NONE;
345391
}
346392

347393
path_type result = NONE;
@@ -403,6 +449,8 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
403449

404450
int starts_with_minus = 0;
405451
int starts_with_minus_alpha = 0;
452+
int only_dots = *it == '.';
453+
int has_slashes = 0;
406454
if (*it == '-') {
407455
starts_with_minus = 1;
408456
it += 1;
@@ -443,11 +491,17 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
443491
if (ch == '/' && *(it2 + 1) == '/') {
444492
return URL;
445493
} else {
494+
if (!only_dots && !has_slashes)
495+
goto skip_p2w;
446496
return POSIX_PATH_LIST;
447497
}
448498
} else if (memchr(it2, '=', end - it) == NULL) {
449499
return SIMPLE_WINDOWS_PATH;
450500
}
501+
} else if (ch != '.') {
502+
only_dots = 0;
503+
if (ch == '/' || ch == '\\')
504+
has_slashes = 1;
451505
}
452506
}
453507

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)