You need Plack
[semece.git] / tools / gitlog2mkd.pl
blobfa2bc804e574196180047fbe51c92c56bcb7b453
1 #!/usr/bin/env perl
3 #Usage:
4 # git log --name-only --date=short | gilog2mkd.pl
6 use strict;
7 use warnings;
9 use constant DEBUG => 1;
10 use constant MAXCOMMIT => 10;
11 # Length of the nit hash in characters
12 use constant GITSHALEN => 40;
14 my $progn = $0; # Current program name
15 my $hdr = "#Noticias:\n";
16 my $git_cr = undef; # Git commit regex, if a line matches this regex then
17 # it's the start of a commit message
18 my $i = 0; # Commit counter
19 my $tmp = undef;
21 $tmp = sprintf('^commit ([[:digit:]abcdef]{%s})$', GITSHALEN);
22 $git_cr = qr/$tmp/o;
24 print $hdr;
26 $_ = <>; # Reads first line
28 # Iterates over commits
29 for ($i = 0; $i < MAXCOMMIT && !eof; $i++) {
30 my $commit = {
31 hash => undef, # Commit hash
32 authn => undef, # Author name
33 authm => undef, # Author mail
34 date => undef, # Commit date
35 msg => undef, # Commit message
36 file => undef # First changed file
39 if (not scalar(($commit->{hash}) = /$git_cr/)) {
40 die sprintf("This doesn't look like a commit message!, ".
41 "stopped at %s line %s; reading %s line %s.\n",
42 $progn, __LINE__, $ARGV, $.);
43 } elsif (not scalar(($commit->{authn}, $commit->{authm})
44 = <> =~ /^Author:\s+([^<]+)<([^>]*)>$/)) {
45 die sprintf("This doesn't look like an 'Author:' line!, ".
46 "stopped at %s line %s; reading %s line %s.\n",
47 $progn, __LINE__, $ARGV, $.);
48 } elsif (not scalar(($commit->{date}) = <> =~ /^Date:\s+(.+)$/)) {
49 die sprintf("This doesn't look like a 'Date:' line!, ".
50 "stopped at %s line %s; reading %s line %s.\n",
51 $progn, __LINE__, $ARGV, $.);
54 # Iterating over a single commit
55 while (<>) {
56 last if /$git_cr/;
57 if(/^\s+/){
58 $commit->{msg} .= $_;
59 }elsif(!$commit->{file} && /^\w/){
60 chomp;
61 $commit->{file} = $_;
65 if (not $commit->{msg}) {
66 die sprintf("Empty commit msg!, ".
67 "stopped at %s line %s; reading %s line %s.\n",
68 $progn, __LINE__, $ARGV, $.);
71 # Prunes empty lines at the start and end of $msg
72 $commit->{msg} =~ s/^\n+//s;
73 $commit->{msg} =~ s/\n+$//s;
75 printf(STDERR "\$commit = {\n") if DEBUG;
76 for (qw(hash
77 authn
78 authm
79 date
80 msg
81 file)) {
82 printf(STDERR "\t%s: '%s'\n",
83 $_, ($commit->{$_} ? $commit->{$_} : "")) if DEBUG;
85 printf(STDERR "};\n") if DEBUG;
87 print <<MARKDOWN;
88 * ###$commit->{date}:
90 $commit->{msg}
91 MARKDOWN
93 print <<MARKDOWN if $commit->{file};
94 [Ir.]($commit->{file})
95 MARKDOWN