Changeset 171954 in webkit


Ignore:
Timestamp:
Aug 1, 2014 4:10:50 PM (10 years ago)
Author:
mitz@apple.com
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.

Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r171947 r171954  
     12014-08-01  Dan Bernstein  <mitz@apple.com>
     2
     3        commit-log-editor uses a non-standard message format when git index contains no ChangeLog changes
     4        https://bugs.webkit.org/show_bug.cgi?id=135527
     5
     6        Reviewed by Tim Horton.
     7
     8        * Scripts/commit-log-editor:
     9        In the case of a git repository when there are no changed ChangeLog files, changed to pass
     10        the --delimiters option to prepare-ChangeLog, then process each entry in the output using
     11        commitMessageFromChangeLogEntry.
     12        (commitMessageFromChangeLogEntry): Factored out from createCommitMessage.
     13        (sortKey): Factored out from createCommitMessage.
     14        (createCommitMessage): Changed to use new sortKey and commitMessageFromChangeLogEntry
     15        subroutines.
     16
     17        * Scripts/prepare-ChangeLog:
     18        (main): Parse new --delimiters option.
     19        (generateNewChangeLogs): When --no-write and --delimiters are both specified, always print
     20        the label before each change log entry, and a "~" delimiter on a new line after each entry.
     21
    1222014-08-01  Bear Travis  <betravis@adobe.com>
    223
  • trunk/Tools/Scripts/commit-log-editor

    r167751 r171954  
    3939use webkitdirs;
    4040
     41sub commitMessageFromChangeLogEntry($);
     42sub sortKey($);
    4143sub createCommitMessage(@);
    4244sub loadTermReadKey();
     
    177179    }
    178180    if ($webkitGenerateCommitMessage ne "false") {
    179         open CHANGELOG_ENTRIES, "-|", "$FindBin::Bin/prepare-ChangeLog --git-index --no-write --no-style" or die "prepare-ChangeLog failed: $!.\n";
    180         while (<CHANGELOG_ENTRIES>) {
    181             print NEWLOG normalizeLineEndings($_, $endl);
    182         }
    183         close CHANGELOG_ENTRIES;
     181        my %changeLogSort;
     182        my %changeLogContents;
     183        open my $changeLogEntries, "-|", "$FindBin::Bin/prepare-ChangeLog --git-index --no-write --no-style --delimiters" or die "prepare-ChangeLog failed: $!.\n";
     184
     185        while (!eof($changeLogEntries)) {
     186            my $label = <$changeLogEntries>;
     187            chomp $label;
     188            $label =~ s/:$//;
     189            ($changeLogContents{$label}) = commitMessageFromChangeLogEntry($changeLogEntries);
     190            $changeLogSort{sortKey($label)} = $label;
     191        }
     192        close $changeLogEntries;
     193
     194        my $commonPrefix = removeLongestCommonPrefixEndingInNewline(%changeLogContents);
     195
     196        my @result;
     197        push @result, normalizeLineEndings($commonPrefix, $endl);
     198        for my $sortKey (sort keys %changeLogSort) {
     199            my $label = $changeLogSort{$sortKey};
     200            next if ($changeLogContents{$label} eq "\n");
     201            if (keys %changeLogSort > 1) {
     202                push @result, normalizeLineEndings("\n", $endl);
     203                push @result, normalizeLineEndings("$label: ", $endl);
     204            }
     205            push @result, normalizeLineEndings($changeLogContents{$label}, $endl);
     206        }
     207
     208        print NEWLOG join '', @result;
    184209    }
    185210} else {
     
    210235unlink "$log.edit";
    211236
     237sub commitMessageFromChangeLogEntry($)
     238{
     239    my ($changeLog) = @_;
     240
     241    my $commitMessage = "";
     242    my $blankLines = "";
     243    my $lineCount = 0;
     244    my $date = "";
     245    my $author = "";
     246    my $email = "";
     247    my $hasAuthorInfoToWrite = 0;
     248
     249    while (<$changeLog>) {
     250        if (/^\S/) {
     251            last if $commitMessage;
     252        }
     253        if (/\S/) {
     254            $commitMessage .= $blankLines if $commitMessage;
     255            $blankLines = "";
     256
     257            my $line = $_;
     258            # Remove indentation spaces
     259            $line =~ s/^ {8}//;
     260
     261            # Grab the author and the date line
     262            if ($line =~ m/^([0-9]{4}-[0-9]{2}-[0-9]{2})\s+(.*[^\s])\s+<(.*)>/ && $lineCount == 0) {
     263                $date = $1;
     264                $author = $2;
     265                $email = $3;
     266                $hasAuthorInfoToWrite = 1;
     267                next;
     268            }
     269
     270            if ($hasAuthorInfoToWrite) {
     271                my $isReviewedByLine = $line =~ m/^(?:Reviewed|Rubber[ \-]?stamped) by/;
     272                my $isModifiedFileLine = $line =~ m/^\* .*:/;
     273
     274                # Insert the authorship line if needed just above the "Reviewed by" line or the
     275                # first modified file (whichever comes first).
     276                if ($isReviewedByLine || $isModifiedFileLine) {
     277                    $hasAuthorInfoToWrite = 0;
     278                    my $authorshipString = patchAuthorshipString($author, $email, $date);
     279                    if ($authorshipString) {
     280                        $commitMessage .= "$authorshipString\n";
     281                        $commitMessage .= "\n" if $isModifiedFileLine;
     282                    }
     283                }
     284            }
     285
     286
     287            $lineCount++;
     288            $commitMessage .= $line;
     289        } else {
     290            $blankLines .= $_;
     291        }
     292    }
     293    return ($commitMessage, $hasAuthorInfoToWrite, $date, $author, $email);
     294}
     295
     296sub sortKey($)
     297{
     298    my ($label) = @_;
     299    my $sortKey = lc $label;
     300    if ($label eq "top level") {
     301        $sortKey = "";
     302    } elsif ($label eq "LayoutTests") {
     303        $sortKey = lc "~, LayoutTests last";
     304    }
     305    return $sortKey;
     306}
     307
    212308sub createCommitMessage(@)
    213309{
     
    219315    my %changeLogContents;
    220316    for my $changeLog (@changeLogs) {
    221         open CHANGELOG, $changeLog or die "Can't open $changeLog";
    222         my $contents = "";
    223         my $blankLines = "";
    224         my $lineCount = 0;
    225         my $date = "";
    226         my $author = "";
    227         my $email = "";
    228         my $hasAuthorInfoToWrite = 0;
    229         while (<CHANGELOG>) {
    230             if (/^\S/) {
    231                 last if $contents;
    232             }
    233             if (/\S/) {
    234                 $contents .= $blankLines if $contents;
    235                 $blankLines = "";
    236 
    237                 my $line = $_;
    238 
    239                 # Remove indentation spaces
    240                 $line =~ s/^ {8}//;
    241 
    242                 # Grab the author and the date line
    243                 if ($line =~ m/^([0-9]{4}-[0-9]{2}-[0-9]{2})\s+(.*[^\s])\s+<(.*)>/ && $lineCount == 0) {
    244                     $date = $1;
    245                     $author = $2;
    246                     $email = $3;
    247                     $hasAuthorInfoToWrite = 1;
    248                     next;
    249                 }
    250 
    251                 if ($hasAuthorInfoToWrite) {
    252                     my $isReviewedByLine = $line =~ m/^(?:Reviewed|Rubber[ \-]?stamped) by/;
    253                     my $isModifiedFileLine = $line =~ m/^\* .*:/;
    254 
    255                     # Insert the authorship line if needed just above the "Reviewed by" line or the
    256                     # first modified file (whichever comes first).
    257                     if ($isReviewedByLine || $isModifiedFileLine) {
    258                         $hasAuthorInfoToWrite = 0;
    259                         my $authorshipString = patchAuthorshipString($author, $email, $date);
    260                         if ($authorshipString) {
    261                             $contents .= "$authorshipString\n";
    262                             $contents .= "\n" if $isModifiedFileLine;
    263                         }
    264                     }
    265                 }
    266 
    267 
    268                 $lineCount++;
    269                 $contents .= $line;
    270             } else {
    271                 $blankLines .= $_;
    272             }
    273         }
     317        open my $changeLogFile, $changeLog or die "Can't open $changeLog";
     318
     319        my ($contents, $hasAuthorInfoToWrite, $date, $author, $email) = commitMessageFromChangeLogEntry($changeLogFile);
    274320        if ($hasAuthorInfoToWrite) {
    275321            # We didn't find anywhere to put the authorship info, so just put it at the end.
     
    279325        }
    280326
    281         close CHANGELOG;
     327        close $changeLogFile;
    282328
    283329        $changeLog = File::Spec->abs2rel(File::Spec->rel2abs($changeLog), $topLevel);
     
    286332        $label = "top level" unless length $label;
    287333
    288         my $sortKey = lc $label;
    289         if ($label eq "top level") {
    290             $sortKey = "";
    291         } elsif ($label eq "LayoutTests") {
    292             $sortKey = lc "~, LayoutTests last";
    293         }
    294 
    295         $changeLogSort{$sortKey} = $label;
     334        $changeLogSort{sortKey($label)} = $label;
    296335        $changeLogContents{$label} = $contents;
    297336    }
  • trunk/Tools/Scripts/prepare-ChangeLog

    r170521 r171954  
    8181sub generateFunctionLists($$$$$);
    8282sub generateFunctionListsByRanges($$$$);
    83 sub generateNewChangeLogs($$$$$$$$$$$);
     83sub generateNewChangeLogs($$$$$$$$$$$$);
    8484sub getLatestChangeLogs($);
    8585sub get_function_line_ranges($$);
     
    132132    my $openChangeLogs = 0;
    133133    my $writeChangeLogs = 1;
     134    my $delimiters = 0;
    134135    my $showHelp = 0;
    135136    my $spewDiff = $ENV{"PREPARE_CHANGELOG_DIFF"};
     
    138139        GetOptions("diff|d!" => \$spewDiff,
    139140                   "bug|b:i" => \$bugNumber,
     141                   "delimiters" => \$delimiters,
    140142                   "description:s" => \$bugDescription,
    141143                   "name:s" => \$name,
     
    165167        print STDERR "  --[no-]update   Update ChangeLogs from svn before adding entry (default: update)\n";
    166168        print STDERR "  --[no-]write    Write ChangeLogs to disk (otherwise send new entries to stdout) (default: write)\n";
     169        print STDERR "  --delimiters    When writing to stdout, label and print a \"~\" after each entry\n";
    167170        print STDERR "  --email=        Specify the email address to be used in the patch\n";
    168171        return 1;
     
    223226    }
    224227
    225     generateNewChangeLogs($prefixes, $filesInChangeLog, $addedRegressionTests, $functionLists, $bugURL, $bugDescription, $name, $emailAddress, $gitReviewer, $gitCommit, $writeChangeLogs);
     228    generateNewChangeLogs($prefixes, $filesInChangeLog, $addedRegressionTests, $functionLists, $bugURL, $bugDescription, $name, $emailAddress, $gitReviewer, $gitCommit, $writeChangeLogs, $delimiters);
    226229
    227230    if ($writeChangeLogs) {
     
    523526}
    524527
    525 sub generateNewChangeLogs($$$$$$$$$$$)
    526 {
    527     my ($prefixes, $filesInChangeLog, $addedRegressionTests, $functionLists, $bugURL, $bugDescription, $name, $emailAddress, $gitReviewer, $gitCommit, $writeChangeLogs) = @_;
     528sub generateNewChangeLogs($$$$$$$$$$$$)
     529{
     530    my ($prefixes, $filesInChangeLog, $addedRegressionTests, $functionLists, $bugURL, $bugDescription, $name, $emailAddress, $gitReviewer, $gitCommit, $writeChangeLogs, $delimiters) = @_;
    528531
    529532    # Generate new ChangeLog entries and (optionally) write out new ChangeLog files.
     
    548551        } else {
    549552            open CHANGE_LOG, ">-" or die "Could not write to STDOUT\n.";
    550             print substr($prefix, 0, length($prefix) - 1) . ":\n\n" unless (scalar @$prefixes) == 1;
     553            print substr($prefix, 0, length($prefix) - 1) . ":\n\n" unless (scalar @$prefixes) == 1 && !$delimiters;
    551554        }
    552555
     
    583586        } else {
    584587            print CHANGE_LOG "\n";
     588            print "~\n"  if $delimiters;
    585589        }
    586590
Note: See TracChangeset for help on using the changeset viewer.