3232# Parse options and build up "git log" command
3333my @cmd = ( " git" );
3434my %opts ;
35- getopts(' b:R :' , \%opts );
35+ getopts(' b:mR :' , \%opts );
3636push (@cmd , " -b" , $opts {" b" }) if exists $opts {" b" };
3737push (@cmd , " --git-dir" , $opts {" R" }) if exists $opts {" R" };
3838push (@cmd , " log" , " --log-size" , " --name-only" , " --date=short" , " --format=$format " , @ARGV );
4545my $key_date = " " ;
4646my $log_size = 0;
4747my @lines ;
48+ my $hash_link = " https://git.sudo.ws/sudo/commit/?id=" ;
4849
4950# Wrap like "hg log --template=changelog"
5051$Text::Wrap::columns = 77;
7273
7374 # Check for continued entry (duplicate Date + Author)
7475 $_ = shift (@lines );
76+ # Strip author email address for markdown
77+ s /\s *<[^>]+>$// if exists $opts {' m' };
78+
7579 if ($_ ne $key_date ) {
7680 # New entry
7781 print " $_ \n\n " ;
106110exit (0);
107111
108112sub print_entry
113+ {
114+ if (exists $opts {' m' }) {
115+ print_entry_markdown(@_ );
116+ } else {
117+ print_entry_plain(@_ );
118+ }
119+ }
120+
121+ sub print_entry_plain
109122{
110123 my $hash = shift ;
111124 my $body = shift ;
@@ -115,3 +128,24 @@ sub print_entry
115128 print fill(" \t " , " \t " , $body ) . " \n " ;
116129 print " \t [$hash ]\n\n " ;
117130}
131+
132+ sub print_entry_markdown
133+ {
134+ my $hash = shift ;
135+ my $body = shift ;
136+ my $files = " : * " . join (" , " , @_ ) . " : " ;
137+
138+ # Obfuscate email addresses in body
139+ $body =~ s / ([^@ ]+@)[\w\. -]+\. (com|org|edu|ws|io)/ $1 .../ g ;
140+
141+ # Escape email chars in body
142+ $body =~ s / ([@<>])/ \\ $1 / g ;
143+
144+ # Expand GitHub issue and bugzilla links
145+ $body =~ s @ (GitHub issue #)(\d +)@ [$1$2 ](https://github.com/sudo-project/sudo/issues/$2 )@ ;
146+ $body =~ s @ (Bug #)(\d +)@ [$1$2 ](https://bugzilla.sudo.ws/show_bug.cgi?id=$2 )@ ;
147+
148+ print wrap(" " , " " , $files ) . " \n " ;
149+ print fill(" " , " " , $body ) . " \n " ;
150+ print " [[${hash} ]](${hash_link}${hash} )\n\n " ;
151+ }
0 commit comments