1 eval '(exit $?0)' && eval 'exec perl -wS "$0" ${1+"$@"}'
2 & eval 'exec perl -wS "$0" $argv:q'
4 # Convert git log output to ChangeLog format.
6 my $VERSION = '2009-10-30 13:46'; # UTC
7 # The definition above must lie within the first 8 lines in order
8 # for the Emacs time-stamp write hook (at end) to update it.
9 # If you change this file with Emacs, please let the write hook
10 # do its job. Otherwise, update this string manually.
12 # Copyright (C) 2008-2011 Free Software Foundation, Inc.
14 # This program is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation, either version 3 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 # Written by Jim Meyering
32 use POSIX qw(strftime);
34 (my $ME = $0) =~ s|.*/||;
36 # use File::Coda; # http://meyering.net/code/Coda/
38 defined fileno STDOUT or return;
39 close STDOUT and return;
40 warn "$ME: failed to close standard output: $!\n";
47 my $STREAM = ($exit_code == 0 ? *STDOUT : *STDERR);
50 print $STREAM "Try `$ME --help' for more information.\n";
55 Usage: $ME [OPTIONS] [ARGS]
57 Convert git log output to ChangeLog format. If present, any ARGS
58 are passed to "git log". To avoid ARGS being parsed as options to
59 $ME, they may be preceded by '--'.
63 --since=DATE convert only the logs since DATE;
64 the default is to convert all log entries.
65 --format=FMT set format string for commit subject and body;
66 see 'man git-log' for the list of format metacharacters;
67 the default is '%s%n%b%n'
69 --help display this help and exit
70 --version output version information and exit
74 $ME --since=2008-01-01 > ChangeLog
75 $ME -- -n 5 foo > last-5-commits-to-branch-foo
82 # If the string $S is a well-behaved file name, simply return it.
83 # If it contains white space, quotes, etc., quote it, and return the new string.
87 if ($s =~ m![^\w+/.,-]!)
89 # Convert each single quote to '\''
90 $s =~ s/\'/\'\\\'\'/g;
91 # Then single quote the string.
99 return join (' ', map {shell_quote $_} @_);
103 my $since_date = '1970-01-01 UTC';
104 my $format_string = '%s%n%b%n';
107 help => sub { usage 0 },
108 version => sub { print "$ME version $VERSION\n"; exit },
109 'since=s' => \$since_date,
110 'format=s' => \$format_string,
113 my @cmd = (qw (git log --log-size), "--since=$since_date",
114 '--pretty=format:%ct %an <%ae>%n%n'.$format_string, @ARGV);
115 open PIPE, '-|', @cmd
116 or die ("$ME: failed to run `". quoted_cmd (@cmd) ."': $!\n"
117 . "(Is your Git too old? Version 1.5.1 or later is required.)\n");
119 my $prev_date_line = '';
122 defined (my $in = <PIPE>)
124 $in =~ /^log size (\d+)$/
125 or die "$ME:$.: Invalid line (expected log size):\n$in";
129 my $n_read = read PIPE, $log, $log_nbytes;
130 $n_read == $log_nbytes
131 or die "$ME:$.: unexpected EOF\n";
133 my @line = split "\n", $log;
134 my $author_line = shift @line;
136 or die "$ME:$.: unexpected EOF\n";
137 $author_line =~ /^(\d+) (.*>)$/
138 or die "$ME:$.: Invalid line "
139 . "(expected date/author/email):\n$author_line\n";
141 my $date_line = sprintf "%s $2\n", strftime ("%F", localtime ($1));
142 # If this line would be the same as the previous date/name/email
143 # line, then arrange not to print it.
144 if ($date_line ne $prev_date_line)
146 $prev_date_line eq ''
150 $prev_date_line = $date_line;
152 # Omit "Signed-off-by..." lines.
153 @line = grep !/^Signed-off-by: .*>$/, @line;
155 # If there were any lines
158 warn "$ME: warning: empty commit message:\n $date_line\n";
162 # Remove leading and trailing blank lines.
163 while ($line[0] =~ /^\s*$/) { shift @line; }
164 while ($line[$#line] =~ /^\s*$/) { pop @line; }
166 # Prefix each non-empty line with a TAB.
167 @line = map { length $_ ? "\t$_" : '' } @line;
169 print "\n", join ("\n", @line), "\n";
172 defined ($in = <PIPE>)
175 and die "$ME:$.: unexpected line:\n$in";
179 or die "$ME: error closing pipe from " . quoted_cmd (@cmd) . "\n";
180 # FIXME-someday: include $PROCESS_STATUS in the diagnostic
185 # indent-tabs-mode: nil
186 # eval: (add-hook 'write-file-hooks 'time-stamp)
187 # time-stamp-start: "my $VERSION = '"
188 # time-stamp-format: "%:y-%02m-%02d %02H:%02M"
189 # time-stamp-time-zone: "UTC"
190 # time-stamp-end: "'; # UTC"