[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373
eric at webkit.org
eric at webkit.org
Thu Apr 8 00:52:00 UTC 2010
The following commit has been merged in the webkit-1.2 branch:
commit a6f349d0e22d62b6cf847cae5f5cc32a92a6441b
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Wed Dec 30 07:19:18 2009 +0000
2009-12-29 Chris Jerdonek <chris.jerdonek at gmail.com>
Reviewed by David Kilzer.
Fixed a bug in fixChangeLogPatch, made it work correctly in
more circumstances, and added unit tests.
https://bugs.webkit.org/show_bug.cgi?id=32919
* Scripts/VCSUtils.pm:
Rewrote fixChangeLogPatch.
* Scripts/VCSUtils_unittest.pl: Added.
Added 7 unit tests for fixChangeLogPatch.
* Scripts/test-webkit-perl: Added.
Added test harness for unit tests of Perl code.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@52646 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index 2499890..9f60fe4 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,21 @@
+2009-12-29 Chris Jerdonek <chris.jerdonek at gmail.com>
+
+ Reviewed by David Kilzer.
+
+ Fixed a bug in fixChangeLogPatch, made it work correctly in
+ more circumstances, and added unit tests.
+
+ https://bugs.webkit.org/show_bug.cgi?id=32919
+
+ * Scripts/VCSUtils.pm:
+ Rewrote fixChangeLogPatch.
+
+ * Scripts/VCSUtils_unittest.pl: Added.
+ Added 7 unit tests for fixChangeLogPatch.
+
+ * Scripts/test-webkit-perl: Added.
+ Added test harness for unit tests of Perl code.
+
2009-12-29 Eric Seidel <eric at webkit.org>
Reviewed by Adam Barth.
diff --git a/WebKitTools/Scripts/VCSUtils.pm b/WebKitTools/Scripts/VCSUtils.pm
index 7638102..aee0827 100644
--- a/WebKitTools/Scripts/VCSUtils.pm
+++ b/WebKitTools/Scripts/VCSUtils.pm
@@ -1,4 +1,5 @@
# Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
+# Copyright (C) 2009 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
@@ -356,64 +357,143 @@ sub gitdiff2svndiff($)
return $_;
}
-# The diff(1) command is greedy when matching lines, so a new ChangeLog entry will
-# have lines of context at the top of a patch when the existing entry has the same
-# date and author as the new entry. Alter the ChangeLog patch so
-# that the added lines ("+") in the patch always start at the beginning of the
-# patch and there are no initial lines of context.
+# 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 "+".
+#
+# If given a patch string not representable as a patch with the above
+# properties, it returns the input back unchanged.
+#
+# WARNING: This subroutine can return an inequivalent patch string if
+# both the beginning of the new ChangeLog file matches the beginning
+# of the source ChangeLog, and the source beginning was modified.
+# Otherwise, it is guaranteed to return an equivalent patch string,
+# if it returns.
+#
+# Applying this subroutine to ChangeLog patches allows svn-apply to
+# insert new ChangeLog entries at the top of the ChangeLog file.
+# svn-apply uses patch with --fuzz=3 to do this. We need to apply
+# this subroutine because the diff(1) command is greedy when matching
+# lines. A new ChangeLog entry with the same date and author as the
+# previous will match and cause the diff to have lines of starting
+# context.
+#
+# This subroutine has unit tests in VCSUtils_unittest.pl.
sub fixChangeLogPatch($)
{
my $patch = shift; # $patch will only contain patch fragments for ChangeLog.
$patch =~ /(\r?\n)/;
my $lineEnding = $1;
- my @patchLines = split(/$lineEnding/, $patch);
-
- # e.g. 2009-06-03 Eric Seidel <eric at webkit.org>
- my $dateLineRegexpString = '^\+(\d{4}-\d{2}-\d{2})' # Consume the leading '+' and the date.
- . '\s+(.+)\s+' # Consume the name.
- . '<([^<>]+)>$'; # And finally the email address.
-
- # Figure out where the patch contents start and stop.
- my $patchHeaderIndex;
- my $firstContentIndex;
- my $trailingContextIndex;
- my $dateIndex;
- my $patchEndIndex = scalar(@patchLines);
- for (my $index = 0; $index < @patchLines; ++$index) {
- my $line = $patchLines[$index];
- if ($line =~ /^\@\@ -\d+,\d+ \+\d+,\d+ \@\@$/) { # e.g. @@ -1,5 +1,18 @@
- if ($patchHeaderIndex) {
- $patchEndIndex = $index; # We only bother to fix up the first patch fragment.
- last;
- }
- $patchHeaderIndex = $index;
+ my @lines = split(/$lineEnding/, $patch);
+
+ my $i = 0; # We reuse the same index throughout.
+
+ # Skip to beginning of first chunk.
+ for (; $i < @lines; ++$i) {
+ if (substr($lines[$i], 0, 1) eq "@") {
+ last;
}
- $firstContentIndex = $index if ($patchHeaderIndex && !$firstContentIndex && $line =~ /^\+[^+]/); # Only match after finding patchHeaderIndex, otherwise we'd match "+++".
- $dateIndex = $index if ($line =~ /$dateLineRegexpString/);
- $trailingContextIndex = $index if ($firstContentIndex && !$trailingContextIndex && $line =~ /^ /);
}
- my $contentLineCount = $trailingContextIndex - $firstContentIndex;
- my $trailingContextLineCount = $patchEndIndex - $trailingContextIndex;
-
- # If we didn't find a date line in the content then this is not a patch we should try and fix.
- return $patch if (!$dateIndex);
-
- # We only need to do anything if the date line is not the first content line.
- return $patch if ($dateIndex == $firstContentIndex);
-
- # Write the new patch.
- my $totalNewContentLines = $contentLineCount + $trailingContextLineCount;
- $patchLines[$patchHeaderIndex] = "@@ -1,$trailingContextLineCount +1,$totalNewContentLines @@"; # Write a new header.
- my @repeatedLines = splice(@patchLines, $dateIndex, $trailingContextIndex - $dateIndex); # The date line and all the content after it that diff saw as repeated.
- splice(@patchLines, $firstContentIndex, 0, @repeatedLines); # Move the repeated content to the top.
- foreach my $line (@repeatedLines) {
- $line =~ s/^\+/ /;
+ my $chunkStartIndex = ++$i;
+
+ # Optimization: do not process if new lines already begin the chunk.
+ if (substr($lines[$i], 0, 1) eq "+") {
+ return $patch;
}
- splice(@patchLines, $trailingContextIndex, $patchEndIndex, @repeatedLines); # Replace trailing context with the repeated content.
- splice(@patchLines, $patchHeaderIndex + 1, $firstContentIndex - $patchHeaderIndex - 1); # Remove any leading context.
- return join($lineEnding, @patchLines) . "\n"; # patch(1) expects an extra trailing newline.
+ # Skip to first line of newly added ChangeLog entry.
+ # For example, +2009-06-03 Eric Seidel <eric at webkit.org>
+ my $dateStartRegEx = '^\+(\d{4}-\d{2}-\d{2})' # leading "+" and date
+ . '\s+(.+)\s+' # name
+ . '<([^<>]+)>$'; # e-mail address
+
+ for (; $i < @lines; ++$i) {
+ my $line = $lines[$i];
+ my $firstChar = substr($line, 0, 1);
+ if ($line =~ /$dateStartRegEx/) {
+ last;
+ } elsif ($firstChar eq " " or $firstChar eq "+") {
+ next;
+ }
+ return $patch; # Do not change if, for example, "-" or "@" found.
+ }
+ if ($i >= @lines) {
+ return $patch; # Do not change if date not found.
+ }
+ my $dateStartIndex = $i;
+
+ # Rewrite overlapping lines to lead with " ".
+ my @overlappingLines = (); # These will include a leading "+".
+ for (; $i < @lines; ++$i) {
+ my $line = $lines[$i];
+ if (substr($line, 0, 1) ne "+") {
+ last;
+ }
+ push(@overlappingLines, $line);
+ $lines[$i] = " " . substr($line, 1);
+ }
+
+ # Remove excess ending context, if necessary.
+ my $shouldTrimContext = 1;
+ for (; $i < @lines; ++$i) {
+ my $firstChar = substr($lines[$i], 0, 1);
+ if ($firstChar eq " ") {
+ next;
+ } elsif ($firstChar eq "@") {
+ last;
+ }
+ $shouldTrimContext = 0; # For example, if "+" or "-" encountered.
+ last;
+ }
+ my $deletedLineCount = 0;
+ if ($shouldTrimContext) { # Also occurs if end of file reached.
+ splice(@lines, $i - @overlappingLines, @overlappingLines);
+ $deletedLineCount = @overlappingLines;
+ }
+
+ # Work backwards, shifting overlapping lines towards front
+ # while checking that patch stays equivalent.
+ for ($i = $dateStartIndex - 1; $i >= $chunkStartIndex; --$i) {
+ my $line = $lines[$i];
+ if (substr($line, 0, 1) ne " ") {
+ next;
+ }
+ my $text = substr($line, 1);
+ my $newLine = pop(@overlappingLines);
+ if ($text ne substr($newLine, 1)) {
+ return $patch; # Unexpected difference.
+ }
+ $lines[$i] = "+$text";
+ }
+
+ # Finish moving whatever overlapping lines remain, and update
+ # the initial chunk range.
+ my $chunkRangeRegEx = '^\@\@ -(\d+),(\d+) \+\d+,(\d+) \@\@$'; # e.g. @@ -2,6 +2,18 @@
+ if ($lines[$chunkStartIndex - 1] !~ /$chunkRangeRegEx/) {
+ # FIXME: Handle errors differently from ChangeLog files that
+ # are okay but should not be altered. That way we can find out
+ # if improvements to the script ever become necessary.
+ return $patch; # Error: unexpected patch string format.
+ }
+ my $skippedFirstLineCount = $1 - 1;
+ my $oldSourceLineCount = $2;
+ my $oldTargetLineCount = $3;
+
+ if (@overlappingLines != $skippedFirstLineCount) {
+ # This can happen, for example, when deliberately inserting
+ # a new ChangeLog entry earlier in the file.
+ return $patch;
+ }
+ # If @overlappingLines > 0, this is where we make use of the
+ # assumption that the beginning of the source file was not modified.
+ splice(@lines, $chunkStartIndex, 0, @overlappingLines);
+
+ my $sourceLineCount = $oldSourceLineCount + @overlappingLines - $deletedLineCount;
+ my $targetLineCount = $oldTargetLineCount + @overlappingLines - $deletedLineCount;
+ $lines[$chunkStartIndex - 1] = "@@ -1,$sourceLineCount +1,$targetLineCount @@";
+
+ return join($lineEnding, @lines) . "\n"; # patch(1) expects an extra trailing newline.
}
sub gitConfig($)
diff --git a/WebKitTools/Scripts/VCSUtils_unittest.pl b/WebKitTools/Scripts/VCSUtils_unittest.pl
new file mode 100644
index 0000000..5a65cb3
--- /dev/null
+++ b/WebKitTools/Scripts/VCSUtils_unittest.pl
@@ -0,0 +1,294 @@
+#!/usr/bin/perl
+#
+# Copyright (C) 2009 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 Google Inc. 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 VCSUtils.pm.
+
+use Test::Simple tests => 7;
+
+use VCSUtils;
+
+# fixChangeLogPatch
+#
+# The source ChangeLog for these tests is the following:
+#
+# 2009-12-22 Alice <alice at email.address>
+#
+# Reviewed by Ray.
+#
+# Changed some code on 2009-12-22.
+#
+# * File:
+# * File2:
+#
+# 2009-12-21 Alice <alice at email.address>
+#
+# Reviewed by Ray.
+#
+# Changed some code on 2009-12-21.
+#
+# * File:
+# * File2:
+
+my $title;
+my $in;
+my $out;
+
+# New test
+$title = "fixChangeLogPatch: [no change] First line is new line.";
+
+$in = <<'END';
+--- ChangeLog
++++ ChangeLog
+@@ -1,3 +1,11 @@
++2009-12-22 Bob <bob at email.address>
++
++ Reviewed by Ray.
++
++ Changed some more code on 2009-12-22.
++
++ * File:
++
+ 2009-12-22 Alice <alice at email.address>
+
+ Reviewed by Ray.
+END
+
+ok(fixChangeLogPatch($in) eq $in, $title);
+
+# New test
+$title = "fixChangeLogPatch: [no change] No date string.";
+
+$in = <<'END';
+--- ChangeLog
++++ ChangeLog
+@@ -6,6 +6,7 @@
+
+ * File:
+ * File2:
++ * File3:
+
+ 2009-12-21 Alice <alice at email.address>
+
+END
+
+ok(fixChangeLogPatch($in) eq $in, $title);
+
+# New test
+$title = "fixChangeLogPatch: [no change] New entry inserted in middle.";
+
+$in = <<'END';
+--- ChangeLog
++++ ChangeLog
+@@ -11,6 +11,14 @@
+
+ Reviewed by Ray.
+
++ Changed some more code on 2009-12-21.
++
++ * File:
++
++2009-12-21 Alice <alice at email.address>
++
++ Reviewed by Ray.
++
+ Changed some code on 2009-12-21.
+
+ * File:
+END
+
+ok(fixChangeLogPatch($in) eq $in, $title);
+
+# New test
+$title = "fixChangeLogPatch: Leading context includes first line.";
+
+$in = <<'END';
+--- ChangeLog
++++ ChangeLog
+@@ -1,5 +1,13 @@
+ 2009-12-22 Alice <alice at email.address>
+
++ Reviewed by Sue.
++
++ Changed some more code on 2009-12-22.
++
++ * File:
++
++2009-12-22 Alice <alice at email.address>
++
+ Reviewed by Ray.
+
+ Changed some code on 2009-12-22.
+END
+
+$out = <<'END';
+--- ChangeLog
++++ ChangeLog
+@@ -1,3 +1,11 @@
++2009-12-22 Alice <alice at email.address>
++
++ Reviewed by Sue.
++
++ Changed some more code on 2009-12-22.
++
++ * File:
++
+ 2009-12-22 Alice <alice at email.address>
+
+ Reviewed by Ray.
+END
+
+ok(fixChangeLogPatch($in) eq $out, $title);
+
+# New test
+$title = "fixChangeLogPatch: Leading context does not include first line.";
+
+$in = <<'END';
+@@ -2,6 +2,14 @@
+
+ Reviewed by Ray.
+
++ Changed some more code on 2009-12-22.
++
++ * File:
++
++2009-12-22 Alice <alice at email.address>
++
++ Reviewed by Ray.
++
+ Changed some code on 2009-12-22.
+
+ * File:
+END
+
+$out = <<'END';
+@@ -1,3 +1,11 @@
++2009-12-22 Alice <alice at email.address>
++
++ Reviewed by Ray.
++
++ Changed some more code on 2009-12-22.
++
++ * File:
++
+ 2009-12-22 Alice <alice at email.address>
+
+ Reviewed by Ray.
+END
+
+ok(fixChangeLogPatch($in) eq $out, $title);
+
+# New test
+$title = "fixChangeLogPatch: Non-consecutive line additions.";
+
+# This can occur, for example, if the new ChangeLog entry includes
+# trailing white space in the first blank line but not the second.
+# A diff command can then match the second blank line of the new
+# ChangeLog entry with the first blank line of the old.
+# The svn diff command with the default --diff-cmd has done this.
+$in = <<'END';
+@@ -1,5 +1,11 @@
+ 2009-12-22 Alice <alice at email.address>
++ <pretend-whitespace>
++ Reviewed by Ray.
+
++ Changed some more code on 2009-12-22.
++
++2009-12-22 Alice <alice at email.address>
++
+ Reviewed by Ray.
+
+ Changed some code on 2009-12-22.
+END
+
+$out = <<'END';
+@@ -1,3 +1,9 @@
++2009-12-22 Alice <alice at email.address>
++ <pretend-whitespace>
++ Reviewed by Ray.
++
++ Changed some more code on 2009-12-22.
++
+ 2009-12-22 Alice <alice at email.address>
+
+ Reviewed by Ray.
+END
+
+ok(fixChangeLogPatch($in) eq $out, $title);
+
+# New test
+$title = "fixChangeLogPatch: Additional edits after new entry.";
+
+$in = <<'END';
+@@ -2,10 +2,17 @@
+
+ Reviewed by Ray.
+
++ Changed some more code on 2009-12-22.
++
++ * File:
++
++2009-12-22 Alice <alice at email.address>
++
++ Reviewed by Ray.
++
+ Changed some code on 2009-12-22.
+
+ * File:
+- * File2:
+
+ 2009-12-21 Alice <alice at email.address>
+
+END
+
+$out = <<'END';
+@@ -1,11 +1,18 @@
++2009-12-22 Alice <alice at email.address>
++
++ Reviewed by Ray.
++
++ Changed some more code on 2009-12-22.
++
++ * File:
++
+ 2009-12-22 Alice <alice at email.address>
+
+ Reviewed by Ray.
+
+ Changed some code on 2009-12-22.
+
+ * File:
+- * File2:
+
+ 2009-12-21 Alice <alice at email.address>
+
+END
+
+ok(fixChangeLogPatch($in) eq $out, $title);
+
diff --git a/WebKitTools/Scripts/test-webkit-perl b/WebKitTools/Scripts/test-webkit-perl
new file mode 100644
index 0000000..a05a2df
--- /dev/null
+++ b/WebKitTools/Scripts/test-webkit-perl
@@ -0,0 +1,35 @@
+#!/usr/bin/perl
+#
+# Copyright (C) 2009 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 Google Inc. 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.
+
+# Runs unit tests of WebKit Perl code.
+
+use Test::Harness;
+
+runtests("VCSUtils_unittest.pl");
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list