Changeset 232228 in webkit


Ignore:
Timestamp:
May 27, 2018 9:50:42 AM (6 years ago)
Author:
ddkilzer@apple.com
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.

Location:
trunk/Tools
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r232222 r232228  
     12018-05-27  David Kilzer  <ddkilzer@apple.com>
     2
     3        svn-apply fails when a patch has an empty file
     4        <https://webkit.org/b/29684>
     5
     6        Reviewed by Daniel Bates.
     7
     8        Prior to this change, applying the following patches resulted in:
     9        - svn: add empty file     (failure)
     10        - svn: delete empty file  (failure)
     11        - svn: rename empty file  (failure)
     12        - git: add empty file     (false-positive success)
     13        - git: delete empty file  (success)
     14        - git: rename empty file  (failure)
     15
     16        * Scripts/VCSUtils.pm:
     17        (parseSvnDiffHeader): Handle the case when there is no patch
     18        following the header.  If the file exists and is empty, that
     19        means it's a deletion.  If the file does not exist, that means
     20        it's an addition. Everything else is a fatal error.
     21        * Scripts/svn-apply:
     22        (patch):
     23        - Only apply a patch for deletion if it has one or more text
     24          chunks.
     25        - Add a case to handle adding an empty file (an addition with no
     26          text chunks), and verify the file doesn't exist yet.
     27        - Any unhandled patch is a fatal error.
     28        * Scripts/webkitperl/VCSUtils_unittest/parseSvnDiffHeader.pl:
     29        Add tests for adding an empty file and deleting an empty file.
     30        * Scripts/webkitperl/VCSUtils_unittest/resources/empty.txt: Add.
     31        Used by parseSvnDiffHeader.pl unit test for "add an empty file"
     32        test case.
     33
    1342018-05-25  Aakash Jain  <aakash_jain@apple.com>
    235
  • trunk/Tools/Scripts/VCSUtils.pm

    r216032 r232228  
    939939    my $foundHeaderEnding;
    940940    my $isBinary;
     941    my $isDeletion;
    941942    my $isNew;
    942943    my $sourceRevision;
     
    993994
    994995    if (!$foundHeaderEnding) {
    995         die("Did not find end of header block corresponding to index path \"$indexPath\".");
     996        if (-z $indexPath) {
     997            # Delete an empty file.
     998            $isDeletion = 1;
     999        } elsif (! -e $indexPath) {
     1000            # Add an empty file.
     1001            $isNew = 1;
     1002        } else {
     1003            die "Did not find end of header block corresponding to index path \"$indexPath\".";
     1004        }
    9961005    }
    9971006
     
    10011010    $header{indexPath} = $indexPath;
    10021011    $header{isBinary} = $isBinary if $isBinary;
     1012    $header{isDeletion} = $isDeletion if $isDeletion;
    10031013    $header{isNew} = $isNew if $isNew;
    10041014    $header{sourceRevision} = $sourceRevision if $sourceRevision;
  • trunk/Tools/Scripts/svn-apply

    r226395 r232228  
    364364            }
    365365        } elsif ($deletion) {
    366             applyPatch($patch, $fullPath, ["--force"]) if $patch;
     366            applyPatch($patch, $fullPath, ["--force"]) if ($patch && $hasTextChunks);
    367367            scmRemove($fullPath);
    368368        } elsif ($addition && $hasTextChunks) {
     
    375375            # What is this for?
    376376            system("svn", "stat", "$escapedFullPath") if isSVN() && -e "$fullPath.orig";
     377        } elsif ($addition && !$hasTextChunks) {
     378            # Add empty file.
     379            die "\"$fullPath\" already exists" if -e $fullPath;
     380            open(my $FH, ">>", $fullPath) or die "Could not open \"$fullPath\" for writing: $!";
     381            close($FH);
     382            scmAdd($fullPath);
     383        } else {
     384            die "Can't handle patch for \"$fullPath\".";
    377385        }
    378386    }
  • trunk/Tools/Scripts/webkitperl/VCSUtils_unittest/parseSvnDiffHeader.pl

    r226395 r232228  
    267267    expectedNextLine => "Property changes on: test_file.swf\n",
    268268},
     269####
     270#    Empty file test cases
     271##
     272{
     273    # New test
     274    diffName => "add an empty file",
     275    inputText => <<'END',
     276Index: empty_file_that_should_never_exist
     277===================================================================
     278END
     279    expectedReturn => [
     280{
     281    svnConvertedText => <<'END',
     282Index: empty_file_that_should_never_exist
     283===================================================================
     284END
     285    indexPath => "empty_file_that_should_never_exist",
     286    isNew => 1,
     287},
     288undef],
     289    expectedNextLine => undef,
     290},
     291{
     292    # New test
     293    diffName => "delete an empty file",
     294    inputText => <<'END',
     295Index: Tools/Scripts/webkitperl/VCSUtils_unittest/resources/empty.txt
     296===================================================================
     297END
     298    expectedReturn => [
     299{
     300    svnConvertedText => <<'END',
     301Index: Tools/Scripts/webkitperl/VCSUtils_unittest/resources/empty.txt
     302===================================================================
     303END
     304    indexPath => "Tools/Scripts/webkitperl/VCSUtils_unittest/resources/empty.txt",
     305    isDeletion => 1,
     306},
     307undef],
     308    expectedNextLine => undef,
     309},
    269310);
    270311
Note: See TracChangeset for help on using the changeset viewer.