Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 993ce4e

Browse files
committed
Add options to git_changelog for use in major release note creation:
--details-after --master-only --oldest-first
1 parent 537b266 commit 993ce4e

File tree

1 file changed

+53
-15
lines changed

1 file changed

+53
-15
lines changed

src/tools/git_changelog

+53-15
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,19 @@ my @BRANCHES = qw(master
4040
# Might want to make this parameter user-settable.
4141
my $timestamp_slop = 600;
4242

43+
my $details_after = 0;
4344
my $post_date = 0;
45+
my $master_only = 0;
46+
my $oldest_first = 0;
4447
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();
4756
usage() if @ARGV;
4857

4958
my @git = qw(git log --format=fuller --date=iso);
@@ -179,17 +188,17 @@ while (1) {
179188
last if !defined $best_branch;
180189
my $winner =
181190
$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 = '';
189200
}
190-
print "\n";
191-
print $winner->{'message'};
192-
print "\n";
201+
193202
$winner->{'done'} = 1;
194203
for my $branch (@BRANCHES) {
195204
my $leader = $all_commits_by_branch{$branch}->[$position{$branch}];
@@ -200,6 +209,8 @@ while (1) {
200209
}
201210
}
202211

212+
print @output_buffer if ($oldest_first);
213+
203214
sub push_commit {
204215
my ($c) = @_;
205216
my $ht = hash_commit($c);
@@ -258,11 +269,38 @@ sub parse_datetime {
258269
return $gm - $tzoffset;
259270
}
260271

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+
261296
sub usage {
262297
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
266304
EOM
267305
exit 1;
268306
}

0 commit comments

Comments
 (0)