Sha256: 19136b22383844cfebe46c2e56ce3096ce9a160828f284e0b2389b92a5f26278

Contents?: true

Size: 1.85 KB

Versions: 23

Compression:

Stored size: 1.85 KB

Contents

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

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
ohloh_scm-2.4.1 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.4.0 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.3.5 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.3.4 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.3.2 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.3.1 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.3.0 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.2.13 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.2.12 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.2.11 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.2.10 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.2.9 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.2.8 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.2.7 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.2.6 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.2.5 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.2.4 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.2.3 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.2.2 lib/ohloh_scm/parsers/svn_parser.rb
ohloh_scm-2.2.1 lib/ohloh_scm/parsers/svn_parser.rb