More conventional spacing.
[semece.git] / tools / gitlog2mkd.pl
blob39873abf2d75059d065cb8a2446b2eaa02aea6fc
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 MAXCOMMIT => 10;
10 # Length of the nit hash in characters
11 use constant GITSHALEN => 40;
13 my $progn = $0; # Current program name
14 my $hdr = "#Noticias:\n";
15 my $git_cr = undef; # Git commit regex, if a line matches this regex then
16 # it's the start of a commit message
17 my $i = 0; # Commit counter
18 my $tmp = undef;
20 $tmp = sprintf('^commit ([[:digit:]abcdef]{%s})$', GITSHALEN);
21 $git_cr = qr/$tmp/o;
23 print $hdr;
25 $_ = <>; # Reads first line
27 # Iterates over commits
28 for ($i = 0; $i < MAXCOMMIT && !eof; $i++) {
29 my $commit = {
30 hash => undef, # Commit hash
31 authn => undef, # Author name
32 authm => undef, # Author mail
33 date => undef, # Commit date
34 msg => undef, # Commit message
35 file => undef # First changed file
38 if (not scalar(($commit->{hash}) = /$git_cr/)) {
39 die sprintf("This doesn't look like a commit message!, ".
40 "stopped at %s line %s; reading %s line %s.\n",
41 $progn, __LINE__, $ARGV, $.);
42 } elsif (not scalar(($commit->{authn}, $commit->{authm})
43 = <> =~ /^Author:\s+([^<]+)<([^>]*)>$/)) {
44 die sprintf("This doesn't look like an 'Author:' line!, ".
45 "stopped at %s line %s; reading %s line %s.\n",
46 $progn, __LINE__, $ARGV, $.);
47 } elsif (not scalar(($commit->{date}) = <> =~ /^Date:\s+(.+)$/)) {
48 die sprintf("This doesn't look like a 'Date:' line!, ".
49 "stopped at %s line %s; reading %s line %s.\n",
50 $progn, __LINE__, $ARGV, $.);
53 # Iterating over a single commit
54 while (<>) {
55 last if /$git_cr/;
56 if(/^\s+/){
57 $commit->{msg} .= $_;
58 }elsif(!$commit->{file} && /^\w/){
59 chomp;
60 $commit->{file} = $_;
64 for (keys %$commit) {
65 printf(STDERR "\$%s: %s\n",
66 $_, ($commit->{$_} ? $commit->{$_} : ""));
69 if ($commit->{file}) {
70 printf(STDERR "\$file: $commit->{file}\n");
73 if (not $commit->{msg}) {
74 die sprintf("Empty commit msg!, ".
75 "stopped at %s line %s; reading %s line %s.\n",
76 $progn, __LINE__, $ARGV, $.);
79 print <<EOF;
80 * ###$commit->{date}:
82 $commit->{msg}
84 \t[Ir.]($commit->{file})
86 EOF