Changeset 53340 in webkit


Ignore:
Timestamp:
Jan 15, 2010 12:36:25 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-01-15 Chris Jerdonek <chris.jerdonek@gmail.com>

Reviewed by David Kilzer.

Altered parseDiffHeader() to skip unrecognized lines and
other minor clean-ups.

https://bugs.webkit.org/show_bug.cgi?id=33476

  • Scripts/VCSUtils.pm:
    • Changed parseDiffHeader() as follows:
      • Skips over unrecognized lines.
      • Addressed FIXME to remove substitution for "diff" line.
      • Renamed "version" header hash key to "sourceRevision".
      • Eliminated "copiedFromVersion" header hash key.
      • Included "sourceRevision" also for copied files.
      • Checks that copy revision number matches "sourceRevision".
      • No longer returns $foundHeaderEnding.
      • Dies if header ending not found.
      • Diff header dividing line now always added.
  • Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl:
    • Made necessary changes in parseDiffHeader() unit tests.
    • Shortened the file paths in some test cases.
Location:
trunk/WebKitTools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r53317 r53340  
     12010-01-15  Chris Jerdonek  <chris.jerdonek@gmail.com>
     2
     3        Reviewed by David Kilzer.
     4
     5        Altered parseDiffHeader() to skip unrecognized lines and
     6        other minor clean-ups.
     7
     8        https://bugs.webkit.org/show_bug.cgi?id=33476
     9
     10        * Scripts/VCSUtils.pm:
     11          - Changed parseDiffHeader() as follows:
     12            - Skips over unrecognized lines.
     13            - Addressed FIXME to remove substitution for "diff" line.
     14            - Renamed "version" header hash key to "sourceRevision".
     15            - Eliminated "copiedFromVersion" header hash key.
     16            - Included "sourceRevision" also for copied files.
     17            - Checks that copy revision number matches "sourceRevision".
     18            - No longer returns $foundHeaderEnding.
     19            - Dies if header ending not found.
     20            - Diff header dividing line now always added.
     21
     22        * Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl:
     23          - Made necessary changes in parseDiffHeader() unit tests.
     24          - Shortened the file paths in some test cases.
     25
    1262010-01-14  Yuzo Fujishima  <yuzo@google.com>
    227
  • trunk/WebKitTools/Scripts/VCSUtils.pm

    r53076 r53340  
    371371    }
    372372    if (m#^index [0-9a-f]{7}\.\.[0-9a-f]{7} [0-9]{6}#) {
     373        # FIXME: No need to return dividing line once parseDiffHeader() is used.
    373374        return "===================================================================$POSTMATCH";
    374375    }
     
    386387# parsed header block.
    387388#
    388 # This subroutine dies if given leading junk.
     389# This subroutine dies if given leading junk or if the end of the header
     390# block could not be detected. The last line of a header block is a
     391# line beginning with "+++".
    389392#
    390393# Args:
     
    394397#   $line: the line last read from $fileHandle
    395398#
    396 # Returns ($headerHashRef, $foundHeaderEnding, $lastReadLine):
     399# Returns ($headerHashRef, $lastReadLine):
    397400#   $headerHashRef: a hash reference representing a diff header
    398 #     copiedFromPath: the path in the "from" clause, if any.
    399 #     copiedFromVersion: the revision number in the "from" clause, if any.
     401#     copiedFromPath: if a file copy, the path from which the file was
     402#                     copied. Otherwise, undefined.
    400403#     indexPath: the path in the "Index:" line.
     404#     sourceRevision: the revision number of the source. This is the same
     405#                     as the revision number the file was copied from, in
     406#                     the case of a file copy.
    401407#     svnConvertedText: the header text converted to SVN format.
    402 #                       Unrecognized Git lines are left alone.
    403 #     version: the revision number of the source.
    404 #   $foundHeaderEnding: whether the last header block line was found.
    405 #                       This is a line beginning with "+++".
    406 #   $lastReadLine: the line last read from $fileHandle. If EOF has not
    407 #                  been reached, this is the first line after the
    408 #                  header ending.
     408#                       Unrecognized lines are discarded.
     409#   $lastReadLine: the line last read from $fileHandle. This is the first
     410#                  line after the header ending.
    409411sub parseDiffHeader($$)
    410412{
     
    426428    my %header;
    427429
    428     my $foundHeaderEnding = 0;
    429     my $lastReadLine;
     430    my $foundHeaderEnding;
     431    my $lastReadLine;
     432    my $sourceRevision;
    430433    my $svnConvertedText = $line;
    431434    while (<$fileHandle>) {
     
    437440        $_ = &$filter($_) if $filter;
    438441
    439         # Fix paths on "diff", "---", and "+++" lines to match the
    440         # leading index line.
    441         s/\S+$/$indexPath/ if /^diff/; # FIXME: Can this ever occur? If so, include
    442                                        #        a unit test. Otherwise, remove it.
    443         s/^--- \S+/--- $indexPath/;
    444         if (/^--- .+\(from (\S+):(\d+)\)$/) {
    445             $header{copiedFromPath} = $1;
    446             $header{copiedFromVersion} = $2 if ($2 != 0);
    447         } elsif (/^--- .+\(revision (\d+)\)$/) {
    448             $header{version} = $1 if ($1 != 0);
     442        # Fix paths on ""---" and "+++" lines to match the leading
     443        # index line.
     444        if (s/^--- \S+/--- $indexPath/) {
     445            # ---
     446            if (/^--- .+\(revision (\d+)\)/) {
     447                $sourceRevision = $1 if ($1 != 0);
     448                if (/\(from (\S+):(\d+)\)$/) {
     449                    # The "from" clause is created by svn-create-patch, in
     450                    # which case there is always also a "revision" clause.
     451                    $header{copiedFromPath} = $1;
     452                    die("Revision number \"$2\" in \"from\" clause does not match " .
     453                        "source revision number \"$sourceRevision\".") if ($2 != $sourceRevision);
     454                }
     455            }
     456            $_ = "=" x 67 . "$eol$_"; # Prepend dividing line ===....
    449457        } elsif (s/^\+\+\+ \S+/+++ $indexPath/) {
     458            # +++
    450459            $foundHeaderEnding = 1;
    451         }
    452 
    453         $svnConvertedText .= "$_$eol"; # Also restore EOL characters.
     460        } else {
     461            # Skip unrecognized lines.
     462            next;
     463        }
     464
     465        $svnConvertedText .= "$_$eol"; # Also restore end-of-line characters.
    454466        if ($foundHeaderEnding) {
    455467            $lastReadLine = <$fileHandle>;
     
    458470    } # $lastReadLine is undef if while loop ran out.
    459471
     472    if (!$foundHeaderEnding) {
     473        die("Did not find end of header block corresponding to index path \"$indexPath\".");
     474    }
     475
    460476    $header{indexPath} = $indexPath;
     477    $header{sourceRevision} = $sourceRevision;
    461478    $header{svnConvertedText} = $svnConvertedText;
    462479
    463     return (\%header, $foundHeaderEnding, $lastReadLine);
     480    return (\%header, $lastReadLine);
    464481}
    465482
  • trunk/WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl

    r53076 r53340  
    3939my @headerKeys = ( # The $headerHashRef keys to check.
    4040    "copiedFromPath",
    41     "copiedFromVersion",
    4241    "indexPath",
     42    "sourceRevision",
    4343    "svnConvertedText",
    44     "version",
    4544);
    4645
     
    5554    my $line = <$fileHandle>;
    5655
    57     my ($headerHashRef, $foundHeaderEnding, $lastReadLine) = VCSUtils::parseDiffHeader($fileHandle, $line);
     56    my ($headerHashRef, $lastReadLine) = VCSUtils::parseDiffHeader($fileHandle, $line);
    5857
    5958    my $titleHeader = "parseDiffHeader(): [$diffTestHashRef->{diffName}] ";
     
    6564    }
    6665
    67     is($foundHeaderEnding, $diffTestHashRef->{foundHeaderEnding}, "${titleHeader}foundHeaderEnding");
    6866    is($lastReadLine, $diffTestHashRef->{lastReadLine}, "${titleHeader}lastReadLine");
    6967
     
    7270}
    7371
    74 my @diffTests = ({
    75     # New test: missing closing header line
    76     diffName => "SVN: incomplete header",
    77     inputText => <<'END',
    78 Index: WebKitTools/Scripts/VCSUtils.pm
    79 END
    80     # Header keys to check
    81     svnConvertedText => <<'END',
    82 Index: WebKitTools/Scripts/VCSUtils.pm
    83 END
    84     copiedFromPath => undef,
    85     copiedFromVersion => undef,
    86     indexPath => "WebKitTools/Scripts/VCSUtils.pm",
    87     version => undef,
    88     # Other values to check
    89     foundHeaderEnding => 0,
    90     lastReadLine => undef,
    91     nextLine => undef,
    92 },
     72my @diffTests = (
    9373{
    9474    # New test
     
    11090END
    11191    copiedFromPath => undef,
    112     copiedFromVersion => undef,
    11392    indexPath => "WebKitTools/Scripts/VCSUtils.pm",
    114     version => "53004",
    115     # Other values to check
    116     foundHeaderEnding => 1,
     93    sourceRevision => "53004",
     94    # Other values to check
    11795    lastReadLine => "@@ -32,6 +32,7 @@ use strict;\n",
    11896    nextLine => " use warnings;\n",
     
    137115END
    138116    copiedFromPath => undef,
    139     copiedFromVersion => undef,
    140117    indexPath => "WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl",
    141     version => undef,
    142     # Other values to check
    143     foundHeaderEnding => 1,
     118    sourceRevision => undef,
     119    # Other values to check
    144120    lastReadLine => "@@ -0,0 +1,262 @@\n",
    145121    nextLine => "+#!/usr/bin/perl -w\n",
     
    149125    diffName => "SVN: copy",
    150126    inputText => <<'END',
    151 Index: WebKitTools/Scripts/webkitpy/move_test.py
    152 ===================================================================
    153 --- WebKitTools/Scripts/webkitpy/move_test.py   (revision 53047)        (from WebKitTools/Scripts/webkitpy/__init__.py:53048)
    154 +++ WebKitTools/Scripts/webkitpy/move_test.py   (working copy)
     127Index: index_path.py
     128===================================================================
     129--- index_path.py       (revision 53048)        (from copied_from_path.py:53048)
     130+++ index_path.py       (working copy)
    155131@@ -0,0 +1,7 @@
    156 +# Required for Python to search this directory for module files
    157 END
    158     # Header keys to check
    159     svnConvertedText => <<'END',
    160 Index: WebKitTools/Scripts/webkitpy/move_test.py
    161 ===================================================================
    162 --- WebKitTools/Scripts/webkitpy/move_test.py   (revision 53047)        (from WebKitTools/Scripts/webkitpy/__init__.py:53048)
    163 +++ WebKitTools/Scripts/webkitpy/move_test.py   (working copy)
    164 END
    165     copiedFromPath => "WebKitTools/Scripts/webkitpy/__init__.py",
    166     copiedFromVersion => "53048",
    167     indexPath => "WebKitTools/Scripts/webkitpy/move_test.py",
    168     version => undef,
    169     # Other values to check
    170     foundHeaderEnding => 1,
     132+# Python file...
     133END
     134    # Header keys to check
     135    svnConvertedText => <<'END',
     136Index: index_path.py
     137===================================================================
     138--- index_path.py       (revision 53048)        (from copied_from_path.py:53048)
     139+++ index_path.py       (working copy)
     140END
     141    copiedFromPath => "copied_from_path.py",
     142    indexPath => "index_path.py",
     143    sourceRevision => 53048,
     144    # Other values to check
    171145    lastReadLine => "@@ -0,0 +1,7 @@\n",
    172     nextLine => "+# Required for Python to search this directory for module files\n",
     146    nextLine => "+# Python file...\n",
    173147},
    174148{
     
    176150    diffName => "SVN: \\r\\n lines",
    177151    inputText => <<END, # No single quotes to allow interpolation of "\r"
    178 Index: WebKitTools/Scripts/webkitpy/move_test.py\r
     152Index: index_path.py\r
    179153===================================================================\r
    180 --- WebKitTools/Scripts/webkitpy/move_test.py   (revision 53047)        (from WebKitTools/Scripts/webkitpy/__init__.py:53048)\r
    181 +++ WebKitTools/Scripts/webkitpy/move_test.py   (working copy)\r
     154--- index_path.py       (revision 53048)        (from copied_from_path.py:53048)\r
     155+++ index_path.py       (working copy)\r
    182156@@ -0,0 +1,7 @@\r
    183 +# Required for Python to search this directory for module files\r
     157+# Python file...\r
    184158END
    185159    # Header keys to check
    186160    svnConvertedText => <<END, # No single quotes to allow interpolation of "\r"
    187 Index: WebKitTools/Scripts/webkitpy/move_test.py\r
     161Index: index_path.py\r
    188162===================================================================\r
    189 --- WebKitTools/Scripts/webkitpy/move_test.py   (revision 53047)        (from WebKitTools/Scripts/webkitpy/__init__.py:53048)\r
    190 +++ WebKitTools/Scripts/webkitpy/move_test.py   (working copy)\r
    191 END
    192     copiedFromPath => "WebKitTools/Scripts/webkitpy/__init__.py",
    193     copiedFromVersion => "53048",
    194     indexPath => "WebKitTools/Scripts/webkitpy/move_test.py",
    195     version => undef,
    196     # Other values to check
    197     foundHeaderEnding => 1,
     163--- index_path.py       (revision 53048)        (from copied_from_path.py:53048)\r
     164+++ index_path.py       (working copy)\r
     165END
     166    copiedFromPath => "copied_from_path.py",
     167    indexPath => "index_path.py",
     168    sourceRevision => 53048,
     169    # Other values to check
    198170    lastReadLine => "@@ -0,0 +1,7 @@\r\n",
    199     nextLine => "+# Required for Python to search this directory for module files\r\n",
     171    nextLine => "+# Python file...\r\n",
    200172},
    201173{
     
    203175    diffName => "SVN: path corrections",
    204176    inputText => <<'END',
    205 Index: WebKitTools/Scripts/webkitpy/move_test.py
    206 ===================================================================
    207 --- bad_path    (revision 53047)        (from WebKitTools/Scripts/webkitpy/__init__.py:53048)
     177Index: index_path.py
     178===================================================================
     179--- bad_path    (revision 53048)        (from copied_from_path.py:53048)
    208180+++ bad_path    (working copy)
    209181@@ -0,0 +1,7 @@
    210 +# Required for Python to search this directory for module files
    211 END
    212     # Header keys to check
    213     svnConvertedText => <<'END',
    214 Index: WebKitTools/Scripts/webkitpy/move_test.py
    215 ===================================================================
    216 --- WebKitTools/Scripts/webkitpy/move_test.py   (revision 53047)        (from WebKitTools/Scripts/webkitpy/__init__.py:53048)
    217 +++ WebKitTools/Scripts/webkitpy/move_test.py   (working copy)
    218 END
    219     copiedFromPath => "WebKitTools/Scripts/webkitpy/__init__.py",
    220     copiedFromVersion => "53048",
    221     indexPath => "WebKitTools/Scripts/webkitpy/move_test.py",
    222     version => undef,
    223     # Other values to check
    224     foundHeaderEnding => 1,
     182+# Python file...
     183END
     184    # Header keys to check
     185    svnConvertedText => <<'END',
     186Index: index_path.py
     187===================================================================
     188--- index_path.py       (revision 53048)        (from copied_from_path.py:53048)
     189+++ index_path.py       (working copy)
     190END
     191    copiedFromPath => "copied_from_path.py",
     192    indexPath => "index_path.py",
     193    sourceRevision => 53048,
     194    # Other values to check
    225195    lastReadLine => "@@ -0,0 +1,7 @@\n",
    226     nextLine => "+# Required for Python to search this directory for module files\n",
     196    nextLine => "+# Python file...\n",
    227197},
    228198{
     
    244214END
    245215    copiedFromPath => undef,
    246     copiedFromVersion => undef,
    247216    indexPath => "WebCore/rendering/style/StyleFlexibleBoxData.h",
    248     version => undef,
    249     # Other values to check
    250     foundHeaderEnding => 1,
     217    sourceRevision => undef,
     218    # Other values to check
    251219    lastReadLine => "@@ -47,7 +47,6 @@ public:\n",
    252220    nextLine => undef,
     
    267235    svnConvertedText => <<'END',
    268236Index: LayoutTests/http/tests/security/listener/xss-inactive-closure.html
    269 new file mode 100644
    270 index 0000000..3c9f114
     237===================================================================
    271238--- LayoutTests/http/tests/security/listener/xss-inactive-closure.html
    272239+++ LayoutTests/http/tests/security/listener/xss-inactive-closure.html
    273240END
    274241    copiedFromPath => undef,
    275     copiedFromVersion => undef,
    276242    indexPath => "LayoutTests/http/tests/security/listener/xss-inactive-closure.html",
    277     version => undef,
    278     # Other values to check
    279     foundHeaderEnding => 1,
     243    sourceRevision => undef,
     244    # Other values to check
    280245    lastReadLine => "@@ -0,0 +1,34 @@\n",
    281246    nextLine => "+<html>\n",
     
    283248);
    284249
    285 plan(tests => @diffTests * 8); # Eight assertions per call to doDiffTest().
     250plan(tests => @diffTests * 6); # Multiply by number of assertions per call to doDiffTest().
    286251
    287252foreach my $diffTestHashRef (@diffTests) {
Note: See TracChangeset for help on using the changeset viewer.