Changeset 69177 in webkit


Ignore:
Timestamp:
Oct 5, 2010 9:58:55 PM (14 years ago)
Author:
dbates@webkit.org
Message:

2010-10-05 Daniel Bates <dbates@rim.com>

Reviewed by David Kilzer.

Add infrastructure to towards detecting change log diffs that aren't at the top of the ChangeLog
https://bugs.webkit.org/show_bug.cgi?id=46058

Make VCSUtils::fixChangeLogPatch() return a reference to a hash
structure so as to support returning additional information
about a change log diff.

Currently, VCSUtils::fixChangeLogPatch() returns a string that
represents the change log diff. Towards supporting the return
of additional information, such as whether the change log diff
inserts an entry at the top of the ChangeLog file, we need to
make VCSUtils::fixChangeLogPatch() return a reference to hash
structure.

  • Scripts/VCSUtils.pm:
    • Modified fixChangeLogPatch() to return a reference to a hash structure.
    • Added documentation to fixChangeLogPatch().
    • Modified call site in mergeChangeLogs() as necessary.
  • Scripts/svn-apply:
    • Modified call site in patch() as necessary.
  • Scripts/svn-create-patch:
    • Modified call site in generateDiff() as necessary.
  • Scripts/svn-unapply:
    • Modified call site in patch() as necessary.
  • Scripts/webkitperl/VCSUtils_unittest/fixChangeLogPatch.pl:
    • Modified the unit tests as necessary.
Location:
trunk/WebKitTools
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r69171 r69177  
     12010-10-05  Daniel Bates  <dbates@rim.com>
     2
     3        Reviewed by David Kilzer.
     4
     5        Add infrastructure to towards detecting change log diffs that aren't at the top of the ChangeLog
     6        https://bugs.webkit.org/show_bug.cgi?id=46058
     7
     8        Make VCSUtils::fixChangeLogPatch() return a reference to a hash
     9        structure so as to support returning additional information
     10        about a change log diff.
     11
     12        Currently, VCSUtils::fixChangeLogPatch() returns a string that
     13        represents the change log diff. Towards supporting the return
     14        of additional information, such as whether the change log diff
     15        inserts an entry at the top of the ChangeLog file, we need to
     16        make VCSUtils::fixChangeLogPatch() return a reference to hash
     17        structure.
     18
     19        * Scripts/VCSUtils.pm:
     20          - Modified fixChangeLogPatch() to return a reference to a
     21            hash structure.
     22          - Added documentation to fixChangeLogPatch().
     23          - Modified call site in mergeChangeLogs() as necessary.
     24        * Scripts/svn-apply:
     25          - Modified call site in patch() as necessary.
     26        * Scripts/svn-create-patch:
     27          - Modified call site in generateDiff() as necessary.
     28        * Scripts/svn-unapply:
     29          - Modified call site in patch() as necessary.
     30        * Scripts/webkitperl/VCSUtils_unittest/fixChangeLogPatch.pl:
     31          - Modified the unit tests as necessary.
     32
    1332010-10-05  Tony Chang  <tony@chromium.org>
    234
  • trunk/WebKitTools/Scripts/VCSUtils.pm

    r66800 r69177  
    12851285#
    12861286# This subroutine has unit tests in VCSUtils_unittest.pl.
     1287#
     1288# Returns $changeLogHashRef:
     1289#   $changeLogHashRef: a hash reference representing a change log patch.
     1290#     patch: a ChangeLog patch equivalent to the given one, but with the
     1291#            newest ChangeLog entry inserted at the top of the file, if possible.
     1292#     hasOverlappingLines: the value 1 if the change log entry overlaps
     1293#                          some lines of another change log entry. This can
     1294#                          happen when deliberately inserting a new ChangeLog
     1295#                          entry earlier in the file above an entry with
     1296#                          the same date and author.                     
    12871297sub fixChangeLogPatch($)
    12881298{
     
    13021312    }
    13031313    my $chunkStartIndex = ++$i;
     1314    my %changeLogHashRef;
    13041315
    13051316    # Optimization: do not process if new lines already begin the chunk.
    13061317    if (substr($lines[$i], 0, 1) eq "+") {
    1307         return $patch;
     1318        $changeLogHashRef{patch} = $patch;
     1319        return \%changeLogHashRef;
    13081320    }
    13091321
     
    13221334            next;
    13231335        }
    1324         return $patch; # Do not change if, for example, "-" or "@" found.
     1336        $changeLogHashRef{patch} = $patch; # Do not change if, for example, "-" or "@" found.
     1337        return \%changeLogHashRef;
    13251338    }
    13261339    if ($i >= @lines) {
    1327         return $patch; # Do not change if date not found.
     1340        $changeLogHashRef{patch} = $patch; # Do not change if date not found.
     1341        return \%changeLogHashRef;
    13281342    }
    13291343    my $dateStartIndex = $i;
     
    13681382        my $newLine = pop(@overlappingLines);
    13691383        if ($text ne substr($newLine, 1)) {
    1370             return $patch; # Unexpected difference.
     1384            $changeLogHashRef{patch} = $patch; # Unexpected difference.
     1385            return \%changeLogHashRef;
    13711386        }
    13721387        $lines[$i] = "+$text";
     
    13801395        # are okay but should not be altered. That way we can find out
    13811396        # if improvements to the script ever become necessary.
    1382         return $patch; # Error: unexpected patch string format.
     1397        $changeLogHashRef{patch} = $patch; # Error: unexpected patch string format.
     1398        return \%changeLogHashRef;
    13831399    }
    13841400    my $skippedFirstLineCount = $1 - 1;
     
    13891405        # This can happen, for example, when deliberately inserting
    13901406        # a new ChangeLog entry earlier in the file.
    1391         return $patch;
     1407        $changeLogHashRef{hasOverlappingLines} = 1;
     1408        $changeLogHashRef{patch} = $patch;
     1409        return \%changeLogHashRef;
    13921410    }
    13931411    # If @overlappingLines > 0, this is where we make use of the
     
    13991417    $lines[$chunkStartIndex - 1] = "@@ -1,$sourceLineCount +1,$targetLineCount @@";
    14001418
    1401     return join($lineEnding, @lines) . "\n"; # patch(1) expects an extra trailing newline.
     1419    $changeLogHashRef{patch} = join($lineEnding, @lines) . "\n"; # patch(1) expects an extra trailing newline.
     1420    return \%changeLogHashRef;
    14021421}
    14031422
     
    15511570
    15521571    open(PATCH, "| patch --force --fuzz=3 --binary $fileNewer > " . File::Spec->devnull()) or die $!;
    1553     print PATCH ($traditionalReject ? $patch : fixChangeLogPatch($patch));
     1572    if ($traditionalReject) {
     1573        print PATCH $patch;
     1574    } else {
     1575        my $changeLogHash = fixChangeLogPatch($patch);
     1576        print PATCH $changeLogHash->{patch};
     1577    }
    15541578    close(PATCH);
    15551579
  • trunk/WebKitTools/Scripts/svn-apply

    r67115 r69177  
    317317        if (basename($fullPath) eq "ChangeLog") {
    318318            my $changeLogDotOrigExisted = -f "${fullPath}.orig";
    319             my $newPatch = setChangeLogDateAndReviewer(fixChangeLogPatch($patch), $reviewer, $epochTime);
     319            my $changeLogHash = fixChangeLogPatch($patch);
     320            my $newPatch = setChangeLogDateAndReviewer($changeLogHash->{patch}, $reviewer, $epochTime);
    320321            applyPatch($newPatch, $fullPath, ["--fuzz=3"]);
    321322            unlink("${fullPath}.orig") if (! $changeLogDotOrigExisted);
  • trunk/WebKitTools/Scripts/svn-create-patch

    r57380 r69177  
    233233    }
    234234    close DIFF;
    235     $patch = fixChangeLogPatch($patch) if basename($file) eq "ChangeLog";
     235    if (basename($file) eq "ChangeLog") {
     236        my $changeLogHash = fixChangeLogPatch($patch);
     237        $patch = $changeLogHash->{patch};   
     238    }
    236239    print $patch;
    237240    if ($fileData->{isBinary}) {
  • trunk/WebKitTools/Scripts/svn-unapply

    r64072 r69177  
    159159        if (basename($fullPath) eq "ChangeLog") {
    160160            my $changeLogDotOrigExisted = -f "${fullPath}.orig";
    161             unapplyPatch(unsetChangeLogDate($fullPath, fixChangeLogPatch($patch)), $fullPath, ["--fuzz=3"]);
     161            my $changeLogHash = fixChangeLogPatch($patch);
     162            unapplyPatch(unsetChangeLogDate($fullPath, $changeLogHash->{patch}), $fullPath, ["--fuzz=3"]);
    162163            unlink("${fullPath}.orig") if (! $changeLogDotOrigExisted);
    163164        } else {
  • trunk/WebKitTools/Scripts/webkitperl/VCSUtils_unittest/fixChangeLogPatch.pl

    r67832 r69177  
    22#
    33# Copyright (C) 2009, 2010 Chris Jerdonek (chris.jerdonek@gmail.com)
     4# Copyright (C) Research In Motion 2010. All rights reserved.
    45#
    56# Redistribution and use in source and binary forms, with or without
     
    3132# Unit tests of VCSUtils::fixChangeLogPatch().
    3233
    33 use Test::Simple tests => 12;
     34use strict;
     35use warnings;
     36
     37use Test::More;
    3438use VCSUtils;
    3539
     
    5458#         * File2:
    5559
    56 my $title;
    57 my $in;
    58 my $out;
    59 
    60 # New test
    61 $title = "fixChangeLogPatch: [no change] In-place change.";
    62 
    63 $in = <<'END';
     60my @testCaseHashRefs = (
     61{ # New test
     62    diffName => "fixChangeLogPatch: [no change] In-place change.",
     63    inputText => <<'END',
    6464--- ChangeLog
    6565+++ ChangeLog
     
    7272         Changed some code on 2010-12-22.
    7373END
    74 
    75 ok(fixChangeLogPatch($in) eq $in, $title);
    76 
    77 # New test
    78 $title = "fixChangeLogPatch: [no change] Remove first entry.";
    79 
    80 $in = <<'END';
     74    expectedReturn => {
     75    patch => <<'END',
     76--- ChangeLog
     77+++ ChangeLog
     78@@ -1,5 +1,5 @@
     79 2010-12-22  Bob  <bob@email.address>
     80 
     81-        Reviewed by Sue.
     82+        Reviewed by Ray.
     83 
     84         Changed some code on 2010-12-22.
     85END
     86    }
     87},
     88{ # New test
     89    diffName => "fixChangeLogPatch: [no change] Remove first entry.",
     90    inputText => <<'END',
    8191--- ChangeLog
    8292+++ ChangeLog
     
    94104         Reviewed by Ray.
    95105END
    96 
    97 ok(fixChangeLogPatch($in) eq $in, $title);
    98 
    99 # New test
    100 $title = "fixChangeLogPatch: [no change] Remove entry in the middle.";
    101 
    102 $in = <<'END';
     106    expectedReturn => {
     107    patch => <<'END',
     108--- ChangeLog
     109+++ ChangeLog
     110@@ -1,11 +1,3 @@
     111-2010-12-22  Bob  <bob@email.address>
     112-
     113-        Reviewed by Ray.
     114-
     115-        Changed some code on 2010-12-22.
     116-
     117-        * File:
     118-
     119 2010-12-22  Alice  <alice@email.address>
     120 
     121         Reviewed by Ray.
     122END
     123    }
     124},
     125{ # New test
     126    diffName => "fixChangeLogPatch: [no change] Remove entry in the middle.",
     127    inputText => <<'END',
    103128--- ChangeLog
    104129+++ ChangeLog
     
    115140         Reviewed by Ray.
    116141END
    117 
    118 ok(fixChangeLogPatch($in) eq $in, $title);
    119 
    120 # New test
    121 $title = "fixChangeLogPatch: [no change] Far apart changes (i.e. more than one chunk).";
    122 
    123 $in = <<'END';
     142    expectedReturn => {
     143    patch => <<'END',
     144--- ChangeLog
     145+++ ChangeLog
     146@@@ -7,10 +7,6 @@
     147 
     148         * File:
     149 
     150-2010-12-22  Bob  <bob@email.address>
     151-
     152-        Changed some code on 2010-12-22.
     153-
     154 2010-12-22  Alice  <alice@email.address>
     155 
     156         Reviewed by Ray.
     157END
     158    }
     159},
     160{ # New test
     161    diffName => "fixChangeLogPatch: [no change] Far apart changes (i.e. more than one chunk).",
     162    inputText => <<'END',
    124163--- ChangeLog
    125164+++ ChangeLog
     
    142181         Changed some code on 2010-12-21.
    143182END
    144 
    145 ok(fixChangeLogPatch($in) eq $in, $title);
    146 
    147 # New test
    148 $title = "fixChangeLogPatch: [no change] First line is new line.";
    149 
    150 $in = <<'END';
     183    expectedReturn => {
     184    patch => <<'END',
     185--- ChangeLog
     186+++ ChangeLog
     187@@ -7,7 +7,7 @@
     188 
     189         * File:
     190 
     191-2010-12-22  Bob  <bob@email.address>
     192+2010-12-22  Bobby <bob@email.address>
     193 
     194         Changed some code on 2010-12-22.
     195 
     196@@ -21,7 +21,7 @@
     197 
     198         * File2:
     199 
     200-2010-12-21  Bob  <bob@email.address>
     201+2010-12-21  Bobby <bob@email.address>
     202 
     203         Changed some code on 2010-12-21.
     204END
     205    }
     206},
     207{ # New test
     208    diffName => "fixChangeLogPatch: [no change] First line is new line.",
     209    inputText => <<'END',
    151210--- ChangeLog
    152211+++ ChangeLog
     
    164223         Reviewed by Ray.
    165224END
    166 
    167 ok(fixChangeLogPatch($in) eq $in, $title);
    168 
    169 # New test
    170 $title = "fixChangeLogPatch: [no change] No date string.";
    171 
    172 $in = <<'END';
     225    expectedReturn => {
     226    patch => <<'END',
     227--- ChangeLog
     228+++ ChangeLog
     229@@ -1,3 +1,11 @@
     230+2009-12-22  Bob  <bob@email.address>
     231+
     232+        Reviewed by Ray.
     233+
     234+        Changed some more code on 2009-12-22.
     235+
     236+        * File:
     237+
     238 2009-12-22  Alice  <alice@email.address>
     239 
     240         Reviewed by Ray.
     241END
     242    }
     243},
     244{ # New test
     245    diffName => "fixChangeLogPatch: [no change] No date string.",
     246    inputText => <<'END',
    173247--- ChangeLog
    174248+++ ChangeLog
     
    182256 
    183257END
    184 
    185 ok(fixChangeLogPatch($in) eq $in, $title);
    186 
    187 # New test
    188 $title = "fixChangeLogPatch: [no change] New entry inserted in middle.";
    189 
    190 $in = <<'END';
     258    expectedReturn => {
     259    patch => <<'END',
     260--- ChangeLog
     261+++ ChangeLog
     262@@ -6,6 +6,7 @@
     263 
     264         * File:
     265         * File2:
     266+        * File3:
     267 
     268 2009-12-21  Alice  <alice@email.address>
     269 
     270END
     271    }
     272},
     273{ # New test
     274    diffName => "fixChangeLogPatch: [no change] New entry inserted in middle.",
     275    inputText => <<'END',
    191276--- ChangeLog
    192277+++ ChangeLog
     
    207292         * File:
    208293END
    209 
    210 ok(fixChangeLogPatch($in) eq $in, $title);
    211 
    212 # New test
    213 $title = "fixChangeLogPatch: [no change] New entry inserted earlier in the file, but after an entry with the same author and date.";
    214 
    215 $in = <<'END';
     294    expectedReturn => {
     295    hasOverlappingLines => 1,
     296    patch => <<'END',
     297--- ChangeLog
     298+++ ChangeLog
     299@@ -11,6 +11,14 @@
     300 
     301         Reviewed by Ray.
     302 
     303+        Changed some more code on 2009-12-21.
     304+
     305+        * File:
     306+
     307+2009-12-21  Alice  <alice@email.address>
     308+
     309+        Reviewed by Ray.
     310+
     311         Changed some code on 2009-12-21.
     312 
     313         * File:
     314END
     315    }
     316},
     317{ # New test
     318    diffName => "fixChangeLogPatch: [no change] New entry inserted earlier in the file, but after an entry with the same author and date.",
     319    inputText => <<'END',
    216320--- ChangeLog
    217321+++ ChangeLog
     
    232336         Changed some code on 2009-12-22.
    233337END
    234 
    235 ok(fixChangeLogPatch($in) eq $in, $title);
    236 
    237 # New test
    238 $title = "fixChangeLogPatch: Leading context includes first line.";
    239 
    240 $in = <<'END';
     338    expectedReturn => {
     339    hasOverlappingLines => 1,
     340    patch => <<'END',
     341--- ChangeLog
     342+++ ChangeLog
     343@@ -70,6 +70,14 @@
     344 
     345 2009-12-22  Alice  <alice@email.address>
     346 
     347+        Reviewed by Sue.
     348+
     349+        Changed some more code on 2009-12-22.
     350+
     351+        * File:
     352+
     353+2009-12-22  Alice  <alice@email.address>
     354+
     355         Reviewed by Ray.
     356 
     357         Changed some code on 2009-12-22.
     358END
     359    }
     360},
     361{ # New test
     362    diffName => "fixChangeLogPatch: Leading context includes first line.",
     363    inputText => <<'END',
    241364--- ChangeLog
    242365+++ ChangeLog
     
    256379         Changed some code on 2009-12-22.
    257380END
    258 
    259 $out = <<'END';
     381    expectedReturn => {
     382    patch => <<'END',
    260383--- ChangeLog
    261384+++ ChangeLog
     
    273396         Reviewed by Ray.
    274397END
    275 
    276 ok(fixChangeLogPatch($in) eq $out, $title);
    277 
    278 # New test
    279 $title = "fixChangeLogPatch: Leading context does not include first line.";
    280 
    281 $in = <<'END';
     398    }
     399},
     400{ # New test
     401    diffName => "fixChangeLogPatch: Leading context does not include first line.",
     402    inputText => <<'END',
    282403@@ -2,6 +2,14 @@
    283404 
     
    296417         * File:
    297418END
    298 
    299 $out = <<'END';
     419    expectedReturn => {
     420    patch => <<'END',
    300421@@ -1,3 +1,11 @@
    301422+2009-12-22  Alice  <alice@email.address>
     
    311432         Reviewed by Ray.
    312433END
    313 
    314 ok(fixChangeLogPatch($in) eq $out, $title);
    315 
    316 # New test
    317 $title = "fixChangeLogPatch: Non-consecutive line additions.";
     434    }
     435},
     436{ # New test
     437    diffName => "fixChangeLogPatch: Non-consecutive line additions.",
    318438
    319439# This can occur, for example, if the new ChangeLog entry includes
     
    322442# ChangeLog entry with the first blank line of the old.
    323443# The svn diff command with the default --diff-cmd has done this.
    324 $in = <<'END';
     444    inputText => <<'END',
    325445@@ -1,5 +1,11 @@
    326446 2009-12-22  Alice  <alice@email.address>
     
    336456         Changed some code on 2009-12-22.
    337457END
    338 
    339 $out = <<'END';
     458    expectedReturn => {
     459    patch => <<'END',
    340460@@ -1,3 +1,9 @@
    341461+2009-12-22  Alice  <alice@email.address>
     
    349469         Reviewed by Ray.
    350470END
    351 
    352 ok(fixChangeLogPatch($in) eq $out, $title);
    353 
    354 # New test
    355 $title = "fixChangeLogPatch: Additional edits after new entry.";
    356 
    357 $in = <<'END';
     471    }
     472},
     473{ # New test
     474    diffName => "fixChangeLogPatch: Additional edits after new entry.",
     475    inputText => <<'END',
    358476@@ -2,10 +2,17 @@
    359477 
     
    376494 
    377495END
    378 
    379 $out = <<'END';
     496    expectedReturn => {
     497    patch => <<'END',
    380498@@ -1,11 +1,18 @@
    381499+2009-12-22  Alice  <alice@email.address>
     
    399517 
    400518END
    401 
    402 ok(fixChangeLogPatch($in) eq $out, $title);
     519    }
     520},
     521);
     522
     523my $testCasesCount = @testCaseHashRefs;
     524plan(tests => $testCasesCount); # Total number of assertions.
     525
     526foreach my $testCase (@testCaseHashRefs) {
     527    my $testNameStart = "fixChangeLogPatch(): $testCase->{diffName}: comparing";
     528
     529    my $got = VCSUtils::fixChangeLogPatch($testCase->{inputText});
     530    my $expectedReturn = $testCase->{expectedReturn};
     531 
     532    is_deeply($got, $expectedReturn, "$testNameStart return value.");
     533}
Note: See TracChangeset for help on using the changeset viewer.