Skip to content

Commit

Permalink
Merge pull request #1 from dscho/git-for-windows
Browse files Browse the repository at this point in the history
Assorted fixes for Git for windows
  • Loading branch information
dscho committed Feb 22, 2015
2 parents bc1ecbf + aefedc0 commit 894e323
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 15 deletions.
2 changes: 1 addition & 1 deletion newlib/libc/stdlib/mbtowc_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ _DEFUN (__ascii_mbtowc, (r, pwc, s, n, charset, state),
if (n == 0)
return -2;

#ifdef __CYGWIN__
#ifdef STRICTLY_7BIT_ASCII
if ((wchar_t)*t >= 0x80)
{
r->_errno = EILSEQ;
Expand Down
2 changes: 1 addition & 1 deletion newlib/libc/stdlib/wctomb_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ _DEFUN (__ascii_wctomb, (r, s, wchar, charset, state),
if (s == NULL)
return 0;

#ifdef __CYGWIN__
#ifdef STRICTLY_7BIT_ASCII
if ((size_t)wchar >= 0x80)
#else
if ((size_t)wchar >= 0x100)
Expand Down
9 changes: 7 additions & 2 deletions winsup/cygwin/environ.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,12 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
bool calc_tl = !no_envblock;
/* Don't pass timezone environment to non-msys applications */
if (!keep_posix && ascii_strncasematch(*srcp, "TZ=", 3))
goto next1;
{
*dstp = (char *) cmalloc (HEAP_1_STR, strlen (*srcp) + 7);
strcpy (*dstp, "MSYS2_");
strcpy (*dstp + 6, *srcp);
goto next0;
}
/* Look for entries that require special attention */
for (unsigned i = 0; i < SPENVS_SIZE; i++)
if (!saw_spenv[i] && (*dstp = spenvs[i].retrieve (no_envblock, *srcp)))
Expand Down Expand Up @@ -1239,7 +1244,7 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
Note that this doesn't stop invalid strings without '=' in it
etc., but we're opting for speed here for now. Adding complete
checking would be pretty expensive. */
if (len == 1 || !*rest)
if (len == 1)
continue;

/* See if this entry requires posix->win32 conversion. */
Expand Down
6 changes: 6 additions & 0 deletions winsup/cygwin/how-to-debug-cygwin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,9 @@ set CYGWIN_DEBUG=cat.exe:gdb.exe
program will crash, probably in small_printf. At that point, a 'bt'
command should show you the offending call to strace_printf with the
improper format string.

9. Debug output without strace

If you cannot use gdb, or if the program behaves differently using strace
for whatever reason, you can still use the small_printf() function to
output debugging messages directly to stderr.
72 changes: 63 additions & 9 deletions winsup/cygwin/msys2_path_conv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void ppl_convert(const char** from, const char* to, char** dst, const char* dste


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

if (**to == *in_string) {
Expand Down Expand Up @@ -237,6 +237,7 @@ void find_end_of_rooted_path(const char** from, const char** to, int* in_string)
void sub_convert(const char** from, const char** to, char** dst, const char* dstend, int* in_string) {
const char* copy_from = *from;
path_type type = find_path_start_and_type(from, false, *to);
debug_printf("found type %d for path %s", type, copy_from);

if (type == POSIX_PATH_LIST) {
find_end_of_posix_list(to, in_string);
Expand Down Expand Up @@ -299,12 +300,6 @@ const char* convert(char *dst, size_t dstlen, const char *src) {
}
continue;
}

if (isspace(*srcit)) {
//sub_convert(&srcbeg, &srcit, &dstit, dstend, &in_string);
//srcbeg = srcit + 1;
break;
}
}

sub_convert(&srcbeg, &srcit, &dstit, dstend, &in_string);
Expand Down Expand Up @@ -340,8 +335,59 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en

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

if (!isalnum(*it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') {
return find_path_start_and_type(move(src, 1), true, end);
/* Let's not convert ~/.file to ~C:\msys64\.file */
if (*it == '~') {
skip_p2w:
*src = end;
return NONE;
}

/*
* Prevent Git's :file.txt and :/message syntax from beeing modified.
*/
if (*it == ':')
goto skip_p2w;

while (it != end && *it) {
switch (*it) {
case '`':
case '\'':
case '"':
case '*':
case '?':
case '[':
case ']':
goto skip_p2w;
case '/':
if (it + 1 < end && it[1] == '~')
goto skip_p2w;
break;
case ':':
// Avoid mangling IPv6 addresses
if (it + 1 < end && it[1] == ':')
goto skip_p2w;

// Leave Git's <rev>:./name syntax alone
if (it + 1 < end && it[1] == '.') {
if (it + 2 < end && it[2] == '/')
goto skip_p2w;
if (it + 3 < end && it[2] == '.' && it[3] == '/')
goto skip_p2w;
}
break;
case '@':
// Paths do not contain '@@'
if (it + 1 < end && it[1] == '@')
goto skip_p2w;
}
++it;
}
it = *src;

while (!isalnum(*it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') {
recurse = true;
it = ++*src;
if (it == end || *it == '\0') return NONE;
}

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

int starts_with_minus = 0;
int starts_with_minus_alpha = 0;
int only_dots = *it == '.';
int has_slashes = 0;
if (*it == '-') {
starts_with_minus = 1;
it += 1;
Expand Down Expand Up @@ -443,11 +491,17 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en
if (ch == '/' && *(it2 + 1) == '/') {
return URL;
} else {
if (!only_dots && !has_slashes)
goto skip_p2w;
return POSIX_PATH_LIST;
}
} else if (memchr(it2, '=', end - it) == NULL) {
return SIMPLE_WINDOWS_PATH;
}
} else if (ch != '.') {
only_dots = 0;
if (ch == '/' || ch == '\\')
has_slashes = 1;
}
}

Expand Down
4 changes: 2 additions & 2 deletions winsup/cygwin/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,11 @@ path_conv::check (const char *src, unsigned opt,
need_directory = 1;
*--tail = '\0';
}
/* Special case for "/" must set need_directory, without removing
/* Special case for "/" must not set need_directory, neither remove
trailing slash */
else if (tail == path_copy + 1 && isslash (tail[-1]))
{
need_directory = 1;
need_directory = 0;
}
path_end = tail;

Expand Down
4 changes: 4 additions & 0 deletions winsup/cygwin/strfuncs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,11 @@ sys_cp_mbstowcs (mbtowc_p f_mbtowc, const char *charset, wchar_t *dst,
to store them in a symmetric way. */
bytes = 1;
if (dst)
#ifdef STRICTLY_7BIT_ASCII
*ptr = L'\xf000' | *pmbs;
#else
*ptr = *pmbs;
#endif
memset (&ps, 0, sizeof ps);
}

Expand Down

4 comments on commit 894e323

@mingwandroid
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dscho Is there any way we can progress to avoid a fork, or are you planning to submit pull requests already?

@dscho
Copy link
Member Author

@dscho dscho commented on 894e323 Mar 4, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mingwandroid my plan is to release a Git for Windows 2.3.0 based on this work ASAP and then throw stuff your way. Hopefully you will like most (or all) of what I did, and if not, hopefully we'll find a good solution for everybody involved!

@mingwandroid
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dscho we'll definitely do what we can to accommodate your changes, I'm sure many are fine, but we need to make sure that the git path mangling alterations don't break other things, so we may need to come up with a way to enable them in that specific situation (e.g. if program is git.exe, or perl.exe called by git.exe etc, ironically, perl is already one of the toughest programs to please from a path mangling perspective and the sooner git doesn't need it the better); we can discuss this in detail after you get your release done.

@dscho
Copy link
Member Author

@dscho dscho commented on 894e323 Mar 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mingwandroid sounds good!

Please sign in to comment.