-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-commit-log
executable file
·211 lines (170 loc) · 5.54 KB
/
git-commit-log
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/perl -w
#========================================================================
#
# git-commit-log
#
# DESCRIPTION
#
# When run in a git repository, generates a listing of git commit ids
# organized by release tags.
#
# AUTHOR
# Bryce W Harrington <[email protected]>
#
# COPYRIGHT
# Copyright (C) 2008 Bryce W. Harrington
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
#========================================================================
use strict;
use Pod::Usage;
use Getopt::Long qw(:config no_ignore_case bundling);
#------------------------------------------------------------------------
# Global variables
#------------------------------------------------------------------------
use vars qw($VERSION $NAME $YEAR);
$VERSION = '1.01';
$NAME = 'git-commit-log';
$YEAR = '2008';
our $opt_version = 0;
our $opt_help = 0;
our $opt_helplong = 0;
our $opt_man = 0;
our $opt_commits = 0;
our $opt_interval = 1;
our $opt_releases = 0;
our $opt_skip = 0;
our $opt_begin;
our $opt_end;
Getopt::Long::Configure ("bundling", "no_ignore_case");
GetOptions(
"version|V",
"help|h",
"helplong|H",
"man|M",
"begin|b=s",
"commits|c",
"releases|r",
"end|e=s",
"interval|i=n",
"skip|s",
) or pod2usage(-verbose => 0, -exitstatus => 0);
version_and_exit() if $opt_version;
pod2usage(-verbose => 0, -exitstatus => 0) if $opt_help;
pod2usage(-verbose => 1, -exitstatus => 0) if $opt_helplong;
pod2usage(-verbose => 0, -exitstatus => 1) if (! $ARGV[0]);
sub usage {
print "$0 [-c] <package>\n";
print "Must be run from inside a git repository\n";
print "Examples:\n";
print " $0 xf86-video-intel\n";
print " $0 nv\n";
print "\n";
print "Options:\n";
print " -b CMMT Start with given commit id\n";
print " -c Only display commit id's\n";
print " -e CMMT Stop with given commit id\n";
print " -i N Interval level\n";
print " -s Skip printing non-interval commits\n";
exit 0;
}
my $package = shift @ARGV || usage();
my @commits = (split(/\n/, `git tag -l "$package-*" `), 'master');
my $prev = pop @commits;
my $display = $prev;
my $select = '';
my $count = 0;
my $do_print = ($opt_begin || $opt_end)? undef : 1;
while (my $next = pop @commits) {
my ($commit, $date, $time, $comment);
foreach my $line (`git log $next..$prev | grep -A2 commit`) {
next if $line =~ /^Author/ or $line =~ /^--/;
if ($line =~ /commit\s*(\w+)/) {
$commit = $1;
} elsif ($line =~ /^Date:\s*\w{3} (\w{3} \d+) (\d\d:\d\d):\d\d (\d{4})/) {
my $short = sprintf("%.8s", $commit);
$date = $3 . ' ' . $1;
$time = $2;
$count++;
if (!$display && $count % $opt_interval) {
next if $opt_skip;
$select = ' ';
} elsif (!$display && $count % ($opt_interval*2)) {
$select = ' ';
} elsif (!$display && $count % ($opt_interval*4)) {
$select = ' ';
} elsif (!$display && $count % ($opt_interval*8)) {
$select = ' ';
} elsif (!$display) {
$select = ' ';
} else {
$select = '';
}
if ($opt_begin && $commit =~ /^$opt_begin/) {
$do_print = 0;
print "Ending printing\n";
} elsif ($opt_end && $commit =~ /^$opt_end/) {
$do_print = 1;
print "Starting printing\n";
}
if ($do_print) {
if ($opt_commits) {
if ($opt_releases) {
printf("%s %s\n", $short, $display || '');
} else {
printf("%s\n", $short);
}
} else {
printf("%-46s %-11s %s r%s %s\n", $select . $commit, $date, $time, $short, $display || '');
}
}
$display = undef;
}
}
$prev = $next;
$display = $prev;
$display =~ s/$package-//;
$count = 1;
}
__END__
=head1 SYNOPSIS
git-commit-log [-c] <tag-pattern>
Examples:
git-commit-log xf86-video-intel
git-commit-log -c nv
=head1 DESCRIPTION
This program displays a listing of commits and commit date from a git
tree, sorted by releases. The 'tag-pattern' allows distinguishing
tags that correspond to releases; only tags containing this text will
be used as valid tags.
=head1 OPTIONS
=over 8
=item B<-V>, B<--version>
Prints the version and exits
=item B<-h>, B<--help>
Prints a brief help message
=item B<-H>, B<--helplong>
Prints a long help message
=item B<--man>
Prints a manual page (detailed help)
=item B<-c>
Display a simple columnar list of commit id's. This is intended to be
suitable for feeding into other programs, like git-pkg.
=back
See B<pkg-page> -h for a summary of options.
=head1 PREREQUISITES
L<Pod::Usage>,
L<Getopt::Long>
=head1 BUGS
=head1 AUTHOR
Bryce W. Harrington E<lt>[email protected]<gt>
L<http://www.bryceharrington.org|http://www.bryceharrington.org>
=head1 COPYRIGHT
Copyright (C) 2008 Bryce W. Harrington.
All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut