- Revision
- 232228
- Author
- [email protected]
- Date
- 2018-05-27 09:50:42 -0700 (Sun, 27 May 2018)
Log Message
svn-apply fails when a patch has an empty file
<https://webkit.org/b/29684>
Reviewed by Daniel Bates.
Prior to this change, applying the following patches resulted in:
- svn: add empty file (failure)
- svn: delete empty file (failure)
- svn: rename empty file (failure)
- git: add empty file (false-positive success)
- git: delete empty file (success)
- git: rename empty file (failure)
* Scripts/VCSUtils.pm:
(parseSvnDiffHeader): Handle the case when there is no patch
following the header. If the file exists and is empty, that
means it's a deletion. If the file does not exist, that means
it's an addition. Everything else is a fatal error.
* Scripts/svn-apply:
(patch):
- Only apply a patch for deletion if it has one or more text
chunks.
- Add a case to handle adding an empty file (an addition with no
text chunks), and verify the file doesn't exist yet.
- Any unhandled patch is a fatal error.
* Scripts/webkitperl/VCSUtils_unittest/parseSvnDiffHeader.pl:
Add tests for adding an empty file and deleting an empty file.
* Scripts/webkitperl/VCSUtils_unittest/resources/empty.txt: Add.
Used by parseSvnDiffHeader.pl unit test for "add an empty file"
test case.
Modified Paths
Added Paths
Diff
Modified: trunk/Tools/ChangeLog (232227 => 232228)
--- trunk/Tools/ChangeLog 2018-05-26 20:59:04 UTC (rev 232227)
+++ trunk/Tools/ChangeLog 2018-05-27 16:50:42 UTC (rev 232228)
@@ -1,3 +1,36 @@
+2018-05-27 David Kilzer <[email protected]>
+
+ svn-apply fails when a patch has an empty file
+ <https://webkit.org/b/29684>
+
+ Reviewed by Daniel Bates.
+
+ Prior to this change, applying the following patches resulted in:
+ - svn: add empty file (failure)
+ - svn: delete empty file (failure)
+ - svn: rename empty file (failure)
+ - git: add empty file (false-positive success)
+ - git: delete empty file (success)
+ - git: rename empty file (failure)
+
+ * Scripts/VCSUtils.pm:
+ (parseSvnDiffHeader): Handle the case when there is no patch
+ following the header. If the file exists and is empty, that
+ means it's a deletion. If the file does not exist, that means
+ it's an addition. Everything else is a fatal error.
+ * Scripts/svn-apply:
+ (patch):
+ - Only apply a patch for deletion if it has one or more text
+ chunks.
+ - Add a case to handle adding an empty file (an addition with no
+ text chunks), and verify the file doesn't exist yet.
+ - Any unhandled patch is a fatal error.
+ * Scripts/webkitperl/VCSUtils_unittest/parseSvnDiffHeader.pl:
+ Add tests for adding an empty file and deleting an empty file.
+ * Scripts/webkitperl/VCSUtils_unittest/resources/empty.txt: Add.
+ Used by parseSvnDiffHeader.pl unit test for "add an empty file"
+ test case.
+
2018-05-25 Aakash Jain <[email protected]>
Display detailed error logs when a script fails in EWS
Modified: trunk/Tools/Scripts/VCSUtils.pm (232227 => 232228)
--- trunk/Tools/Scripts/VCSUtils.pm 2018-05-26 20:59:04 UTC (rev 232227)
+++ trunk/Tools/Scripts/VCSUtils.pm 2018-05-27 16:50:42 UTC (rev 232228)
@@ -938,6 +938,7 @@
my $copiedFromPath;
my $foundHeaderEnding;
my $isBinary;
+ my $isDeletion;
my $isNew;
my $sourceRevision;
my $svnConvertedText;
@@ -992,7 +993,15 @@
}
if (!$foundHeaderEnding) {
- die("Did not find end of header block corresponding to index path \"$indexPath\".");
+ if (-z $indexPath) {
+ # Delete an empty file.
+ $isDeletion = 1;
+ } elsif (! -e $indexPath) {
+ # Add an empty file.
+ $isNew = 1;
+ } else {
+ die "Did not find end of header block corresponding to index path \"$indexPath\".";
+ }
}
my %header;
@@ -1000,6 +1009,7 @@
$header{copiedFromPath} = $copiedFromPath if $copiedFromPath;
$header{indexPath} = $indexPath;
$header{isBinary} = $isBinary if $isBinary;
+ $header{isDeletion} = $isDeletion if $isDeletion;
$header{isNew} = $isNew if $isNew;
$header{sourceRevision} = $sourceRevision if $sourceRevision;
$header{svnConvertedText} = $svnConvertedText;
Modified: trunk/Tools/Scripts/svn-apply (232227 => 232228)
--- trunk/Tools/Scripts/svn-apply 2018-05-26 20:59:04 UTC (rev 232227)
+++ trunk/Tools/Scripts/svn-apply 2018-05-27 16:50:42 UTC (rev 232228)
@@ -363,7 +363,7 @@
handleBinaryChange($fullPath, $patch) if $patch;
}
} elsif ($deletion) {
- applyPatch($patch, $fullPath, ["--force"]) if $patch;
+ applyPatch($patch, $fullPath, ["--force"]) if ($patch && $hasTextChunks);
scmRemove($fullPath);
} elsif ($addition && $hasTextChunks) {
# Addition
@@ -374,6 +374,14 @@
my $escapedFullPath = escapeSubversionPath("$fullPath.orig");
# What is this for?
system("svn", "stat", "$escapedFullPath") if isSVN() && -e "$fullPath.orig";
+ } elsif ($addition && !$hasTextChunks) {
+ # Add empty file.
+ die "\"$fullPath\" already exists" if -e $fullPath;
+ open(my $FH, ">>", $fullPath) or die "Could not open \"$fullPath\" for writing: $!";
+ close($FH);
+ scmAdd($fullPath);
+ } else {
+ die "Can't handle patch for \"$fullPath\".";
}
}
Modified: trunk/Tools/Scripts/webkitperl/VCSUtils_unittest/parseSvnDiffHeader.pl (232227 => 232228)
--- trunk/Tools/Scripts/webkitperl/VCSUtils_unittest/parseSvnDiffHeader.pl 2018-05-26 20:59:04 UTC (rev 232227)
+++ trunk/Tools/Scripts/webkitperl/VCSUtils_unittest/parseSvnDiffHeader.pl 2018-05-27 16:50:42 UTC (rev 232228)
@@ -266,6 +266,47 @@
"\n"],
expectedNextLine => "Property changes on: test_file.swf\n",
},
+####
+# Empty file test cases
+##
+{
+ # New test
+ diffName => "add an empty file",
+ inputText => <<'END',
+Index: empty_file_that_should_never_exist
+===================================================================
+END
+ expectedReturn => [
+{
+ svnConvertedText => <<'END',
+Index: empty_file_that_should_never_exist
+===================================================================
+END
+ indexPath => "empty_file_that_should_never_exist",
+ isNew => 1,
+},
+undef],
+ expectedNextLine => undef,
+},
+{
+ # New test
+ diffName => "delete an empty file",
+ inputText => <<'END',
+Index: Tools/Scripts/webkitperl/VCSUtils_unittest/resources/empty.txt
+===================================================================
+END
+ expectedReturn => [
+{
+ svnConvertedText => <<'END',
+Index: Tools/Scripts/webkitperl/VCSUtils_unittest/resources/empty.txt
+===================================================================
+END
+ indexPath => "Tools/Scripts/webkitperl/VCSUtils_unittest/resources/empty.txt",
+ isDeletion => 1,
+},
+undef],
+ expectedNextLine => undef,
+},
);
my $testCasesCount = @testCaseHashRefs;
Added: trunk/Tools/Scripts/webkitperl/VCSUtils_unittest/resources/empty.txt ( => )