Title: [271805] trunk/Tools
Revision
271805
Author
[email protected]
Date
2021-01-25 11:58:49 -0800 (Mon, 25 Jan 2021)

Log Message

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):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (271804 => 271805)


--- trunk/Tools/ChangeLog	2021-01-25 19:57:20 UTC (rev 271804)
+++ trunk/Tools/ChangeLog	2021-01-25 19:58:49 UTC (rev 271805)
@@ -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

Modified: trunk/Tools/Scripts/commit-log-editor (271804 => 271805)


--- trunk/Tools/Scripts/commit-log-editor	2021-01-25 19:57:20 UTC (rev 271804)
+++ trunk/Tools/Scripts/commit-log-editor	2021-01-25 19:58:49 UTC (rev 271805)
@@ -194,7 +194,7 @@
             my $label = <$changeLogEntries>;
             chomp $label;
             $label =~ s/:$//;
-            ($changeLogContents{$label}) = commitMessageFromChangeLogEntry($changeLogEntries);
+            $changeLogContents{sortKey($label)} = commitMessageFromChangeLogEntry($changeLogEntries);
             $changeLogSort{sortKey($label)} = $label;
         }
         close $changeLogEntries;
@@ -205,12 +205,12 @@
         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;
@@ -340,7 +340,7 @@
         $label = "top level" unless length $label;
 
         $changeLogSort{sortKey($label)} = $label;
-        $changeLogContents{$label} = $contents;
+        $changeLogContents{sortKey($label)} = $contents;
     }
 
     my $commonPrefix = removeLongestCommonPrefixEndingInNewline(%changeLogContents);
@@ -349,12 +349,12 @@
     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;
@@ -385,29 +385,31 @@
 {
     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($)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to