Title: [171954] trunk/Tools
Revision
171954
Author
m...@apple.com
Date
2014-08-01 16:10:50 -0700 (Fri, 01 Aug 2014)

Log Message

commit-log-editor uses a non-standard message format when git index contains no ChangeLog changes
https://bugs.webkit.org/show_bug.cgi?id=135527

Reviewed by Tim Horton.

* Scripts/commit-log-editor:
In the case of a git repository when there are no changed ChangeLog files, changed to pass
the --delimiters option to prepare-ChangeLog, then process each entry in the output using
commitMessageFromChangeLogEntry.
(commitMessageFromChangeLogEntry): Factored out from createCommitMessage.
(sortKey): Factored out from createCommitMessage.
(createCommitMessage): Changed to use new sortKey and commitMessageFromChangeLogEntry
subroutines.

* Scripts/prepare-ChangeLog:
(main): Parse new --delimiters option.
(generateNewChangeLogs): When --no-write and --delimiters are both specified, always print
the label before each change log entry, and a "~" delimiter on a new line after each entry.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (171953 => 171954)


--- trunk/Tools/ChangeLog	2014-08-01 22:49:51 UTC (rev 171953)
+++ trunk/Tools/ChangeLog	2014-08-01 23:10:50 UTC (rev 171954)
@@ -1,3 +1,24 @@
+2014-08-01  Dan Bernstein  <m...@apple.com>
+
+        commit-log-editor uses a non-standard message format when git index contains no ChangeLog changes
+        https://bugs.webkit.org/show_bug.cgi?id=135527
+
+        Reviewed by Tim Horton.
+
+        * Scripts/commit-log-editor:
+        In the case of a git repository when there are no changed ChangeLog files, changed to pass
+        the --delimiters option to prepare-ChangeLog, then process each entry in the output using
+        commitMessageFromChangeLogEntry.
+        (commitMessageFromChangeLogEntry): Factored out from createCommitMessage.
+        (sortKey): Factored out from createCommitMessage.
+        (createCommitMessage): Changed to use new sortKey and commitMessageFromChangeLogEntry
+        subroutines.
+
+        * Scripts/prepare-ChangeLog:
+        (main): Parse new --delimiters option.
+        (generateNewChangeLogs): When --no-write and --delimiters are both specified, always print
+        the label before each change log entry, and a "~" delimiter on a new line after each entry.
+
 2014-08-01  Bear Travis  <betra...@adobe.com>
 
         [Feature Queries] Enable Feature Queries on EFL/GTK

Modified: trunk/Tools/Scripts/commit-log-editor (171953 => 171954)


--- trunk/Tools/Scripts/commit-log-editor	2014-08-01 22:49:51 UTC (rev 171953)
+++ trunk/Tools/Scripts/commit-log-editor	2014-08-01 23:10:50 UTC (rev 171954)
@@ -38,6 +38,8 @@
 use VCSUtils;
 use webkitdirs;
 
+sub commitMessageFromChangeLogEntry($);
+sub sortKey($);
 sub createCommitMessage(@);
 sub loadTermReadKey();
 sub normalizeLineEndings($$);
@@ -176,11 +178,34 @@
         chomp($webkitGenerateCommitMessage = `git config --bool core.webkitGenerateCommitMessage`);
     }
     if ($webkitGenerateCommitMessage ne "false") {
-        open CHANGELOG_ENTRIES, "-|", "$FindBin::Bin/prepare-ChangeLog --git-index --no-write --no-style" or die "prepare-ChangeLog failed: $!.\n";
-        while (<CHANGELOG_ENTRIES>) {
-            print NEWLOG normalizeLineEndings($_, $endl);
+        my %changeLogSort;
+        my %changeLogContents;
+        open my $changeLogEntries, "-|", "$FindBin::Bin/prepare-ChangeLog --git-index --no-write --no-style --delimiters" or die "prepare-ChangeLog failed: $!.\n";
+
+        while (!eof($changeLogEntries)) {
+            my $label = <$changeLogEntries>;
+            chomp $label;
+            $label =~ s/:$//;
+            ($changeLogContents{$label}) = commitMessageFromChangeLogEntry($changeLogEntries);
+            $changeLogSort{sortKey($label)} = $label;
         }
-        close CHANGELOG_ENTRIES;
+        close $changeLogEntries;
+
+        my $commonPrefix = removeLongestCommonPrefixEndingInNewline(%changeLogContents);
+
+        my @result;
+        push @result, normalizeLineEndings($commonPrefix, $endl);
+        for my $sortKey (sort keys %changeLogSort) {
+            my $label = $changeLogSort{$sortKey};
+            next if ($changeLogContents{$label} eq "\n");
+            if (keys %changeLogSort > 1) {
+                push @result, normalizeLineEndings("\n", $endl);
+                push @result, normalizeLineEndings("$label: ", $endl);
+            }
+            push @result, normalizeLineEndings($changeLogContents{$label}, $endl);
+        }
+
+        print NEWLOG join '', @result;
     }
 } else {
     print NEWLOG createCommitMessage(@changeLogs);
@@ -209,68 +234,89 @@
 
 unlink "$log.edit";
 
-sub createCommitMessage(@)
+sub commitMessageFromChangeLogEntry($)
 {
-    my @changeLogs = @_;
+    my ($changeLog) = @_;
 
-    my $topLevel = determineVCSRoot();
+    my $commitMessage = "";
+    my $blankLines = "";
+    my $lineCount = 0;
+    my $date = "";
+    my $author = "";
+    my $email = "";
+    my $hasAuthorInfoToWrite = 0;
 
-    my %changeLogSort;
-    my %changeLogContents;
-    for my $changeLog (@changeLogs) {
-        open CHANGELOG, $changeLog or die "Can't open $changeLog";
-        my $contents = "";
-        my $blankLines = "";
-        my $lineCount = 0;
-        my $date = "";
-        my $author = "";
-        my $email = "";
-        my $hasAuthorInfoToWrite = 0;
-        while (<CHANGELOG>) {
-            if (/^\S/) {
-                last if $contents;
-            }
-            if (/\S/) {
-                $contents .= $blankLines if $contents;
-                $blankLines = "";
+    while (<$changeLog>) {
+        if (/^\S/) {
+            last if $commitMessage;
+        }
+        if (/\S/) {
+            $commitMessage .= $blankLines if $commitMessage;
+            $blankLines = "";
 
-                my $line = $_;
+            my $line = $_;
+            # Remove indentation spaces
+            $line =~ s/^ {8}//;
 
-                # Remove indentation spaces
-                $line =~ s/^ {8}//;
+            # Grab the author and the date line
+            if ($line =~ m/^([0-9]{4}-[0-9]{2}-[0-9]{2})\s+(.*[^\s])\s+<(.*)>/ && $lineCount == 0) {
+                $date = $1;
+                $author = $2;
+                $email = $3;
+                $hasAuthorInfoToWrite = 1;
+                next;
+            }
 
-                # Grab the author and the date line
-                if ($line =~ m/^([0-9]{4}-[0-9]{2}-[0-9]{2})\s+(.*[^\s])\s+<(.*)>/ && $lineCount == 0) {
-                    $date = $1;
-                    $author = $2;
-                    $email = $3;
-                    $hasAuthorInfoToWrite = 1;
-                    next;
-                }
+            if ($hasAuthorInfoToWrite) {
+                my $isReviewedByLine = $line =~ m/^(?:Reviewed|Rubber[ \-]?stamped) by/;
+                my $isModifiedFileLine = $line =~ m/^\* .*:/;
 
-                if ($hasAuthorInfoToWrite) {
-                    my $isReviewedByLine = $line =~ m/^(?:Reviewed|Rubber[ \-]?stamped) by/;
-                    my $isModifiedFileLine = $line =~ m/^\* .*:/;
-
-                    # Insert the authorship line if needed just above the "Reviewed by" line or the
-                    # first modified file (whichever comes first).
-                    if ($isReviewedByLine || $isModifiedFileLine) {
-                        $hasAuthorInfoToWrite = 0;
-                        my $authorshipString = patchAuthorshipString($author, $email, $date);
-                        if ($authorshipString) {
-                            $contents .= "$authorshipString\n";
-                            $contents .= "\n" if $isModifiedFileLine;
-                        }
+                # Insert the authorship line if needed just above the "Reviewed by" line or the
+                # first modified file (whichever comes first).
+                if ($isReviewedByLine || $isModifiedFileLine) {
+                    $hasAuthorInfoToWrite = 0;
+                    my $authorshipString = patchAuthorshipString($author, $email, $date);
+                    if ($authorshipString) {
+                        $commitMessage .= "$authorshipString\n";
+                        $commitMessage .= "\n" if $isModifiedFileLine;
                     }
                 }
+            }
 
 
-                $lineCount++;
-                $contents .= $line;
-            } else {
-                $blankLines .= $_;
-            }
+            $lineCount++;
+            $commitMessage .= $line;
+        } else {
+            $blankLines .= $_;
         }
+    }
+    return ($commitMessage, $hasAuthorInfoToWrite, $date, $author, $email);
+}
+
+sub sortKey($)
+{
+    my ($label) = @_;
+    my $sortKey = lc $label;
+    if ($label eq "top level") {
+        $sortKey = "";
+    } elsif ($label eq "LayoutTests") {
+        $sortKey = lc "~, LayoutTests last";
+    }
+    return $sortKey;
+}
+
+sub createCommitMessage(@)
+{
+    my @changeLogs = @_;
+
+    my $topLevel = determineVCSRoot();
+
+    my %changeLogSort;
+    my %changeLogContents;
+    for my $changeLog (@changeLogs) {
+        open my $changeLogFile, $changeLog or die "Can't open $changeLog";
+
+        my ($contents, $hasAuthorInfoToWrite, $date, $author, $email) = commitMessageFromChangeLogEntry($changeLogFile);
         if ($hasAuthorInfoToWrite) {
             # We didn't find anywhere to put the authorship info, so just put it at the end.
             my $authorshipString = patchAuthorshipString($author, $email, $date);
@@ -278,21 +324,14 @@
             $hasAuthorInfoToWrite = 0;
         }
 
-        close CHANGELOG;
+        close $changeLogFile;
 
         $changeLog = File::Spec->abs2rel(File::Spec->rel2abs($changeLog), $topLevel);
 
         my $label = dirname($changeLog);
         $label = "top level" unless length $label;
 
-        my $sortKey = lc $label;
-        if ($label eq "top level") {
-            $sortKey = "";
-        } elsif ($label eq "LayoutTests") {
-            $sortKey = lc "~, LayoutTests last";
-        }
-
-        $changeLogSort{$sortKey} = $label;
+        $changeLogSort{sortKey($label)} = $label;
         $changeLogContents{$label} = $contents;
     }
 

Modified: trunk/Tools/Scripts/prepare-ChangeLog (171953 => 171954)


--- trunk/Tools/Scripts/prepare-ChangeLog	2014-08-01 22:49:51 UTC (rev 171953)
+++ trunk/Tools/Scripts/prepare-ChangeLog	2014-08-01 23:10:50 UTC (rev 171954)
@@ -80,7 +80,7 @@
 sub generateFileList(\%$$$);
 sub generateFunctionLists($$$$$);
 sub generateFunctionListsByRanges($$$$);
-sub generateNewChangeLogs($$$$$$$$$$$);
+sub generateNewChangeLogs($$$$$$$$$$$$);
 sub getLatestChangeLogs($);
 sub get_function_line_ranges($$);
 sub get_function_line_ranges_for_cpp($$);
@@ -131,12 +131,14 @@
     my $checkWebKitStyle;
     my $openChangeLogs = 0;
     my $writeChangeLogs = 1;
+    my $delimiters = 0;
     my $showHelp = 0;
     my $spewDiff = $ENV{"PREPARE_CHANGELOG_DIFF"};
     my $updateChangeLogs = 1;
     my $parseOptionsResult =
         GetOptions("diff|d!" => \$spewDiff,
                    "bug|b:i" => \$bugNumber,
+                   "delimiters" => \$delimiters,
                    "description:s" => \$bugDescription,
                    "name:s" => \$name,
                    "email:s" => \$emailAddress,
@@ -164,6 +166,7 @@
         print STDERR "  -o|--open       Open ChangeLogs in an editor when done\n";
         print STDERR "  --[no-]update   Update ChangeLogs from svn before adding entry (default: update)\n";
         print STDERR "  --[no-]write    Write ChangeLogs to disk (otherwise send new entries to stdout) (default: write)\n";
+        print STDERR "  --delimiters    When writing to stdout, label and print a \"~\" after each entry\n";
         print STDERR "  --email=        Specify the email address to be used in the patch\n";
         return 1;
     }
@@ -222,7 +225,7 @@
         resolveConflictedChangeLogs($changeLogs);
     }
 
-    generateNewChangeLogs($prefixes, $filesInChangeLog, $addedRegressionTests, $functionLists, $bugURL, $bugDescription, $name, $emailAddress, $gitReviewer, $gitCommit, $writeChangeLogs);
+    generateNewChangeLogs($prefixes, $filesInChangeLog, $addedRegressionTests, $functionLists, $bugURL, $bugDescription, $name, $emailAddress, $gitReviewer, $gitCommit, $writeChangeLogs, $delimiters);
 
     if ($writeChangeLogs) {
         print STDERR "-- Please remember to include a detailed description in your ChangeLog entry. --\n-- See <http://webkit.org/coding/contributing.html> for more info --\n";
@@ -522,9 +525,9 @@
     close RESOLVE;
 }
 
-sub generateNewChangeLogs($$$$$$$$$$$)
+sub generateNewChangeLogs($$$$$$$$$$$$)
 {
-    my ($prefixes, $filesInChangeLog, $addedRegressionTests, $functionLists, $bugURL, $bugDescription, $name, $emailAddress, $gitReviewer, $gitCommit, $writeChangeLogs) = @_;
+    my ($prefixes, $filesInChangeLog, $addedRegressionTests, $functionLists, $bugURL, $bugDescription, $name, $emailAddress, $gitReviewer, $gitCommit, $writeChangeLogs, $delimiters) = @_;
 
     # Generate new ChangeLog entries and (optionally) write out new ChangeLog files.
     foreach my $prefix (@$prefixes) {
@@ -547,7 +550,7 @@
             open CHANGE_LOG, "> ${changeLogPath}" or die "Could not write ${changeLogPath}\n.";
         } else {
             open CHANGE_LOG, ">-" or die "Could not write to STDOUT\n.";
-            print substr($prefix, 0, length($prefix) - 1) . ":\n\n" unless (scalar @$prefixes) == 1;
+            print substr($prefix, 0, length($prefix) - 1) . ":\n\n" unless (scalar @$prefixes) == 1 && !$delimiters;
         }
 
         my $date = changeLogDate(ChangeLogTimeZone);
@@ -582,6 +585,7 @@
             print CHANGE_LOG normalizeLineEndings("\n", $endl), @old_change_log;
         } else {
             print CHANGE_LOG "\n";
+            print "~\n"  if $delimiters;
         }
 
         close CHANGE_LOG;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to