diff options
author | Ben Murdoch <benm@google.com> | 2009-08-11 17:01:47 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2009-08-11 18:21:02 +0100 |
commit | 0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5 (patch) | |
tree | 2943df35f62d885c89d01063cc528dd73b480fea /WebKitTools/Scripts/commit-log-editor | |
parent | 7e7a70bfa49a1122b2597a1e6367d89eb4035eca (diff) | |
download | external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.zip external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.tar.gz external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.tar.bz2 |
Merge in WebKit r47029.
Diffstat (limited to 'WebKitTools/Scripts/commit-log-editor')
-rwxr-xr-x | WebKitTools/Scripts/commit-log-editor | 156 |
1 files changed, 121 insertions, 35 deletions
diff --git a/WebKitTools/Scripts/commit-log-editor b/WebKitTools/Scripts/commit-log-editor index 939b28c..e2fc92d 100755 --- a/WebKitTools/Scripts/commit-log-editor +++ b/WebKitTools/Scripts/commit-log-editor @@ -1,6 +1,7 @@ #!/usr/bin/perl -w -# Copyright (C) 2006, 2007 Apple Inc. All rights reserved. +# Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. +# Copyright (C) 2009 Torch Mobile Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -33,10 +34,28 @@ use File::Basename; use File::Spec; use FindBin; use lib $FindBin::Bin; +use Term::ReadKey; use VCSUtils; use webkitdirs; +sub normalizeLineEndings($$); + +sub usage +{ + print "Usage: [--help] [--regenerate-log] <log file>\n"; + exit 1; +} + +my $help = checkForArgumentAndRemoveFromARGV("--help"); +if ($help) { + usage(); +} + +my $regenerateLog = checkForArgumentAndRemoveFromARGV("--regenerate-log"); my $log = $ARGV[0]; +if (!$log) { + usage(); +} my $baseDir = baseProductDir(); @@ -74,18 +93,37 @@ while (<LOG>) { } } - $logContents .= $_; + if (!isGit() || /^#/) { # + $logContents .= $_; + } else { + # $_ contains the current git log message + # (without the log comment info). We don't need it. + } $existingLog = isGit() && !(/^#/ || /^\s*$/) unless $existingLog; - push @changeLogs, makeFilePathRelative($1) if $inChangesToBeCommitted && (/^M....(.*ChangeLog)$/ || /^#\tmodified: (.*ChangeLog)/) && !/-ChangeLog/; + push @changeLogs, makeFilePathRelative($1) if $inChangesToBeCommitted && (/^M....(.*ChangeLog)\r?\n?$/ || /^#\tmodified: (.*ChangeLog)/) && !/-ChangeLog/; } close LOG; +# We want to match the line endings of the existing log file in case they're +# different from perl's line endings. +my $endl = "\n"; +$endl = $1 if $logContents =~ /(\r?\n)/; + +my $keepExistingLog = 1; +if ($regenerateLog && $existingLog && scalar(@changeLogs) > 0) { + print "Existing log message detected, Use 'r' to regenerate log message from ChangeLogs, or any other key to keep the existing message.\n"; + ReadMode('cbreak'); + my $key = ReadKey(0); + ReadMode('normal'); + $keepExistingLog = 0 if ($key eq "r"); +} + # Don't change anything if there's already a log message # (as can happen with git-commit --amend) -exec $editor, @ARGV if $existingLog; +exec $editor, @ARGV if $existingLog && $keepExistingLog; -my $topLevel = topLevelSourceDirectory(); +my $topLevel = determineVCSRoot(); my %changeLogSort; my %changeLogContents; @@ -93,18 +131,67 @@ for my $changeLog (@changeLogs) { open CHANGELOG, $changeLog or die "Can't open $changeLog"; my $contents = ""; my $blankLines = ""; + my $reviewedByLine = ""; + 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; + my $previousLineWasBlank = 1 unless $blankLines eq ""; + my $line = $_; + my $currentLineBlankLines = $blankLines; $blankLines = ""; - $contents .= $_; + + # Remove indentation spaces + $line =~ s/^ {8}//; + + # Save the reviewed by line + if ($line =~ m/^Reviewed by .*/) { + $reviewedByLine = $line; + 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; + } + + $contents .= $currentLineBlankLines if $contents; + + # Attempt to insert the "patch by" line, after the first blank line. + if ($previousLineWasBlank && $hasAuthorInfoToWrite && $lineCount > 0) { + my $authorAndCommitterAreSamePerson = $ENV{EMAIL_ADDRESS} && $email eq $ENV{EMAIL_ADDRESS}; + if (!$authorAndCommitterAreSamePerson) { + $contents .= "Patch by $author <$email> on $date\n"; + $hasAuthorInfoToWrite = 0; + } + } + + # Attempt to insert the "reviewed by" line, after the first blank line. + if ($previousLineWasBlank && $reviewedByLine && $lineCount > 0) { + $contents .= $reviewedByLine . "\n"; + $reviewedByLine = ""; + } + + + $lineCount++; + $contents .= $line; } else { $blankLines .= $_; } } + if ($reviewedByLine) { + $contents .= "\n".$reviewedByLine; + } close CHANGELOG; $changeLog = File::Spec->abs2rel(File::Spec->rel2abs($changeLog), $topLevel); @@ -131,14 +218,30 @@ for my $changeLog (@changeLogs) { my $first = 1; open NEWLOG, ">$log.edit" or die; -for my $sortKey (sort keys %changeLogSort) { - my $label = $changeLogSort{$sortKey}; - if (keys %changeLogSort > 1) { - print NEWLOG "\n" if !$first; - $first = 0; - print NEWLOG "$label:\n\n"; +if (isGit() && scalar keys %changeLogSort == 0) { + # populate git commit message with WebKit-format ChangeLog entries unless explicitly disabled + my $branch = gitBranch(); + chomp(my $webkitGenerateCommitMessage = `git config --bool branch.$branch.webkitGenerateCommitMessage`); + if ($webkitGenerateCommitMessage eq "") { + chomp($webkitGenerateCommitMessage = `git config --bool core.webkitGenerateCommitMessage`); + } + if ($webkitGenerateCommitMessage ne "false") { + open CHANGELOG_ENTRIES, "-|", "prepare-ChangeLog --git-index --no-write" or die "prepare-ChangeLog failed: $!.\n"; + while (<CHANGELOG_ENTRIES>) { + print NEWLOG normalizeLineEndings($_, $endl); + } + close CHANGELOG_ENTRIES; + } +} else { + for my $sortKey (sort keys %changeLogSort) { + my $label = $changeLogSort{$sortKey}; + if (keys %changeLogSort > 1) { + print NEWLOG normalizeLineEndings("\n", $endl) if !$first; + $first = 0; + print NEWLOG normalizeLineEndings("$label: ", $endl); + } + print NEWLOG normalizeLineEndings($changeLogContents{$label}, $endl); } - print NEWLOG $changeLogContents{$label}; } print NEWLOG $logContents; close NEWLOG; @@ -164,26 +267,9 @@ if ($foundComment) { unlink "$log.edit"; -sub topLevelSourceDirectory +sub normalizeLineEndings($$) { - if (isGit()) { - chomp(my $gitDir = `git rev-parse --git-dir`); - return dirname($gitDir); - } elsif (isSVN()) { - open(INFO, "-|", qw(svn info)) or die; - my ($root, $url); - while (my $line = <INFO>) { - if ($line =~ /^Repository Root: (.*)$/) { - $root = $1; - } elsif ($line =~ /^URL: (.*)$/) { - $url = $1; - } - } - close(INFO); - - my $path = $url; - $path =~ s/^\Q$root\E//; - $path =~ s/^\/?(branches\/[^\/]*|trunk)\/?//; - return File::Spec->rel2abs(File::Spec->catdir(map { ".." } File::Spec->splitdir($path))); - } + my ($string, $endl) = @_; + $string =~ s/\r?\n/$endl/g; + return $string; } |