9 use POSIX qw( strftime );
11 $Text::Wrap::columns = 74;
14 our $GIT_LOG = 'git log --pretty=format:"%at|%an|<%ae>|%h|%s"';
15 our $GIT_DIFF_TREE = 'git diff-tree --name-only -r';
18 my $result = GetOptions(
22 pod2usage(1) if $help;
24 our $revs = $ARGV[0] or undef;
26 my $log_cmd = $GIT_LOG;
27 $log_cmd .= ' ' . $revs if defined $revs;
29 open my $git_log, '-|', $log_cmd
30 or die("Unable to invoke git-log: $!\n");
37 my ($timestamp, $committer, $email, $commit_hash, $subject) =
38 split /\|/, $log_line, 5;
40 # use a shorter date line
41 my $date = strftime("%Y-%m-%d", localtime($timestamp));
43 print STDOUT $date, " ", $committer, " ", $email, "\n\n";
45 # list the file changes
47 my $diff_cmd = $GIT_DIFF_TREE . " " . $commit_hash;
49 open my $git_diff, '-|', $diff_cmd
50 or die("Unable to invoke git-diff-tree: $!\n");
57 next if $diff_line =~ /^$commit_hash/;
58 print STDOUT "\t* ", $diff_line, ":\n";
64 print STDOUT "\t* *:\n";
69 # no need to use the full body, the subject will do
70 if (defined $subject) {
73 print STDOUT wrap("\t", "\t", $subject), "\n";
88 gen-changelog - Creates a ChangeLog from a git log
92 gen-changelog <options>
96 B<gen-changelog> is a small Perl script that reads the output of git log
97 and creates a file using the GNU ChangeLog format. It should be used when
98 creating a tarball of a project, to provide a full log of the changes to
107 Prints a brief help message
109 =item E<lt>sinceE<gt>..E<lt>untilE<gt>
111 Show only commits between the named two commits. When either E<lt>sinceE<gt>
112 or E<lt>untilE<gt> is omitted, it defaults to `HEAD`, i.e. the tip of the
113 current branch. For a more complete list of ways to spell E<lt>sinceE<gt>
114 and E<lt>untilE<gt>, see "SPECIFYING REVISIONS" section in git rev-parse.
120 B<gen-changelog> is very simple and should be tweaked to fit your use case.
121 It does fit the author's, but he'll gladly accept patches and requests.
127 =item Print the full log and redirect it to a file
129 gen-changelog > ChangeLog
131 =item Print the changelog of the local changes
133 gen-changelog origin..HEAD
139 Emmanuele Bassi E<lt>ebassi (at) gnome.orgE<gt>
141 =head1 COPYRIGHT AND LICENSE
143 Copyright (C) 2009 Emmanuele Bassi
145 This program is free software. It can be distributed and/or modified under
146 the terms of Perl itself. See L<perlartistic> for further details.