Add a --brief option to git_changelog.
authorTom Lane
Tue, 26 Apr 2016 22:52:17 +0000 (18:52 -0400)
committerTom Lane
Tue, 26 Apr 2016 22:52:41 +0000 (18:52 -0400)
In commit c0b050192, Andres introduced the idea of including one-line
commit references in our major release notes.  Teach git_changelog to
emit a (lightly adapted) version of that format, so that we don't
have to laboriously add it to the notes after the fact.  The default
output isn't changed, since I anticipate still using that for minor
release notes.

src/tools/git_changelog

index d9f0976a334aa985e6ee9380b3f83564a932acd4..031772158e1682360f9252b026df1eee20057a5e 100755 (executable)
@@ -5,7 +5,9 @@
 #
 # Display all commits on active branches, merging together commits from
 # different branches that occur close together in time and with identical
-# log messages.  Commits are annotated with branch and release info thus:
+# log messages.
+#
+# By default, commits are annotated with branch and release info thus:
 # Branch: REL8_3_STABLE Release: REL8_3_2 [92c3a8004] 2008-03-29 00:15:37 +0000
 # This shows that the commit on REL8_3_STABLE was released in 8.3.2.
 # Commits on master will usually instead have notes like
 # If no Release: marker appears, the commit hasn't yet made it into any
 # release.
 #
+# The --brief option shortens that to a format like:
+# YYYY-MM-DD [hash] abbreviated commit subject line
+# Since the branch isn't shown, this is mainly useful in conjunction
+# with --master-only.
+#
 # Most of the time, matchable commits occur in the same order on all branches,
 # and we print them out in that order.  However, if commit A occurs before
 # commit B on branch X and commit B occurs before commit A on branch Y, then
 # we sort a merged commit according to its timestamp on the newest branch
 # it appears in.
 #
-# Typical usage to generate major release notes:
-#   git_changelog --since '2010-07-09 00:00:00' --master-only --oldest-first --details-after
+# The default output of this script is meant for generating minor release
+# notes, where we need to know which branches a merged commit affects.
 #
-# To find the branch start date, use:
-#   git show $(git merge-base REL9_0_STABLE master)
+# To generate major release notes, intended usage is
+#   git_changelog --master-only --brief --oldest-first --since='start-date'
+# To find the appropriate start date, use:
+#   git show $(git merge-base REL9_5_STABLE master)
+# where the branch to mention is the previously forked-off branch.  This
+# shows the last commit before that branch was made.
 
 
 use strict;
@@ -47,6 +58,7 @@ my @BRANCHES = qw(master
 # Might want to make this parameter user-settable.
 my $timestamp_slop = 24 * 60 * 60;
 
+my $brief         = 0;
 my $details_after = 0;
 my $post_date     = 0;
 my $master_only   = 0;
@@ -56,6 +68,7 @@ my @output_buffer;
 my $output_line = '';
 
 Getopt::Long::GetOptions(
+   'brief'         => \$brief,
    'details-after' => \$details_after,
    'master-only'   => \$master_only,
    'post-date'     => \$post_date,
@@ -336,12 +349,25 @@ sub output_details
    }
    foreach my $c (@{ $item->{'commits'} })
    {
-       output_str("Branch: %s ", $c->{'branch'}) if (!$master_only);
-       if (defined $c->{'last_tag'})
+       if ($brief)
+       {
+           $item->{'message'} =~ m/^\s*(.*)/;
+
+           output_str("%s [%s] %s\n",
+                  substr($c->{'date'}, 0, 10),
+                  substr($c->{'commit'}, 0, 9),
+                  substr($1, 0, 56));
+       }
+       else
        {
-           output_str("Release: %s ", $c->{'last_tag'});
+           output_str("Branch: %s ", $c->{'branch'})
+               if (!$master_only);
+           output_str("Release: %s ", $c->{'last_tag'})
+               if (defined $c->{'last_tag'});
+           output_str("[%s] %s\n",
+                  substr($c->{'commit'}, 0, 9),
+                  $c->{'date'});
        }
-       output_str("[%s] %s\n", substr($c->{'commit'}, 0, 9), $c->{'date'});
    }
    output_str("\n");
 }
@@ -349,7 +375,8 @@ sub output_details
 sub usage
 {
    print STDERR <
-Usage: git_changelog [--details-after/-d] [--master-only/-m] [--oldest-first/-o] [--post-date/-p] [--since=SINCE]
+Usage: git_changelog [--brief/-b] [--details-after/-d] [--master-only/-m] [--oldest-first/-o] [--post-date/-p] [--since=SINCE]
+    --brief         Shorten commit descriptions, omitting branch identification
     --details-after Show branch and author info after the commit description
     --master-only   Show commits made exclusively to the master branch
     --oldest-first  Show oldest commits first