Commit 31e16802 authored by Robert Ricci's avatar Robert Ricci

New option to gitmail: summarize commits at the top

When the new 'summarythreshold' config option is set, gitmail will
produce a summary at the top of the mail. This consists of the
abbreviated commit hash and first line of the log message (truncated
to 72 characters to look nice in mail)
parent 94493625
...@@ -186,6 +186,12 @@ my $exclude_repo = get_config("excluderepo",undef); ...@@ -186,6 +186,12 @@ my $exclude_repo = get_config("excluderepo",undef);
# #
my @repo_keywords = get_config("keyword",undef); my @repo_keywords = get_config("keyword",undef);
#
# If defined, produce a summary at the top of the mail if there are at least
# this many commits
#
my $summary_threshold = get_config("summarythreshold",undef);
###################################################################### ######################################################################
# Constants # Constants
###################################################################### ######################################################################
...@@ -226,6 +232,7 @@ sub revparse($); ...@@ -226,6 +232,7 @@ sub revparse($);
sub changed_files(@); sub changed_files(@);
sub get_mail_addresses($@); sub get_mail_addresses($@);
sub get_merge_base($$); sub get_merge_base($$);
sub get_summary($);
sub uniq(@); sub uniq(@);
sub flatten_arrayref($); sub flatten_arrayref($);
sub commit_mail($\@$@); sub commit_mail($\@$@);
...@@ -714,6 +721,20 @@ sub commit_mail($\@$@) { ...@@ -714,6 +721,20 @@ sub commit_mail($\@$@) {
$actionstring .= "\n\n"; $actionstring .= "\n\n";
#
# Make a pretty summary of commits if there are enough of them
#
my $summary;
if (defined($summary_threshold) && scalar(@$commits) >= $summary_threshold
&& !$separate_mail) {
my @summaries;
foreach my $rev (@$commits) {
push @summaries, get_summary($rev);
}
$summary = join("\n",@summaries) .
"\n\n" . "="x72 . "\n\n";
}
my @fullbody; my @fullbody;
foreach my $rev (@$commits) { foreach my $rev (@$commits) {
# #
...@@ -775,7 +796,9 @@ sub commit_mail($\@$@) { ...@@ -775,7 +796,9 @@ sub commit_mail($\@$@) {
# #
if (!$separate_mail && @fullbody) { if (!$separate_mail && @fullbody) {
send_mail($subject, send_mail($subject,
$actionstring . join("\n" . "-"x72 . "\n\n", $actionstring .
$summary .
join("\n" . "-"x72 . "\n\n",
map { join "",@$_} @fullbody), map { join "",@$_} @fullbody),
short_refname($refname), short_refname($refname),
@mailaddrs); @mailaddrs);
...@@ -1053,6 +1076,20 @@ sub get_merge_base($$) ...@@ -1053,6 +1076,20 @@ sub get_merge_base($$)
return $mb return $mb
} }
#
# Returns a one-line summary of the given commit. Ensures that the resulting
# line is suitable for mail (ie. truncates it to 72 characters)
# (assumes the object passed in is a commit object; doesn't check!)
#
sub get_summary($) {
my ($rev) = @_;
# I would imagine there's a less hacky way to get the summary of one
# commit? 'git show' insists on printing the diff, though
my $oneliner = `$GIT log --oneline '$rev~'..'$rev'`;
chomp $oneliner;
return substr($oneliner,0,72);
}
# #
# Returns 1 if the given object (identified by hash) exists in the given # Returns 1 if the given object (identified by hash) exists in the given
# repository (identified by path); 0 if it does not . # repository (identified by path); 0 if it does not .
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment