@@ -40,10 +40,19 @@ my @BRANCHES = qw(master
40
40
# Might want to make this parameter user-settable.
41
41
my $timestamp_slop = 600;
42
42
43
+ my $details_after = 0;
43
44
my $post_date = 0;
45
+ my $master_only = 0;
46
+ my $oldest_first = 0;
44
47
my $since ;
45
- Getopt::Long::GetOptions(' post-date' => \$post_date ,
46
- ' since=s' => \$since ) || usage();
48
+ my @output_buffer ;
49
+ my $output_line = ' ' ;
50
+
51
+ Getopt::Long::GetOptions(' details-after' => \$details_after ,
52
+ ' master-only' => \$master_only ,
53
+ ' post-date' => \$post_date ,
54
+ ' oldest-first' => \$oldest_first ,
55
+ ' since=s' => \$since ) || usage();
47
56
usage() if @ARGV ;
48
57
49
58
my @git = qw( git log --format=fuller --date=iso) ;
@@ -179,17 +188,17 @@ while (1) {
179
188
last if !defined $best_branch ;
180
189
my $winner =
181
190
$all_commits_by_branch {$best_branch }-> [$position {$best_branch }];
182
- printf " Author: %s \n " , $winner -> {' author' };
183
- foreach my $c (@{$winner -> {' commits' }}) {
184
- printf " Branch: %s " , $c -> {' branch' };
185
- if (defined $c -> {' last_tag' }) {
186
- printf " Release: %s " , $c -> {' last_tag' };
187
- }
188
- printf " [%s ] %s \n " , substr ($c -> {' commit' }, 0, 9), $c -> {' date' };
191
+
192
+ # check for master-only
193
+ if (! $master_only || ($winner -> {' commits' }[0]-> {' branch' } eq ' master' &&
194
+ @{$winner -> {' commits' }} == 1)) {
195
+ output_details($winner ) if (! $details_after );
196
+ output_str(" %s " , $winner -> {' message' } . " \n " );
197
+ output_details($winner ) if ($details_after );
198
+ unshift (@output_buffer , $output_line ) if ($oldest_first );
199
+ $output_line = ' ' ;
189
200
}
190
- print " \n " ;
191
- print $winner -> {' message' };
192
- print " \n " ;
201
+
193
202
$winner -> {' done' } = 1;
194
203
for my $branch (@BRANCHES ) {
195
204
my $leader = $all_commits_by_branch {$branch }-> [$position {$branch }];
@@ -200,6 +209,8 @@ while (1) {
200
209
}
201
210
}
202
211
212
+ print @output_buffer if ($oldest_first );
213
+
203
214
sub push_commit {
204
215
my ($c ) = @_ ;
205
216
my $ht = hash_commit($c );
@@ -258,11 +269,38 @@ sub parse_datetime {
258
269
return $gm - $tzoffset ;
259
270
}
260
271
272
+ sub output_str {
273
+ ($oldest_first ) ? ($output_line .= sprintf (shift , @_ )) : printf (@_ );
274
+ }
275
+
276
+ sub output_details {
277
+ my $item = shift ;
278
+
279
+ if ($details_after ) {
280
+ $item -> {' author' } =~ m { ^(.*?)\s *<[^>]*>$} ;
281
+ # output only author name, not email address
282
+ output_str(" (%s )\n " , $1 );
283
+ } else {
284
+ output_str(" Author: %s \n " , $item -> {' author' });
285
+ }
286
+ foreach my $c (@{$item -> {' commits' }}) {
287
+ output_str(" Branch: %s " , $c -> {' branch' }) if (! $master_only );
288
+ if (defined $c -> {' last_tag' }) {
289
+ output_str(" Release: %s " , $c -> {' last_tag' });
290
+ }
291
+ output_str(" [%s ] %s \n " , substr ($c -> {' commit' }, 0, 9), $c -> {' date' });
292
+ }
293
+ output_str(" \n " );
294
+ }
295
+
261
296
sub usage {
262
297
print STDERR <<EOM ;
263
- Usage: git_changelog [--post-date/-p] [--since=SINCE]
264
- --post-date Show branches made after a commit occurred
265
- --since Print only commits dated since SINCE
298
+ Usage: git_changelog [--details-after/-d] [--master-only/-m] [--oldest-first/-o] [--post-date/-p] [--since=SINCE]
299
+ --details-after Show branch and author info after the commit description
300
+ --master-only Show commits made exclusively to the master branch
301
+ --oldest-first Show oldest commits first
302
+ --post-date Show branches made after a commit occurred
303
+ --since Print only commits dated since SINCE
266
304
EOM
267
305
exit 1;
268
306
}
0 commit comments