forked from rcoder/ohloh_scm
/
svn_parser.rb
66 lines (61 loc) · 1.85 KB
/
svn_parser.rb
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
module OhlohScm::Parsers
class SvnParser < Parser
def self.scm
'svn'
end
def self.internal_parse(buffer, opts)
e = nil
state = :data
buffer.each_line do |l|
l.chomp!
next_state = state
if state == :data
if l =~ /^r(\d+) \| (.*) \| (\d+-\d+-\d+ .*) \(.*\) \| .*/
e = OhlohScm::Commit.new
e.token = $1.to_i
e.committer_name = $2
e.committer_date = Time.parse($3).utc
elsif l == "Changed paths:"
next_state = :diffs
elsif l.empty?
next_state = :comment
end
elsif state == :diffs
if l =~ /^ (\w) ([^\(\)]+)( \(from (.+):(\d+)\))?$/
e.diffs ||= []
e.diffs << OhlohScm::Diff.new(:action => $1, :path => $2, :from_path => $4, :from_revision => $5.to_i)
else
next_state = :comment
end
# The :log_embedded_within_comment state is special-case code to fix the Wireshark project, which
# includes fragments of svn logs within its comment blocks, which really confuses the parser.
# I am not sure whether only Wireshark does this, but I suspect it happens because there is a tool
# out there somethere to generate these embedded log comments.
elsif state == :log_embedded_within_comment
e.message << "\n"
e.message << l
next_state = :comment if l =~ /============================ .* log end =+/
elsif state == :comment
if l =~ /------------------------------------------------------------------------/
yield e if block_given?
e = nil
next_state = :data
elsif l =~ /============================ .* log start =+/
e.message << "\n"
e.message << l
next_state = :log_embedded_within_comment
else
if e.message
e.message << "\n"
e.message << l
else
e.message = l
end
end
end
state = next_state
end
yield e if block_given?
end
end
end