-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitlog2gnucl
executable file
·131 lines (112 loc) · 3.03 KB
/
gitlog2gnucl
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/ruby
#To use this script, do: ./gitlog2gnucl > ChangeLog.generated
#ChangeLog.generated will be your generated ChangeLog file.
#Author: Dodji Seketeli
#This program is free software; you can redistribute
#it and/or modify it under the terms of
#the GNU General Public License as published by the
#Free Software Foundation; either version 2,
#or (at your option) any later version.
#This program is distributed in the hope that it will
#be useful, but WITHOUT ANY WARRANTY;
#without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#See the GNU General Public License for more details.
#You should have received a copy of the
#GNU General Public License along with Nemiver;
#see the file COPYING.
#If not, write to the Free Software Foundation,
#Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
class Entry
attr_accessor :date, :author, :summary, :body
def initialize(date, author, summary, body)
@date = filter_date(date)
@author = author
@summary = summary
@body = body
end
def filter_date(date)
if date =~ /(\d\d\d\d-\d\d-\d\d) (\d\d:\d\d:\d\d) (\+\d\d\d\d)/
return $1
end
return date
end
# Filters lines of body and summary
# Basically, don't keep lines with dates formated like:
# Lundi 2 Juillet 2007, Foo bar <[email protected]>
def keep_line(line)
if line =~ /svn path=(.*)?; revision=.*/
return false
end
#Filter out lines containing some date formated like: mardi 2 Mars 2006
if line =~ /\w+\s\d{1,2} .+? \d\d\d\d,/
return false
end
#Filter out lines containing data like
if line =~ /^\d\d\d\d-\d\d-\d\d [\w\s]+/
return false
end
return true
end
def to_s
s = "#{@date} #{@author}\n\n"
if !summary.empty?
if keep_line(summary)
s += "\t#{@summary}\n"
end
end
@body.each {|line|
if keep_line(line)
s += "\t#{line}\n"
end
}
return s
end
end
def process_git_log (log)
author = ""
date = ""
summary = ""
body = Array.new
msg_line_num = 0
entries = Array.new
log.each_line {|line|
if line =~ /^--START-ENTRY--/ #This is the start of an entry
author = ""
date = ""
summary = ""
body = Array.new
msg_line_num = 0
next
elsif line =~ /^--END-ENTRY--/
if !author.empty? and !date.empty?
entries.push(Entry.new(date, author, summary, body))
end
next
else #We are in the middle of an entry
if line =~ /^Author:(.*)?$/
author = $1
author = author.strip
elsif line =~ /^Date:(.*)?$/
date = $1
date = date.strip
msg_line_num = 0
elsif line =~ /^.+?$/
msg_line_num += 1
line = line.strip
if line.length == 0
next
end
if msg_line_num == 1 and line[0] != '*'
summary = line;
else
body.push(line)
end
end
end
}
return entries
end
gitlog = `git log --pretty=format:"--START-ENTRY--%ncommit %H%nAuthor:%an <%ae>%nDate:%ai%n%s%n%b%n--END-ENTRY--"`
entries = process_git_log(gitlog);
entries.each {|entry| print(entry.to_s,"\n") }