-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve handling of commands in Git.pm on native Windows #1604
Improve handling of commands in Git.pm on native Windows #1604
Conversation
@ColMelvin Looks sensible. The patches will need the 'sign off' added (can be force pushed to update). |
This looks sane enough. I'm not a Windows user, so I can't speak to the patches' functionality, but I don't see anything obviously wrong. Note that Git expects things to run on Perl 5.8. I'm not sure about why the ActiveState pipe wrapper was needed in the first place, but assuming the native pipe implementation can run on 5.8 on Windows, that should be fine. |
Is there anyone from @ActiveState in the community? I tried searching for ActiveState Perl 5.8 but was unable to find any Community Editions that I could test with. Failing that, I'd like to know why an untested It is my sincere hope that Perl 5.8 solved the problem that Maintaining compatibility with older versions is important to me. Indeed, it's part of why I separated the fixes into two different commits, in case the However, this all requires access to older Perl versions on Windows that I'm having difficulty obtaining. |
@ColMelvin thank you for your contribution. Could you please sign off on the patches, too? See https://github.com/probot/dco#how-it-works for details. |
Also, I am too little of a Perl expert to review these patches. So after you add your Signed-off-by lines, I would like to take these upstream. Please note that core Git requires your real name in those Signed-off-by lines, to allow for future conversations about your patches. As to ActiveState Perl: I have not heard in years of anybody using Git.pm with it... |
In light of the compatibility comments, I'm re-thinking my testing strategy. I'm going to take a stab at testing older versions on Windows, which may take a while. When I'm done, I'll force push with signed off commits. |
@ColMelvin thanks! |
3f603ce
to
0dcb6ea
Compare
It took a while, but I eventually setup a Windows VM and found a copy of ActiveState Perl 5.8 (see http://www.perlmonks.org/?node_id=1188770). I ran a test using the list form of an
The good news is: I was able to run the unit test on 5.8 and the current fix (treating Windows specially) passes the tests. Once the merge conflict is resolved, this change should be ready for merging. |
Thanks for keeping at it! |
4c6b35b
to
85e159e
Compare
Checked ActiveState Perl 5.8.0 (build 806) on Windows 7 32-bit:
RE: Reviews
By all means. I am personally satisfied with @bk2204's approval; he is one of the most knowledgeable Perl developers (on Linux) I know. |
A little bit of context for those involved: @ColMelvin and I are co-workers, and we've discussed this issue in person. If this goes to the git list, I'm happy to be CC'd for review and comments. |
For the record, I have serious troubles with the test case that was added in this PR. First of all, it uses a Then, it uses the wrong paths to the Perl modules (there was a change recently where things are generated into Then, it is skipped by default in the Git for Windows SDK because it expects Even if I fix all that, things don't work for me, as now every single test seems to be failing (and I interrupted it at test case 161...). Will keep you posted on my progress. |
For the record, this is the first failing test case:
|
Even launching this from a CMD window does not help:
|
Hmm. I seem to be unable to wrap my head around the problem. It does seem as if @bk2204 any ideas? |
Okay, I give up for now. I cannot make that test work with MSYS2 Perl as included in Git for Windows' SDK... |
I reproduced the error you're seeing and it stems from the command line used by Perl. On *nix-like systems, such as MSYS2, As you correctly surmized, the problem comes from interpolation. The Windows command line does not perform variable interpolation (just like exec). And in In a Microsoft quirk, both the Windows command line and perl -e "print $ARGV[0]" testing The change I made only applies to That said, I must apologize -- I did not test the *.bat file after rebasing my work. That was a mistake and I would have caught the pathing issue had I done so. I will update the paths accordingly. |
@ColMelvin how do you want to proceed from here? I am still eager to take fixes ;-) |
@ColMelvin ping? |
85e159e
to
8665930
Compare
Thanks for pinging me; it's about time I pick up a personal project again. I made several changes, mostly to add documentation to the tests. I haven't had a chance to test the batch script as my current machine lacks a compiler. I hope to get one setup tomorrow for validation. As an additional improvement, I spent some time trying to run start //B //I /WAIT cmd //C t9701-perl-git-windows.bat |
Welcome back @ColMelvin!
You could, in theory, adjust the
|
The problem is, I don't know where the user installed ActiveState or Strawberry Perl (or another 'MSWin32' Perl). I can make some educated guesses (the installer's defaults, for 32-bit and 64-bit, for global and user-only installs), but a consistent (and, theoretically, simpler) way to detect the binary location is to use the PATH as set by Windows when CMD is first started. If the user installed one of these Perls, but did not setup the PATH, then they likely aren't using that Perl from CMD and they won't run into this issue. Therefore, the PATH seems - to me - to be the most authoritative source. Unfortunately, since Git Bash modifies the PATH to put the Git for Windows Perl first, I can't use that mechanism. Thus, I was hoping to reset the values to the system default with To answer your questions:
|
8665930
to
edb5f24
Compare
@dscho I've validated the batch test works correctly on Windows and I updated the commit messages to hopefully be more helpful. I would say this is ready for review. |
How about making this an environment variable, then, that is tested in that lazy prerequisite? That way, if you want to run that test case, you simply have to specify that environment variable (e.g. As you can guess from my harping on this issue, I find it highly important to integrate this test into the test suite, to make it automatable, rather than forcing the user to run it manually, and to figure out in the first place how to run this correctly.
Requiring that environment variable as a prerequisite would cirumvent this in a very elegant way: when running in Cygwin, you are simply expected to specify the path to the Perl executable in a way understood by Cygwin's Bash. |
edb5f24
to
cbb7eb7
Compare
I think we both agree: if a test needs a user to take action so it can run, it will (almost) never run. From this principle, I don't think the environment variable will suffice. The underlying problem with an environment variable is the same as with the batch script: a user needs to know it exists and then take action to get the test running. My original submission assumed as much -- the "test" was primarily designed for manual debugging. However, if automation is to be our goal, I would want tests to work (pass or skip) without user configuration and on all platforms. After much trial and error (on Linux, Cygwin, & MSYS2 builds), I think I have a solution that meets this ideal. The latest commits have this change (and were rebased onto v2.18.0, to stay up to date). However, to truly ensure the test always runs, we still need to add an MSWin32 build of Perl to VSTS on the GitHub project. This is something I cannot do (AFAIK). |
I agree.
The difference there is that I can integrate that into CI, while I cannot integrate your
Right now, there is a With the prerequisite I propose, the user running the test script would see that some test was skipped because of an unmet prerequisite. Reading the documentation above that prerequisite would then inform the user that a specific environment variable needs to be set, to point to an appropriate
This is not my goal. I do not want that test to run always, in particular not when there is no Strawberry nor ActiveState Perl to test against. What I want is to make it easy and convenient for people who are not called @ColMelvin to discover and to run this test ;-) |
t/t9701-perl-git-MSWin32.sh
Outdated
fi | ||
done | ||
return 1 | ||
} |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
On Thu, 5 Jul 2018, Beat Bolli wrote:
Can't we use `which -a perl | grep -v ^/usr | grep -v /^mingw` to check if a MSWin32 perl is found in some other path?
I would rather have the environment variable, but you're right, we could
probably have both.
The problem with your version is that it is not portable IIRC (Git tries
to avoid `which` for some reason that I seem to vaguely recall being
portability). To help with that, you could first use
```sh
{ test_have_prereq MINGW || test_have_prereq CYGWIN; } &&
```
in that lazy prerequisite, but I think at this stage it is just too much
effort for too little gain. The main benefit for me will be that I can
easily reuse my vcpkg's portable Strawberry Perl to test this.
|
I have deleted this comment because I saw after writing it that this was exactly the method used in the commit, so my comment was redundant. |
@ColMelvin are you still interested in this PR? |
@ColMelvin ping? |
Oh, I thought this was resolved. Apparently, I misread the comments and conflated the authors. Adding an optional environmental variable should be easy to add. |
Ah, I see what you mean, the |
cbb7eb7
to
c044b7b
Compare
On a native Windows build of Perl (where $^O equals 'MSWin32'), like Strawberry or ActiveState Perl, the Git.pm module follows a unique code path, one that alters the behavior of piped Git commands. This special path failed to handle spaces contained in an argument to Git. Remove that limitation by improving Windows command line support. On Windows, the command line is part of the operating system; it is not provided by a shell. This system requires certain characters (\, ") to be escaped (in certain cases). The cmd.exe command prompt rests on top of the command line and it has its own, additional escaping mechanism. When creating pipes, an MSWin32 build of Perl will either use the system call, CreateProcess (which takes the command line), or, if interpreted characters are detected, the command prompt, cmd.exe. Add a function to unescape command line arguments, one that will work with CreateProcess or with cmd.exe, as appropriate. This ensures any Git command will have its arguments parsed correctly, regardless of content. Additionally, include tests to verify that Perl's system() behavior remains unchanged -- notably, that the list of interpreted characters (for selecting cmd.exe) does not change. These tests need an MSWin32 build of Perl in the PATH to work; otherwise, they are skipped. This change will improve commands (or batch scripts) run in CMD, where native (MSWin32) builds of Perl are all that is available in the PATH (unless the user opts to install Unix utils in the PATH, which is not recommended in the Git for Windows installer). Commands run in MSYS Perl, which is included with Git for Windows, will not change (as it never had a problem). Closes: git-for-windows#1602 Signed-off-by: Chris Lindee <chris.lindee+github@gmail.com>
Replace the legacy TIEHANDLE used to fake out a pipe and replace it with real pipes. As modern Perl seems to handle these simple pipes well, the need for a special-case object has evaporated. As a consequence of this change, input pipes are now supported. Closes: git-for-windows#1603 Signed-off-by: Chris Lindee <chris.lindee+github@gmail.com>
Pull out the logic to find a MSWin32 build of Perl, so it can be used by all tests. Signed-off-by: Chris Lindee <chris.lindee+github@gmail.com>
e3f78f0
to
f6033be
Compare
@ColMelvin what's the status on this PR? |
I am under the impression that all concerns raised were addressed and that this change is awaiting merge. Other than the merge conflicts that have appeared, are there any concerns preventing this from merging? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am really not sure that I like the third patch. I'd rather have this an opt-in than an automatic default that adds (typically useless) churn to every invocation of make
.
done \ | ||
) | ||
endif | ||
MSWIN32_PERL_PATH_SQ = $(subst ','\'',$(MSWIN32_PERL_PATH)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure that this is a good change. By default, the Git for Windows SDK comes with a perl.exe
and we know exactly which one it is: the one that is shipped with (and therefore, supported by) Git for Windows.
In other words, if you really want this, I would want to make it an opt-in rather than an opt-out.
Besides, would it not make things substantially cleaner if you simply prepended the path to the known MSWin32 Perl (if configured via MSWIN32_PERL_PATH
explicitly) to PATH
? That way, perl
would already find the Perl interpreter you want, no need to play extra games with any mswin32_perl
shell function.
mswin32_perl () { | ||
local GITPERLLIB="$GITPERLLIB" | ||
if test_have_prereq CYGWIN || test_have_prereq MINGW; then | ||
GITPERLLIB="$(cygpath -w -p "$GITPERLLIB")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that really work? There are native .dll
files that some of the Perl modules want to load, and I am rather certain that they can be used only by /usr/bin/perl
. It has to be an MSYS Perl. It even has to match the precise version, otherwise it won't load.
Let's close this as stale. |
Improve the Git.pm module so native Windows users can make use of it without overbearing restrictions on what can be sent.
This change allows users to use:
This will enable users to run even more Git commands in a Windows environment (like cmd or PowerShell) through Perl.