Merge branch 'master' into msvc-support-master
[profile/ivi/clutter.git] / build / gen-changelog.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Text::Wrap;
7 use Pod::Usage;
8 use Getopt::Long;
9 use POSIX qw( strftime );
10
11 $Text::Wrap::columns = 74;
12
13 # git commands
14 our $GIT_LOG       = 'git log --pretty=format:"%at|%an|<%ae>|%h|%s"';
15 our $GIT_DIFF_TREE = 'git diff-tree --name-only -r';
16
17 my $help;
18 my $result = GetOptions(
19     "h|help"    => \$help,
20 );
21
22 pod2usage(1) if $help;
23
24 our $revs = $ARGV[0] or undef;
25
26 my $log_cmd = $GIT_LOG;
27 $log_cmd .= ' ' . $revs if defined $revs;
28
29 open my $git_log, '-|', $log_cmd
30     or die("Unable to invoke git-log: $!\n");
31
32 while (<$git_log>) {
33     my $log_line = $_;
34
35     chomp($log_line);
36
37     my ($timestamp, $committer, $email, $commit_hash, $subject) =
38         split /\|/, $log_line, 5;
39
40     # use a shorter date line
41     my $date = strftime("%Y-%m-%d", localtime($timestamp));
42
43     print STDOUT $date, "  ", $committer, "  ", $email, "\n\n";
44
45     # list the file changes
46     if ($commit_hash) {
47         my $diff_cmd = $GIT_DIFF_TREE . " " . $commit_hash;
48
49         open my $git_diff, '-|', $diff_cmd
50             or die("Unable to invoke git-diff-tree: $!\n");
51
52         while (<$git_diff>) {
53             my $diff_line = $_;
54
55             chomp($diff_line);
56
57             next if $diff_line =~ /^$commit_hash/;
58             print STDOUT "\t* ", $diff_line, ":\n";
59         }
60
61         close($git_diff);
62     }
63     else {
64         print STDOUT "\t* *:\n";
65     }
66
67     print STDOUT "\n";
68
69     # no need to use the full body, the subject will do
70     if (defined $subject) {
71         $subject =~ s/\t//g;
72
73         print STDOUT wrap("\t", "\t", $subject), "\n";
74     }
75
76     print STDOUT "\n";
77 }
78
79 close($git_log);
80
81 0;
82 __END__
83
84 =pod
85
86 =head1 NAME
87
88 gen-changelog - Creates a ChangeLog from a git log
89
90 =head1 SYNOPSIS
91
92   gen-changelog <options>
93
94 =head1 DESCRIPTION
95
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
99 the users.
100
101 =head1 OPTIONS
102
103 =over 4
104
105 =item -h, --help
106
107 Prints a brief help message
108
109 =item E<lt>sinceE<gt>..E<lt>untilE<gt>
110
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.
115
116 =back
117
118 =head1 CAVEATS
119
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.
122
123 =head1 EXAMPLES
124
125 =over 4
126
127 =item Print the full log and redirect it to a file
128
129   gen-changelog > ChangeLog
130
131 =item Print the changelog of the local changes
132
133   gen-changelog origin..HEAD
134
135 =back
136
137 =head1 AUTHOR
138
139 Emmanuele Bassi  E<lt>ebassi (at) gnome.orgE<gt>
140
141 =head1 COPYRIGHT AND LICENSE
142
143 Copyright (C) 2009  Emmanuele Bassi
144
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.
147
148 =cut