| 1 | #!/usr/bin/ruby |
|---|
| 2 | |
|---|
| 3 | #To use this script, do: ./gitlog2gnucl > ChangeLog.generated |
|---|
| 4 | #ChangeLog.generated will be your generated ChangeLog file. |
|---|
| 5 | |
|---|
| 6 | #Author: Dodji Seketeli |
|---|
| 7 | |
|---|
| 8 | #This program is free software; you can redistribute |
|---|
| 9 | #it and/or modify it under the terms of |
|---|
| 10 | #the GNU General Public License as published by the |
|---|
| 11 | #Free Software Foundation; either version 2, |
|---|
| 12 | #or (at your option) any later version. |
|---|
| 13 | |
|---|
| 14 | #This program is distributed in the hope that it will |
|---|
| 15 | #be useful, but WITHOUT ANY WARRANTY; |
|---|
| 16 | #without even the implied warranty of |
|---|
| 17 | #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 18 | #See the GNU General Public License for more details. |
|---|
| 19 | |
|---|
| 20 | #You should have received a copy of the |
|---|
| 21 | #GNU General Public License along with Nemiver; |
|---|
| 22 | #see the file COPYING. |
|---|
| 23 | #If not, write to the Free Software Foundation, |
|---|
| 24 | #Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | class Entry |
|---|
| 28 | attr_accessor :date, :author, :summary, :body |
|---|
| 29 | |
|---|
| 30 | def initialize(date, author, summary, body) |
|---|
| 31 | @date = filter_date(date) |
|---|
| 32 | @author = author |
|---|
| 33 | @summary = summary |
|---|
| 34 | @body = body |
|---|
| 35 | |
|---|
| 36 | end |
|---|
| 37 | |
|---|
| 38 | def filter_date(date) |
|---|
| 39 | if date =~ /(\d\d\d\d-\d\d-\d\d) (\d\d:\d\d:\d\d) (\+\d\d\d\d)/ |
|---|
| 40 | return $1 |
|---|
| 41 | end |
|---|
| 42 | return date |
|---|
| 43 | end |
|---|
| 44 | |
|---|
| 45 | # Filters lines of body and summary |
|---|
| 46 | # Basically, don't keep lines with dates formated like: |
|---|
| 47 | # Lundi 2 Juillet 2007, Foo bar <foo@bar.org> |
|---|
| 48 | def keep_line(line) |
|---|
| 49 | if line =~ /svn path=(.*)?; revision=.*/ |
|---|
| 50 | return false |
|---|
| 51 | end |
|---|
| 52 | |
|---|
| 53 | #Filter out lines containing some date formated like: mardi 2 Mars 2006 |
|---|
| 54 | if line =~ /\w+\s\d{1,2} .+? \d\d\d\d,/ |
|---|
| 55 | return false |
|---|
| 56 | end |
|---|
| 57 | #Filter out lines containing data like |
|---|
| 58 | if line =~ /^\d\d\d\d-\d\d-\d\d [\w\s]+/ |
|---|
| 59 | return false |
|---|
| 60 | end |
|---|
| 61 | return true |
|---|
| 62 | end |
|---|
| 63 | |
|---|
| 64 | def to_s |
|---|
| 65 | s = "#{@date} #{@author}\n\n" |
|---|
| 66 | if !summary.empty? |
|---|
| 67 | if keep_line(summary) |
|---|
| 68 | s += "\t#{@summary}\n" |
|---|
| 69 | end |
|---|
| 70 | end |
|---|
| 71 | @body.each {|line| |
|---|
| 72 | if keep_line(line) |
|---|
| 73 | s += "\t#{line}\n" |
|---|
| 74 | end |
|---|
| 75 | } |
|---|
| 76 | return s |
|---|
| 77 | end |
|---|
| 78 | end |
|---|
| 79 | |
|---|
| 80 | def process_git_log (log) |
|---|
| 81 | |
|---|
| 82 | author = "" |
|---|
| 83 | date = "" |
|---|
| 84 | summary = "" |
|---|
| 85 | body = Array.new |
|---|
| 86 | msg_line_num = 0 |
|---|
| 87 | |
|---|
| 88 | entries = Array.new |
|---|
| 89 | |
|---|
| 90 | log.each_line {|line| |
|---|
| 91 | if line =~ /^--START-ENTRY--/ #This is the start of an entry |
|---|
| 92 | author = "" |
|---|
| 93 | date = "" |
|---|
| 94 | summary = "" |
|---|
| 95 | body = Array.new |
|---|
| 96 | msg_line_num = 0 |
|---|
| 97 | next |
|---|
| 98 | elsif line =~ /^--END-ENTRY--/ |
|---|
| 99 | if !author.empty? and !date.empty? |
|---|
| 100 | entries.push(Entry.new(date, author, summary, body)) |
|---|
| 101 | end |
|---|
| 102 | next |
|---|
| 103 | else #We are in the middle of an entry |
|---|
| 104 | if line =~ /^Author:(.*)?$/ |
|---|
| 105 | author = $1 |
|---|
| 106 | author = author.strip |
|---|
| 107 | elsif line =~ /^Date:(.*)?$/ |
|---|
| 108 | date = $1 |
|---|
| 109 | date = date.strip |
|---|
| 110 | msg_line_num = 0 |
|---|
| 111 | elsif line =~ /^.+?$/ |
|---|
| 112 | msg_line_num += 1 |
|---|
| 113 | line = line.strip |
|---|
| 114 | if line.length == 0 |
|---|
| 115 | next |
|---|
| 116 | end |
|---|
| 117 | if msg_line_num == 1 and line[0] != '*' |
|---|
| 118 | summary = line; |
|---|
| 119 | else |
|---|
| 120 | body.push(line) |
|---|
| 121 | end |
|---|
| 122 | end |
|---|
| 123 | end |
|---|
| 124 | } |
|---|
| 125 | return entries |
|---|
| 126 | end |
|---|
| 127 | |
|---|
| 128 | gitlog = `git log --pretty=format:"--START-ENTRY--%ncommit %H%nAuthor:%an <%ae>%nDate:%ai%n%s%n%b%n--END-ENTRY--"` |
|---|
| 129 | entries = process_git_log(gitlog); |
|---|
| 130 | entries.each {|entry| print(entry.to_s,"\n") } |
|---|