[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.18-1-697-g2f78b87
ddkilzer at apple.com
ddkilzer at apple.com
Wed Jan 20 22:19:20 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit c068fe44a2098666372651e266efdda789971734
Author: ddkilzer at apple.com <ddkilzer at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Mon Jan 11 15:52:48 2010 +0000
Created a unit-tested function to parse the header block of
a Git or SVN diff -- for future refactoring of svn-apply and
svn-unapply.
Patch by Chris Jerdonek <chris.jerdonek at gmail.com> on 2010-01-11
Reviewed by David Kilzer.
https://bugs.webkit.org/show_bug.cgi?id=33447
* Scripts/VCSUtils.pm:
- Added parseDiffHeader().
- Removed irrelevant comment from gitdiff2svndiff().
* Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl: Added.
- Added 48 unit tests for parseDiffHeader().
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@53076 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index 8eaf455..b807717 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,20 @@
+2010-01-11 Chris Jerdonek <chris.jerdonek at gmail.com>
+
+ Reviewed by David Kilzer.
+
+ Created a unit-tested function to parse the header block of
+ a Git or SVN diff -- for future refactoring of svn-apply and
+ svn-unapply.
+
+ https://bugs.webkit.org/show_bug.cgi?id=33447
+
+ * Scripts/VCSUtils.pm:
+ - Added parseDiffHeader().
+ - Removed irrelevant comment from gitdiff2svndiff().
+
+ * Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl: Added.
+ - Added 48 unit tests for parseDiffHeader().
+
2010-01-10 Adam Barth <abarth at webkit.org>
Rubber stamped by David Kilzer.
diff --git a/WebKitTools/Scripts/VCSUtils.pm b/WebKitTools/Scripts/VCSUtils.pm
index 183ebcd..18adb15 100644
--- a/WebKitTools/Scripts/VCSUtils.pm
+++ b/WebKitTools/Scripts/VCSUtils.pm
@@ -365,8 +365,7 @@ sub svnStatus($)
sub gitdiff2svndiff($)
{
$_ = shift @_;
-
- # \V is any character that is not vertical white space
+
if (m#^diff --git \w/(.+) \w/([^\r\n]+)#) {
return "Index: $1$POSTMATCH";
}
@@ -382,6 +381,88 @@ sub gitdiff2svndiff($)
return $_;
}
+# Parse the next diff header from the given file handle, and advance
+# the file handle so the last line read is the first line after the
+# parsed header block.
+#
+# This subroutine dies if given leading junk.
+#
+# Args:
+# $fileHandle: advanced so the last line read is the first line of the
+# next diff header. For SVN-formatted diffs, this is the
+# "Index:" line.
+# $line: the line last read from $fileHandle
+#
+# Returns ($headerHashRef, $foundHeaderEnding, $lastReadLine):
+# $headerHashRef: a hash reference representing a diff header
+# copiedFromPath: the path in the "from" clause, if any.
+# copiedFromVersion: the revision number in the "from" clause, if any.
+# indexPath: the path in the "Index:" line.
+# svnConvertedText: the header text converted to SVN format.
+# Unrecognized Git lines are left alone.
+# version: the revision number of the source.
+# $foundHeaderEnding: whether the last header block line was found.
+# This is a line beginning with "+++".
+# $lastReadLine: the line last read from $fileHandle. If EOF has not
+# been reached, this is the first line after the
+# header ending.
+sub parseDiffHeader($$)
+{
+ my ($fileHandle, $line) = @_;
+
+ my $filter;
+ if ($line =~ m#^diff --git #) {
+ $filter = \&gitdiff2svndiff;
+ }
+ $line = &$filter($line) if $filter;
+
+ my $indexPath;
+ if ($line =~ /^Index: ([^\r\n]+)/) {
+ $indexPath = $1;
+ } else {
+ die("Could not parse first line of diff header: \"$line\".");
+ }
+
+ my %header;
+
+ my $foundHeaderEnding = 0;
+ my $lastReadLine;
+ my $svnConvertedText = $line;
+ while (<$fileHandle>) {
+ # Temporarily strip off any end-of-line characters to simplify
+ # regex matching below.
+ s/([\n\r]+)$//;
+ my $eol = $1;
+
+ $_ = &$filter($_) if $filter;
+
+ # Fix paths on "diff", "---", and "+++" lines to match the
+ # leading index line.
+ s/\S+$/$indexPath/ if /^diff/; # FIXME: Can this ever occur? If so, include
+ # a unit test. Otherwise, remove it.
+ s/^--- \S+/--- $indexPath/;
+ if (/^--- .+\(from (\S+):(\d+)\)$/) {
+ $header{copiedFromPath} = $1;
+ $header{copiedFromVersion} = $2 if ($2 != 0);
+ } elsif (/^--- .+\(revision (\d+)\)$/) {
+ $header{version} = $1 if ($1 != 0);
+ } elsif (s/^\+\+\+ \S+/+++ $indexPath/) {
+ $foundHeaderEnding = 1;
+ }
+
+ $svnConvertedText .= "$_$eol"; # Also restore EOL characters.
+ if ($foundHeaderEnding) {
+ $lastReadLine = <$fileHandle>;
+ last;
+ }
+ } # $lastReadLine is undef if while loop ran out.
+
+ $header{indexPath} = $indexPath;
+ $header{svnConvertedText} = $svnConvertedText;
+
+ return (\%header, $foundHeaderEnding, $lastReadLine);
+}
+
# If possible, returns a ChangeLog patch equivalent to the given one,
# but with the newest ChangeLog entry inserted at the top of the
# file -- i.e. no leading context and all lines starting with "+".
diff --git a/WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl b/WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl
new file mode 100644
index 0000000..8c861aa
--- /dev/null
+++ b/WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl
@@ -0,0 +1,289 @@
+#!/usr/bin/perl -w
+#
+# Copyright (C) 2010 Chris Jerdonek (chris.jerdonek at gmail.com)
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+# its contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Unit tests of parseDiffHeader().
+
+use strict;
+use warnings;
+
+use Test::More;
+use VCSUtils;
+
+my @headerKeys = ( # The $headerHashRef keys to check.
+ "copiedFromPath",
+ "copiedFromVersion",
+ "indexPath",
+ "svnConvertedText",
+ "version",
+);
+
+# Test parseDiffHeader() for the given $diffTestHashRef.
+sub doDiffTest($)
+{
+ my ($diffTestHashRef) = @_;
+
+ my $fileHandle;
+ open($fileHandle, "<", \$diffTestHashRef->{inputText});
+
+ my $line = <$fileHandle>;
+
+ my ($headerHashRef, $foundHeaderEnding, $lastReadLine) = VCSUtils::parseDiffHeader($fileHandle, $line);
+
+ my $titleHeader = "parseDiffHeader(): [$diffTestHashRef->{diffName}] ";
+ my $title;
+
+ foreach my $headerKey (@headerKeys) {
+ my $title = "${titleHeader}key=\"$headerKey\"";
+ is($headerHashRef->{$headerKey}, $diffTestHashRef->{$headerKey}, $title);
+ }
+
+ is($foundHeaderEnding, $diffTestHashRef->{foundHeaderEnding}, "${titleHeader}foundHeaderEnding");
+ is($lastReadLine, $diffTestHashRef->{lastReadLine}, "${titleHeader}lastReadLine");
+
+ my $nextLine = <$fileHandle>;
+ is($nextLine, $diffTestHashRef->{nextLine}, "${titleHeader}nextLine");
+}
+
+my @diffTests = ({
+ # New test: missing closing header line
+ diffName => "SVN: incomplete header",
+ inputText => <<'END',
+Index: WebKitTools/Scripts/VCSUtils.pm
+END
+ # Header keys to check
+ svnConvertedText => <<'END',
+Index: WebKitTools/Scripts/VCSUtils.pm
+END
+ copiedFromPath => undef,
+ copiedFromVersion => undef,
+ indexPath => "WebKitTools/Scripts/VCSUtils.pm",
+ version => undef,
+ # Other values to check
+ foundHeaderEnding => 0,
+ lastReadLine => undef,
+ nextLine => undef,
+},
+{
+ # New test
+ diffName => "SVN: simple",
+ inputText => <<'END',
+Index: WebKitTools/Scripts/VCSUtils.pm
+===================================================================
+--- WebKitTools/Scripts/VCSUtils.pm (revision 53004)
++++ WebKitTools/Scripts/VCSUtils.pm (working copy)
+@@ -32,6 +32,7 @@ use strict;
+ use warnings;
+END
+ # Header keys to check
+ svnConvertedText => <<'END',
+Index: WebKitTools/Scripts/VCSUtils.pm
+===================================================================
+--- WebKitTools/Scripts/VCSUtils.pm (revision 53004)
++++ WebKitTools/Scripts/VCSUtils.pm (working copy)
+END
+ copiedFromPath => undef,
+ copiedFromVersion => undef,
+ indexPath => "WebKitTools/Scripts/VCSUtils.pm",
+ version => "53004",
+ # Other values to check
+ foundHeaderEnding => 1,
+ lastReadLine => "@@ -32,6 +32,7 @@ use strict;\n",
+ nextLine => " use warnings;\n",
+},
+{
+ # New test
+ diffName => "SVN: new file",
+ inputText => <<'END',
+Index: WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl
+===================================================================
+--- WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl (revision 0)
++++ WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl (revision 0)
+@@ -0,0 +1,262 @@
++#!/usr/bin/perl -w
+END
+ # Header keys to check
+ svnConvertedText => <<'END',
+Index: WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl
+===================================================================
+--- WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl (revision 0)
++++ WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl (revision 0)
+END
+ copiedFromPath => undef,
+ copiedFromVersion => undef,
+ indexPath => "WebKitTools/Scripts/webkitperl/VCSUtils_unittest/parseDiffHeader.pl",
+ version => undef,
+ # Other values to check
+ foundHeaderEnding => 1,
+ lastReadLine => "@@ -0,0 +1,262 @@\n",
+ nextLine => "+#!/usr/bin/perl -w\n",
+},
+{
+ # New test
+ diffName => "SVN: copy",
+ inputText => <<'END',
+Index: WebKitTools/Scripts/webkitpy/move_test.py
+===================================================================
+--- WebKitTools/Scripts/webkitpy/move_test.py (revision 53047) (from WebKitTools/Scripts/webkitpy/__init__.py:53048)
++++ WebKitTools/Scripts/webkitpy/move_test.py (working copy)
+@@ -0,0 +1,7 @@
++# Required for Python to search this directory for module files
+END
+ # Header keys to check
+ svnConvertedText => <<'END',
+Index: WebKitTools/Scripts/webkitpy/move_test.py
+===================================================================
+--- WebKitTools/Scripts/webkitpy/move_test.py (revision 53047) (from WebKitTools/Scripts/webkitpy/__init__.py:53048)
++++ WebKitTools/Scripts/webkitpy/move_test.py (working copy)
+END
+ copiedFromPath => "WebKitTools/Scripts/webkitpy/__init__.py",
+ copiedFromVersion => "53048",
+ indexPath => "WebKitTools/Scripts/webkitpy/move_test.py",
+ version => undef,
+ # Other values to check
+ foundHeaderEnding => 1,
+ lastReadLine => "@@ -0,0 +1,7 @@\n",
+ nextLine => "+# Required for Python to search this directory for module files\n",
+},
+{
+ # New test
+ diffName => "SVN: \\r\\n lines",
+ inputText => <<END, # No single quotes to allow interpolation of "\r"
+Index: WebKitTools/Scripts/webkitpy/move_test.py\r
+===================================================================\r
+--- WebKitTools/Scripts/webkitpy/move_test.py (revision 53047) (from WebKitTools/Scripts/webkitpy/__init__.py:53048)\r
++++ WebKitTools/Scripts/webkitpy/move_test.py (working copy)\r
+@@ -0,0 +1,7 @@\r
++# Required for Python to search this directory for module files\r
+END
+ # Header keys to check
+ svnConvertedText => <<END, # No single quotes to allow interpolation of "\r"
+Index: WebKitTools/Scripts/webkitpy/move_test.py\r
+===================================================================\r
+--- WebKitTools/Scripts/webkitpy/move_test.py (revision 53047) (from WebKitTools/Scripts/webkitpy/__init__.py:53048)\r
++++ WebKitTools/Scripts/webkitpy/move_test.py (working copy)\r
+END
+ copiedFromPath => "WebKitTools/Scripts/webkitpy/__init__.py",
+ copiedFromVersion => "53048",
+ indexPath => "WebKitTools/Scripts/webkitpy/move_test.py",
+ version => undef,
+ # Other values to check
+ foundHeaderEnding => 1,
+ lastReadLine => "@@ -0,0 +1,7 @@\r\n",
+ nextLine => "+# Required for Python to search this directory for module files\r\n",
+},
+{
+ # New test
+ diffName => "SVN: path corrections",
+ inputText => <<'END',
+Index: WebKitTools/Scripts/webkitpy/move_test.py
+===================================================================
+--- bad_path (revision 53047) (from WebKitTools/Scripts/webkitpy/__init__.py:53048)
++++ bad_path (working copy)
+@@ -0,0 +1,7 @@
++# Required for Python to search this directory for module files
+END
+ # Header keys to check
+ svnConvertedText => <<'END',
+Index: WebKitTools/Scripts/webkitpy/move_test.py
+===================================================================
+--- WebKitTools/Scripts/webkitpy/move_test.py (revision 53047) (from WebKitTools/Scripts/webkitpy/__init__.py:53048)
++++ WebKitTools/Scripts/webkitpy/move_test.py (working copy)
+END
+ copiedFromPath => "WebKitTools/Scripts/webkitpy/__init__.py",
+ copiedFromVersion => "53048",
+ indexPath => "WebKitTools/Scripts/webkitpy/move_test.py",
+ version => undef,
+ # Other values to check
+ foundHeaderEnding => 1,
+ lastReadLine => "@@ -0,0 +1,7 @@\n",
+ nextLine => "+# Required for Python to search this directory for module files\n",
+},
+{
+ # New test
+ diffName => "Git: simple",
+ inputText => <<'END',
+diff --git a/WebCore/rendering/style/StyleFlexibleBoxData.h b/WebCore/rendering/style/StyleFlexibleBoxData.h
+index f5d5e74..3b6aa92 100644
+--- a/WebCore/rendering/style/StyleFlexibleBoxData.h
++++ b/WebCore/rendering/style/StyleFlexibleBoxData.h
+@@ -47,7 +47,6 @@ public:
+END
+ # Header keys to check
+ svnConvertedText => <<'END',
+Index: WebCore/rendering/style/StyleFlexibleBoxData.h
+===================================================================
+--- WebCore/rendering/style/StyleFlexibleBoxData.h
++++ WebCore/rendering/style/StyleFlexibleBoxData.h
+END
+ copiedFromPath => undef,
+ copiedFromVersion => undef,
+ indexPath => "WebCore/rendering/style/StyleFlexibleBoxData.h",
+ version => undef,
+ # Other values to check
+ foundHeaderEnding => 1,
+ lastReadLine => "@@ -47,7 +47,6 @@ public:\n",
+ nextLine => undef,
+},
+{
+ # New test
+ diffName => "Git: unrecognized lines",
+ inputText => <<'END',
+diff --git a/LayoutTests/http/tests/security/listener/xss-inactive-closure.html b/LayoutTests/http/tests/security/listener/xss-inactive-closure.html
+new file mode 100644
+index 0000000..3c9f114
+--- /dev/null
++++ b/LayoutTests/http/tests/security/listener/xss-inactive-closure.html
+@@ -0,0 +1,34 @@
++<html>
+END
+ # Header keys to check
+ svnConvertedText => <<'END',
+Index: LayoutTests/http/tests/security/listener/xss-inactive-closure.html
+new file mode 100644
+index 0000000..3c9f114
+--- LayoutTests/http/tests/security/listener/xss-inactive-closure.html
++++ LayoutTests/http/tests/security/listener/xss-inactive-closure.html
+END
+ copiedFromPath => undef,
+ copiedFromVersion => undef,
+ indexPath => "LayoutTests/http/tests/security/listener/xss-inactive-closure.html",
+ version => undef,
+ # Other values to check
+ foundHeaderEnding => 1,
+ lastReadLine => "@@ -0,0 +1,34 @@\n",
+ nextLine => "+<html>\n",
+},
+);
+
+plan(tests => @diffTests * 8); # Eight assertions per call to doDiffTest().
+
+foreach my $diffTestHashRef (@diffTests) {
+ doDiffTest($diffTestHashRef);
+}
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list