Skip to content

Commit ad52395

Browse files
committed
Merge pull request #1 from dscho/git-for-windows
Assorted fixes for Git for windows
2 parents c273e01 + 7f7e0cf commit ad52395

File tree

6 files changed

+86
-14
lines changed

6 files changed

+86
-14
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,11 +1339,11 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
13391339
Note that this doesn't stop invalid strings without '=' in it
13401340
etc., but we're opting for speed here for now. Adding complete
13411341
checking would be pretty expensive. */
1342-
if (len == 1 || !*rest)
1342+
if (len == 1)
13431343
continue;
13441344

13451345
/* See if this entry requires posix->win32 conversion. */
1346-
conv = getwinenv (*srcp, rest, &temp);
1346+
conv = !*rest ? NULL : getwinenv (*srcp, rest, &temp);
13471347
if (conv)
13481348
{
13491349
p = conv->native; /* Use win32 path */
@@ -1357,7 +1357,7 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
13571357
}
13581358
}
13591359
#ifdef __MSYS__
1360-
else if (!keep_posix) {
1360+
else if (!keep_posix && *rest) {
13611361
char *win_arg = arg_heuristic_with_exclusions
13621362
(*srcp, msys2_env_conv_excl_env, msys2_env_conv_excl_count);
13631363
debug_printf("WIN32_PATH is %s", win_arg);

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

202202

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

207207
if (**to == *in_string) {
@@ -238,6 +238,7 @@ void find_end_of_rooted_path(const char** from, const char** to, int* in_string)
238238
void sub_convert(const char** from, const char** to, char** dst, const char* dstend, int* in_string) {
239239
const char* copy_from = *from;
240240
path_type type = find_path_start_and_type(from, false, *to);
241+
debug_printf("found type %d for path %s", type, copy_from);
241242

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

312307
sub_convert(&srcbeg, &srcit, &dstit, dstend, &in_string);
@@ -346,8 +341,67 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
346341

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

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

353407
path_type result = NONE;
@@ -409,6 +463,8 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
409463

410464
int starts_with_minus = 0;
411465
int starts_with_minus_alpha = 0;
466+
int only_dots = *it == '.';
467+
int has_slashes = 0;
412468
if (*it == '-') {
413469
starts_with_minus = 1;
414470
it += 1;
@@ -452,11 +508,17 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
452508
if (ch == '/' && *(it2 + 1) == '/') {
453509
return URL;
454510
} else {
511+
if (!only_dots && !has_slashes)
512+
goto skip_p2w;
455513
return POSIX_PATH_LIST;
456514
}
457515
} else if (memchr(it2, '=', end - it) == NULL) {
458516
return SIMPLE_WINDOWS_PATH;
459517
}
518+
} else if (ch != '.') {
519+
only_dots = 0;
520+
if (ch == '/' || ch == '\\')
521+
has_slashes = 1;
460522
}
461523
}
462524

winsup/cygwin/strfuncs.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,11 @@ _sys_mbstowcs (mbtowc_p f_mbtowc, wchar_t *dst, size_t dlen, const char *src,
616616
to store them in a symmetric way. */
617617
bytes = 1;
618618
if (dst)
619+
#ifdef STRICTLY_7BIT_ASCII
619620
*ptr = L'\xf000' | *pmbs;
621+
#else
622+
*ptr = *pmbs;
623+
#endif
620624
memset (&ps, 0, sizeof ps);
621625
}
622626

0 commit comments

Comments
 (0)