Bug 115281 - WebKit tools cannot apply git patches for filenames containing spaces
Summary: WebKit tools cannot apply git patches for filenames containing spaces
Status: RESOLVED DUPLICATE of bug 111066
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Major
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2013-04-26 15:26 PDT by Simon Cooper
Modified: 2013-05-19 23:30 PDT (History)
8 users (show)

See Also:


Attachments
An example of svn patch (15.44 KB, text/plain)
2013-04-26 15:49 PDT, Alexey Proskuryakov
no flags Details
proposed fix (2.95 KB, patch)
2013-05-15 23:02 PDT, Alexey Proskuryakov
no flags Details | Formatted Diff | Diff
proposed patch (2.90 KB, patch)
2013-05-15 23:14 PDT, Alexey Proskuryakov
ddkilzer: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Comment 1 Alexey Proskuryakov 2013-04-26 15:28:27 PDT
Looks like this is an issue with git patches, but not with svn ones.
Comment 2 Alexey Proskuryakov 2013-04-26 15:33:01 PDT
The script that needs to be fixed in likely Tools/Scripts/svn-apply.
Comment 3 Simon Cooper 2013-04-26 15:34:39 PDT
There were two files that had spaces in their names in this patch...

Source/WebKit2/Resources/PlugInSandboxProfiles/com.macromedia.QuckTime Plugin.plugin.sb
Source/WebKit2/Resources/PlugInSandboxProfiles/com.macromedia.Flash Player.plugin.sb

It was the first one that appears in the logs for the failing patch application.
Comment 4 Simon Cooper 2013-04-26 15:35:15 PDT
What does a svn patch look like then?

How is it different from the git patch?
Comment 5 Alexey Proskuryakov 2013-04-26 15:49:40 PDT
Created attachment 199867 [details]
An example of svn patch

Attaching the same patch, re-made with svn.
Comment 6 Mark Rowe (bdash) 2013-04-26 16:26:24 PDT
The difficulty is in parsing this line:

diff --git a/Source/WebKit2/Resources/PlugInSandboxProfiles/com.apple.QuickTime Plugin.plugin.sb b/Source/WebKit2/Resources/PlugInSandboxProfiles/com.apple.QuickTime Plugin.plugin.sb

There's no obvious delimiter between the two filenames.
Comment 7 Simon Cooper 2013-04-26 16:55:48 PDT
There is a faulty regex:  $gitDiffStartRegEx. 

It is not sufficient to parse arguments containing spaces.  The logic in parseGitDiffHeader() doesn’t help, because it assumes the regex actually can parse all filenames.  That isn’t how it is done for SVN.

There are perfectly good and easily parseable filenames on the line following the “diff” line.

However, the following diff will parse my patch (although there may be issues with other tools) — I just debugged this to the point where it can parse the diffs.

diff --git a/Tools/Scripts/VCSUtils.pm b/Tools/Scripts/VCSUtils.pm
index cf87db3..fb6380a 100644
--- a/Tools/Scripts/VCSUtils.pm
+++ b/Tools/Scripts/VCSUtils.pm
@@ -107,7 +107,7 @@ my $svnVersion;
 # Project time zone for Cupertino, CA, US
 my $changeLogTimeZone = "PST8PDT";
 
-my $gitDiffStartRegEx = qr#^diff --git (\w/)?(.+) (\w/)?([^\r\n]+)#;
+my $gitDiffStartRegEx = qr#^diff --git (\w/)(.+) (\w/)([^\r\n]+?)$#;
 my $svnDiffStartRegEx = qr#^Index: ([^\r\n]+)#;
 my $svnPropertiesStartRegEx = qr#^Property changes on: ([^\r\n]+)#; # $1 is normally the same as the index path.
 my $svnPropertyStartRegEx = qr#^(Modified|Name|Added|Deleted): ([^\r\n]+)#; # $2 is the name of the property.


The fix works by making sure the starting a/ or b/ are not optional, the 2nd regex is *not* greedy and the whole regex needs to be terminally anchored (to force the consumption of the whole string).
Comment 8 Mark Rowe (bdash) 2013-04-26 17:02:55 PDT
The leading a/ b/ were intentionally made optional back in r58741 / bug 32438.
Comment 9 Simon Cooper 2013-04-26 17:05:53 PDT
Then parseGitDiffHeader() has to be rewritten to get the filenames from the ^--- and ^+++ lines.
Comment 10 Simon Cooper 2013-04-26 18:06:44 PDT
svn-apply also mangles git patches in a way that “patch” cannot apply them to files with spaces.  It is not clear what is going on, but patch does do something special when there is an “Index:” line.

I’m giving up on looking at this.
Comment 11 Alexey Proskuryakov 2013-05-15 23:02:15 PDT
Created attachment 201923 [details]
proposed fix

I don't really know what I'm doing here (neither Perl nor the structure of patches). Please review carefully.

I think that the trick here was that +++ and --- lines are really of this format:

--- Source/WebKit2/Resources/PlugInSandboxProfiles/com.macromedia.Flash Player.plugin.sb<TAB>(revision 149145)

When there are no spaces, a path alone suffices, but if there are spaces, at least the tab is desired.
Comment 12 Alexey Proskuryakov 2013-05-15 23:14:23 PDT
Created attachment 201924 [details]
proposed patch

Actually, looks like git patches do the same thing with tabs, so let's preserve these more carefully.
Comment 13 David Kilzer (:ddkilzer) 2013-05-17 10:27:32 PDT
Comment on attachment 201924 [details]
proposed patch

I'm overriding darin's r+ with an r- because this doesn't have a test added for the changes.

Tests for this method are in Tools/Scripts/webkitperl/VCSUtils_unittest/parseGitDiffHeader.pl.

To run the tests, use:  ./Tools/Scripts/test-webkitperl
Comment 14 Alexey Proskuryakov 2013-05-17 11:22:34 PDT
I didn't know that we had secret regression tests for this tool! Looks like the patch is not good.

Svn and git "+++" and "---" lines are different - looks like one likes to put /dev/null there when adding or deleting files, and another does not. Unsure how to fix.
Comment 15 Alexey Proskuryakov 2013-05-17 11:26:14 PDT
<rdar://problem/13925627>
Comment 16 Daniel Bates 2013-05-19 23:30:34 PDT

*** This bug has been marked as a duplicate of bug 111066 ***