| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
gitlog2imchanges - tiny tool to convert Git commit logs to IM's 00changes |
| 6 |
|
| 7 |
=head1 SYNOPSIS |
| 8 |
|
| 9 |
git log | gitlog2imchanges > 00changes |
| 10 |
|
| 11 |
git log --no-merges --decorate | gitlog2imchanges > 00changes |
| 12 |
|
| 13 |
(Use --no-merges to ignore merge commits. |
| 14 |
Use --decorate to show version tags.) |
| 15 |
|
| 16 |
=head1 SEE ALSO |
| 17 |
|
| 18 |
IM: |
| 19 |
<http://tats.hauN.org/im/> |
| 20 |
<http://packages.qa.debian.org/i/im.html> |
| 21 |
|
| 22 |
=head1 COPYRIGHT |
| 23 |
|
| 24 |
Copyright (c) 2013 Tatsuya Kinoshita |
| 25 |
|
| 26 |
Redistribution and use in source and binary forms, with or without |
| 27 |
modification, are permitted without restriction, with NO WARRANTY. |
| 28 |
You may regard this as a work that is placed in the public domain. |
| 29 |
|
| 30 |
=cut |
| 31 |
|
| 32 |
use strict; |
| 33 |
use warnings; |
| 34 |
|
| 35 |
my $PRODUCT = "IM"; |
| 36 |
my $OWNER = "Tatsuya Kinoshita <tats>"; |
| 37 |
|
| 38 |
my $author = ""; my $date = ""; my $comment = ""; |
| 39 |
my $version = "xxx"; my $pre_version = ""; |
| 40 |
|
| 41 |
sub print_entry { |
| 42 |
print "* "; |
| 43 |
|
| 44 |
$comment =~ s/\n([ \t]*\n)+/\n/g; |
| 45 |
$comment =~ s/\n+$//; |
| 46 |
$comment =~ s/\n/\n /g; |
| 47 |
$comment =~ s/^\* //; |
| 48 |
print "$comment\n"; |
| 49 |
|
| 50 |
my $name = $author; |
| 51 |
$name =~ s/<([^@]+)@[^>]+>/<$1>/; |
| 52 |
if ($name ne $OWNER) { |
| 53 |
print "\t$name\n"; |
| 54 |
} |
| 55 |
|
| 56 |
$author = ""; $date = ""; $comment = ""; |
| 57 |
} |
| 58 |
|
| 59 |
while (<>) { |
| 60 |
if (/^Author:[ \t]+([^\n]+)/) { |
| 61 |
$author = $1; |
| 62 |
} elsif (/^Date:[ \t]+(Sun|Mon|Tue|Wed|Thu|Fri|Sat) +(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) +(\d+) +\d+:\d+:\d+ +(\d+)/) { # Assume git log --date=default or --date=local |
| 63 |
my $mm = $2; |
| 64 |
my $dd = $3; |
| 65 |
my $yyyy = $4; |
| 66 |
$mm =~ s/Jan/01/; $mm =~ s/Feb/02/; $mm =~ s/Mar/03/; $mm =~ s/Apr/04/; |
| 67 |
$mm =~ s/May/05/; $mm =~ s/Jun/06/; $mm =~ s/Jul/07/; $mm =~ s/Aug/08/; |
| 68 |
$mm =~ s/Sep/09/; $mm =~ s/Oct/10/; $mm =~ s/Nov/11/; $mm =~ s/Dec/12/; |
| 69 |
$dd =~ s/^(\d)$/0$1/; |
| 70 |
$date = "$yyyy/$mm/$dd"; |
| 71 |
} elsif (/^Date:[ \t]+(\d+-\d+-\d+)/) { # Assume git log --date=short or --date=iso |
| 72 |
$date = $1; |
| 73 |
$date =~ s!-!/!g; |
| 74 |
} elsif (/^Date:[ \t]+(.+)$/) { |
| 75 |
$date = $1; |
| 76 |
} elsif (/^ (.*)$/) { |
| 77 |
$comment .= "$1\n"; |
| 78 |
} elsif (/^commit /) { |
| 79 |
if ($author && $date) { |
| 80 |
&print_entry; |
| 81 |
} |
| 82 |
if (/\((tag: v\d[^\),]+)[^\)]*\)$/) { |
| 83 |
$version = $1; |
| 84 |
$version =~ s/tag: v//g; |
| 85 |
} |
| 86 |
} |
| 87 |
if ($version ne $pre_version && $date ne "") { |
| 88 |
print "\n" if $pre_version ne ""; |
| 89 |
print "$PRODUCT " if $PRODUCT ne ""; |
| 90 |
print "$version ($date)\n\n"; |
| 91 |
$pre_version = $version; |
| 92 |
} |
| 93 |
} |
| 94 |
if ($author && $date) { |
| 95 |
&print_entry; |
| 96 |
} |