Skip to content

Commit

Permalink
The generated commit message have a directory label at the first line…
Browse files Browse the repository at this point in the history
… rather than the bug's title if ChangeLogs have different bug titles

https://bugs.webkit.org/show_bug.cgi?id=220822

Reviewed by Darin Adler.

commit-log-editor generates the default commit message by
collecting all ChangeLog entries and merging them with prepending
directory lables. If it finds out a common prefix for all entries,
it removes the prefix from entries and hoists the prefix as the
beginning of the commit message. This step removes duplicated
lines of the bug title, the bug URL, the reviewed-by line, and the
descriptions.

If such prefix is not found, i.e. ChangeLog entries has different
bug titles, it simply merges all entries with directory labels. As
the result, the generated commit message has the directory label
at the first line. This is not desirable. The first line of the
commit message should be the bug title.

This patch yanks the first line of the first entry as the common
prefix in the case.

* Scripts/commit-log-editor:
(createCommitMessage):
(removeLongestCommonPrefixEndingInNewline):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@271805 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
[email protected] authored and [email protected] committed Jan 25, 2021
1 parent 1a37db1 commit b408e42
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 24 deletions.
28 changes: 28 additions & 0 deletions Tools/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
2021-01-25 Fujii Hironori <[email protected]>

The generated commit message have a directory label at the first line rather than the bug's title if ChangeLogs have different bug titles
https://bugs.webkit.org/show_bug.cgi?id=220822

Reviewed by Darin Adler.

commit-log-editor generates the default commit message by
collecting all ChangeLog entries and merging them with prepending
directory lables. If it finds out a common prefix for all entries,
it removes the prefix from entries and hoists the prefix as the
beginning of the commit message. This step removes duplicated
lines of the bug title, the bug URL, the reviewed-by line, and the
descriptions.

If such prefix is not found, i.e. ChangeLog entries has different
bug titles, it simply merges all entries with directory labels. As
the result, the generated commit message has the directory label
at the first line. This is not desirable. The first line of the
commit message should be the bug title.

This patch yanks the first line of the first entry as the common
prefix in the case.

* Scripts/commit-log-editor:
(createCommitMessage):
(removeLongestCommonPrefixEndingInNewline):

2021-01-25 Lauro Moura <[email protected]>

[GLIB] Gardening API failures after r271794
Expand Down
50 changes: 26 additions & 24 deletions Tools/Scripts/commit-log-editor
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ if (isGit() && @changeLogs == 0) {
my $label = <$changeLogEntries>;
chomp $label;
$label =~ s/:$//;
($changeLogContents{$label}) = commitMessageFromChangeLogEntry($changeLogEntries);
$changeLogContents{sortKey($label)} = commitMessageFromChangeLogEntry($changeLogEntries);
$changeLogSort{sortKey($label)} = $label;
}
close $changeLogEntries;
Expand All @@ -205,12 +205,12 @@ if (isGit() && @changeLogs == 0) {
push @result, normalizeLineEndings($commonPrefix, $endl);
for my $sortKey (sort keys %changeLogSort) {
my $label = $changeLogSort{$sortKey};
next if ($changeLogContents{$label} eq "\n");
next unless $changeLogContents{$sortKey};
if (keys %changeLogSort > 1) {
push @result, normalizeLineEndings("\n", $endl);
push @result, normalizeLineEndings("$label: ", $endl);
}
push @result, normalizeLineEndings($changeLogContents{$label}, $endl);
push @result, normalizeLineEndings($changeLogContents{$sortKey}, $endl);
}

print NEWLOG join '', @result;
Expand Down Expand Up @@ -340,7 +340,7 @@ sub createCommitMessage(@)
$label = "top level" unless length $label;

$changeLogSort{sortKey($label)} = $label;
$changeLogContents{$label} = $contents;
$changeLogContents{sortKey($label)} = $contents;
}

my $commonPrefix = removeLongestCommonPrefixEndingInNewline(%changeLogContents);
Expand All @@ -349,12 +349,12 @@ sub createCommitMessage(@)
push @result, normalizeLineEndings($commonPrefix, $endl);
for my $sortKey (sort keys %changeLogSort) {
my $label = $changeLogSort{$sortKey};
next if ($changeLogContents{$label} eq "\n");
next unless $changeLogContents{$sortKey};
if (keys %changeLogSort > 1) {
push @result, normalizeLineEndings("\n", $endl);
push @result, normalizeLineEndings("$label:\n", $endl);
}
push @result, normalizeLineEndings($changeLogContents{$label}, $endl);
push @result, normalizeLineEndings($changeLogContents{$sortKey}, $endl);
}

return join '', @result;
Expand Down Expand Up @@ -385,29 +385,31 @@ sub removeLongestCommonPrefixEndingInNewline(\%)
{
my ($hashOfStrings) = @_;

my @strings = values %{$hashOfStrings};
return "" unless @strings > 1;
return "" unless keys %$hashOfStrings > 1;

my $prefix = shift @strings;
my $prefixLength = length $prefix;
foreach my $string (@strings) {
while ($prefixLength) {
last if substr($string, 0, $prefixLength) eq $prefix;
--$prefixLength;
$prefix = substr($prefix, 0, -1);
}
last unless $prefixLength;
my %strings;
foreach my $key (keys %$hashOfStrings) {
$strings{$key} = [ split(/^/, $hashOfStrings->{$key}) ];
}
my @prefix;
while (1) {
# Collect the first lines of all entries
my @heads = map { @$_ ? $_->[0] : "" } (values %strings);
my %hash_of_heads = map {$_, 1} @heads;
last if exists $hash_of_heads{""};
# Check the all first lines match
last unless keys %hash_of_heads == 1;
push @prefix, $heads[0];
# Remove the first lines
map { shift(@{$strings{$_}}) } keys %strings;
}

return "" unless $prefixLength;
map { $hashOfStrings->{$_} = join "", @{$strings{$_}} } keys %strings;

my $lastNewline = rindex($prefix, "\n");
return "" unless $lastNewline > 0;
# The first line should be the bug title. Use the first line of the first entry if no prefix found.
@prefix = $strings{(sort keys %strings)[0]}->[0] unless @prefix;

foreach my $key (keys %{$hashOfStrings}) {
$hashOfStrings->{$key} = substr($hashOfStrings->{$key}, $lastNewline);
}
return substr($prefix, 0, $lastNewline);
return join "", @prefix;
}

sub isCommitLogEditor($)
Expand Down

0 comments on commit b408e42

Please sign in to comment.