#!/usr/bin/perl use strict; use warnings; use POSIX qw( strftime ); # options our $GIT_LOG = 'git-log --pretty=format:"%at:%an:<%ae>:%h:%s"'; our $GIT_DIFF_TREE = 'git-diff-tree --name-only -r'; our $revs = $ARGV[0] or undef; my $log_cmd = $GIT_LOG; $log_cmd .= ' ' . $revs if defined $revs; open my $git_log, '-|', $log_cmd or die("Unable to invoke git-log: $!\n"); while (<$git_log>) { my $log_line = $_; chomp($log_line); my ($timestamp, $committer, $email, $commit_hash, $subject) = split /:/, $log_line, 5; # use a shorter date line my $date = strftime("%Y-%m-%d", localtime($timestamp)); print $date, " ", $committer, " ", $email, "\n\n"; # list the file changes if ($commit_hash) { my $cmd = $GIT_DIFF_TREE . " " . $commit_hash; open my $git_diff, '-|', $cmd or die("Unable to invoke git-diff-tree: $!\n"); while (<$git_diff>) { my $diff_line = $_; chomp($diff_line); next if $diff_line =~ /^$commit_hash/; print "\t* ", $diff_line, ":\n"; } close($git_diff); } else { print "\t* *:\n"; } print "\n"; # no need to use the full body, the subject will do print "\t", $subject, "\n" if $subject; print "\n"; } close($git_log); 0; __END__ =pod =head1 NAME git-changelog - Creates a ChangeLog from a git log =head1 SYNOPSIS cd some-repository.git git-changelog > ChangeLog git-changelog .. =head1 DESCRIPTION B is a small Perl script that reads the output of git-log and creates a file using the ChangeLog format. It should be used when creating a tarball of a project, to provide a full log of the changes. =head1 OPTIONS =over 4 =item EsinceE..EuntilE Show only commits between the named two commits. When either EsinceE or EuntilE is omitted, it defaults to `HEAD`, i.e. the tip of the current branch. For a more complete list of ways to spell EsinceE and EuntilE, see "SPECIFYING REVISIONS" section in git-rev-parse. =back =head1 CAVEATS B is very simple and should be tweaked to fit your use case. It does fit the author's, but he'll gladly accept patches and requests. =head1 AUTHOR Emmanuele Bassi Eebassi (at) gnome.orgE =head1 COPYRIGHT AND LICENSE Copyright (C) 2007 Emmanuele Bassi This program is free software. It can be distributed and/or modified under the terms of Perl itself. See L for further details. =cut