webengine/osswebengine/WebKitTools/Scripts/commit-log-editor
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 #!/usr/bin/perl -w
       
     2 
       
     3 # Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
       
     4 #
       
     5 # Redistribution and use in source and binary forms, with or without
       
     6 # modification, are permitted provided that the following conditions
       
     7 # are met:
       
     8 #
       
     9 # 1.  Redistributions of source code must retain the above copyright
       
    10 #     notice, this list of conditions and the following disclaimer. 
       
    11 # 2.  Redistributions in binary form must reproduce the above copyright
       
    12 #     notice, this list of conditions and the following disclaimer in the
       
    13 #     documentation and/or other materials provided with the distribution. 
       
    14 # 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
       
    15 #     its contributors may be used to endorse or promote products derived
       
    16 #     from this software without specific prior written permission. 
       
    17 #
       
    18 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
       
    19 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
       
    21 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
       
    22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
       
    23 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
       
    24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
       
    25 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
       
    27 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    28 
       
    29 # Script to put change log comments in as default check-in comment.
       
    30 
       
    31 use strict;
       
    32 use FindBin;
       
    33 use lib $FindBin::Bin;
       
    34 use VCSUtils;
       
    35 use webkitdirs;
       
    36 
       
    37 my $log = $ARGV[0];
       
    38 
       
    39 my $baseDir = baseProductDir();
       
    40 
       
    41 my $editor = $ENV{SVN_LOG_EDITOR};
       
    42 if (!$editor) {
       
    43     $editor = $ENV{CVS_LOG_EDITOR};
       
    44 }
       
    45 if (!$editor) {
       
    46     my $builtEditorApplication = "$baseDir/Release/Commit Log Editor.app/Contents/MacOS/Commit Log Editor";
       
    47     $editor = $builtEditorApplication if -x $builtEditorApplication;
       
    48 }
       
    49 if (!$editor) {
       
    50     my $builtEditorApplication = "$baseDir/Debug/Commit Log Editor.app/Contents/MacOS/Commit Log Editor";
       
    51     $editor = $builtEditorApplication if -x $builtEditorApplication;
       
    52 }
       
    53 if (!$editor) {
       
    54     my $installedEditorApplication = "$ENV{HOME}/Applications/Commit Log Editor.app/Contents/MacOS/Commit Log Editor";
       
    55     $editor = $installedEditorApplication if -x $installedEditorApplication;
       
    56 }
       
    57 if (!$editor) {
       
    58     $editor = $ENV{EDITOR} || "/usr/bin/vi";
       
    59 }
       
    60 
       
    61 my $inChangesToBeCommitted = !isGit();
       
    62 my @changeLogs = ();
       
    63 my $logContents = "";
       
    64 my $existingLog = 0;
       
    65 open LOG, $log or die;
       
    66 while (<LOG>) {
       
    67     if (isGit()) {
       
    68         if (/^# Changes to be committed:$/) {
       
    69             $inChangesToBeCommitted = 1;
       
    70         } elsif ($inChangesToBeCommitted && /^# \S/) {
       
    71             $inChangesToBeCommitted = 0;
       
    72         }
       
    73     }
       
    74 
       
    75     $logContents .= $_;
       
    76     $existingLog = isGit() && !(/^#/ || /^\s*$/) unless $existingLog;
       
    77 
       
    78     push @changeLogs, makeFilePathRelative($1) if $inChangesToBeCommitted && (/^M....(.*ChangeLog)$/ || /^#\tmodified:   (.*ChangeLog)/) && !/-ChangeLog/;
       
    79 }
       
    80 close LOG;
       
    81 
       
    82 # Don't change anything if there's already a log message
       
    83 # (as can happen with git-commit --amend)
       
    84 exec $editor, @ARGV if $existingLog;
       
    85 
       
    86 my %changeLogSort;
       
    87 my %changeLogContents;
       
    88 for my $changeLog (@changeLogs) {
       
    89     open CHANGELOG, $changeLog or die "Can't open $changeLog";
       
    90     my $contents = "";
       
    91     my $blankLines = "";
       
    92     while (<CHANGELOG>) {
       
    93         if (/^\S/) {
       
    94             last if $contents;
       
    95             next;
       
    96         } elsif (/\S/) {
       
    97             $contents .= $blankLines if $contents;
       
    98             $blankLines = "";
       
    99             $contents .= $_;
       
   100         } else {
       
   101             $blankLines .= $_;
       
   102         }
       
   103     }
       
   104     close CHANGELOG;
       
   105 
       
   106     my $label;
       
   107     if ($changeLog =~ m-^(.*/)?([^/]+)/ChangeLog$-) {
       
   108         $label = $2;
       
   109     } else {
       
   110         $label = "top level";
       
   111     }
       
   112 
       
   113     my $sortKey = lc $label;
       
   114     if ($label eq "top level") {
       
   115         $sortKey = "";
       
   116     } elsif ($label eq "Tools") {
       
   117         $sortKey = "-, just after top level";
       
   118     } elsif ($label eq "WebBrowser") {
       
   119         $sortKey = lc "WebKit, WebBrowser after";
       
   120     } elsif ($label eq "WebCore") {
       
   121         $sortKey = lc "WebFoundation, WebCore after";
       
   122     } elsif ($label eq "LayoutTests") {
       
   123         $sortKey = lc "~, LayoutTests last";
       
   124     }
       
   125 
       
   126     $changeLogSort{$sortKey} = $label;
       
   127     $changeLogContents{$label} = $contents;
       
   128 }
       
   129 
       
   130 my $first = 1;
       
   131 open NEWLOG, ">$log.edit" or die;
       
   132 for my $sortKey (sort keys %changeLogSort) {
       
   133     my $label = $changeLogSort{$sortKey};
       
   134     if (keys %changeLogSort > 1) {
       
   135         print NEWLOG "\n" if !$first;
       
   136         $first = 0;
       
   137         print NEWLOG "$label:\n\n";
       
   138     }
       
   139     print NEWLOG $changeLogContents{$label};
       
   140 }
       
   141 print NEWLOG $logContents;
       
   142 close NEWLOG;
       
   143 
       
   144 system $editor, "$log.edit";
       
   145 
       
   146 open NEWLOG, "$log.edit" or exit;
       
   147 my $foundComment = 0;
       
   148 while (<NEWLOG>) {
       
   149     $foundComment = 1 if (/\S/ && !/^CVS:/);
       
   150 }
       
   151 close NEWLOG;
       
   152 
       
   153 if ($foundComment) {
       
   154     open NEWLOG, "$log.edit" or die;
       
   155     open LOG, ">$log" or die;
       
   156     while (<NEWLOG>) {
       
   157         print LOG;
       
   158     }
       
   159     close LOG;
       
   160     close NEWLOG;
       
   161 }
       
   162 
       
   163 unlink "$log.edit";