File: gitlog2mewchanges

package info (click to toggle)
mew-beta 7.0.50~6.6%2B0.20140902-1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 4,640 kB
  • ctags: 4,784
  • sloc: lisp: 36,518; ansic: 3,597; haskell: 577; sh: 440; makefile: 414; ruby: 310; perl: 58
file content (96 lines) | stat: -rwxr-xr-x 2,371 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/perl

=head1 NAME

gitlog2mewchanges - tiny tool to convert Git commit logs to Mew's 00changes

=head1 SYNOPSIS

git log | gitlog2mewchanges > 00changes

git log --no-merges --decorate | gitlog2mewchanges > 00changes

(Use --no-merges to ignore merge commits.
 Use --decorate to show version tags.)

=head1 SEE ALSO

Mew:
    <http://www.mew.org/>
    <https://github.com/kazu-yamamoto/Mew>

=head1 COPYRIGHT

Copyright (c) 2013 Tatsuya Kinoshita

Redistribution and use in source and binary forms, with or without
modification, are permitted without restriction, with NO WARRANTY.
You may regard this as a work that is placed in the public domain.

=cut

use strict;
use warnings;

my $PRODUCT = "Mew";
my $OWNER = "Kazu Yamamoto <kazu>";

my $author = ""; my $date = ""; my $comment = "";
my $version = "x.x"; my $pre_version = "";

sub print_entry {
    print "* ";

    $comment =~ s/\n([ \t]*\n)+/\n/g;
    $comment =~ s/\n+$//;
    $comment =~ s/\n/\n  /g;
    $comment =~ s/^\* //;
    print "$comment\n";

    my $name = $author;
    $name =~ s/<([^@]+)@[^>]+>/<$1>/;
    if ($name ne $OWNER) {
	print "\t$name\n";
    }

    $author = ""; $date = ""; $comment = "";
}

while (<>) {
    if (/^Author:[ \t]+([^\n]+)/) {
	$author = $1;
    } 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
	my $mm = $2;
	my $dd = $3;
	my $yyyy = $4;
	$mm =~ s/Jan/01/; $mm =~ s/Feb/02/; $mm =~ s/Mar/03/; $mm =~ s/Apr/04/;
	$mm =~ s/May/05/; $mm =~ s/Jun/06/; $mm =~ s/Jul/07/; $mm =~ s/Aug/08/;
	$mm =~ s/Sep/09/; $mm =~ s/Oct/10/; $mm =~ s/Nov/11/; $mm =~ s/Dec/12/;
	$dd =~ s/^(\d)$/0$1/;
	$date = "$yyyy/$mm/$dd";
    } elsif (/^Date:[ \t]+(\d+-\d+-\d+)/) {  # Assume git log --date=short or --date=iso
	$date = $1;
	$date  =~ s!-!/!g;
    } elsif (/^Date:[ \t]+(.+)$/) {
	$date = $1;
    } elsif (/^    (.*)$/) {
	$comment .= "$1\n";
    } elsif (/^commit /) {
	if ($author && $date) {
	    &print_entry;
	}
	if (/\((tag: v\d[^\)]+)\)$/) {
	    $version = $1;
	    $version =~ s/tag: v//g;
	}
    }
    if ($version ne $pre_version && $date ne "") {
	print "\n" if $pre_version ne "";
	print "$PRODUCT " if $PRODUCT ne "";
	print "$version ($date)\n\n";
	$pre_version = $version;
    }
}
if ($author && $date) {
    &print_entry;
}