Skip to content

Commit e13163c

Browse files
committed
Add markdown mode for use with the sudo web site.
1 parent a3c1cbd commit e13163c

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

scripts/log2cl.pl

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# Parse options and build up "git log" command
3333
my @cmd = ( "git" );
3434
my %opts;
35-
getopts('b:R:', \%opts);
35+
getopts('b:mR:', \%opts);
3636
push(@cmd, "-b", $opts{"b"}) if exists $opts{"b"};
3737
push(@cmd, "--git-dir", $opts{"R"}) if exists $opts{"R"};
3838
push(@cmd, "log", "--log-size", "--name-only", "--date=short", "--format=$format", @ARGV);
@@ -45,6 +45,7 @@
4545
my $key_date = "";
4646
my $log_size = 0;
4747
my @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;
@@ -72,6 +73,9 @@
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";
@@ -106,6 +110,15 @@
106110
exit(0);
107111

108112
sub 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

Comments
 (0)