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.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@232228 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Tools/Scripts/svn-apply b/Tools/Scripts/svn-apply
index c3c972f5..d840216 100755
--- a/Tools/Scripts/svn-apply
+++ b/Tools/Scripts/svn-apply
@@ -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\".";
}
}