class OhlohScm::BazaarListener

Attributes

callback[RW]
commit[RW]
diff[RW]
text[W]

Public Class Methods

new(callback) click to toggle source
# File lib/ohloh_scm/parser/bzr_xml_parser.rb, line 13
def initialize(callback)
  @callback = callback
  @merge_commit = []
  @state = :none
  @authors = []
end

Public Instance Methods

cdata(data) click to toggle source

rubocop:disable Style/TrivialAccessors # Cannot use attr_writer; we need cdata not cdata=.

# File lib/ohloh_scm/parser/bzr_xml_parser.rb, line 80
def cdata(data)
  @cdata = data
end
tag_end(name) click to toggle source

rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity

# File lib/ohloh_scm/parser/bzr_xml_parser.rb, line 44
def tag_end(name)
  case name
  when 'log'
    @callback.call(@commit)
  when 'revisionid'
    @commit.token = @text
  when 'message'
    @commit.message = @cdata
  when 'committer'
    committer = BzrXmlParser.capture_name(@text)
    @commit.committer_name = committer[0]
    @commit.committer_email = committer[1]
  when 'author'
    author = BzrXmlParser.capture_name(@text)
    @authors << { author_name: author[0], author_email: author[1] }
  when 'timestamp'
    @commit.committer_date = Time.parse(@text)
  when 'file'
    @diffs.concat(parse_diff(@action, @text, @before_path)) if @state == :collect_files
    @before_path = nil
    @text = nil
  when 'added', 'modified', 'removed', 'renamed'
    @state = :none
  when 'affected-files'
    @commit.diffs = remove_dupes(@diffs)
  when 'merge'
    @commit = @merge_commit.pop
  when 'authors'
    @commit.author_name = @authors[0][:author_name]
    @commit.author_email = @authors[0][:author_email]
    @authors.clear
  end
end
tag_start(name, attrs) click to toggle source

rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength

# File lib/ohloh_scm/parser/bzr_xml_parser.rb, line 21
def tag_start(name, attrs)
  case name
  when 'log'
    @commit = OhlohScm::Commit.new
    @commit.diffs = []
  when 'affected-files'
    @diffs = []
  when 'added', 'modified', 'removed', 'renamed'
    @action = name
    @state = :collect_files
  when 'file'
    @before_path = attrs['oldpath']
  when 'merge'
    # This is a merge commit, save it and pop it after all branch commits
    @merge_commit.push(@commit)
  when 'authors'
    @state = :collect_authors
    @authors = []
  end
end
text(text) click to toggle source
# File lib/ohloh_scm/parser/bzr_xml_parser.rb, line 84
def text(text)
  @text = text
end

Private Instance Methods

parse_diff(action, path, before_path) click to toggle source

rubocop:disable Metrics/MethodLength Parse one single diff

# File lib/ohloh_scm/parser/bzr_xml_parser.rb, line 93
def parse_diff(action, path, before_path)
  diffs = []
  case action
    # A rename action requires two diffs: one to remove the old filename,
    # another to add the new filename.
    #
    # Note that is possible to be renamed to the empty string!
    # This happens when a subdirectory is moved to become the root.
  when 'renamed'
    diffs = [OhlohScm::Diff.new(action: 'D', path: before_path),
             OhlohScm::Diff.new(action: 'A', path: path || '')]
  when 'added'
    diffs = [OhlohScm::Diff.new(action: 'A', path: path)]
  when 'modified'
    diffs = [OhlohScm::Diff.new(action: 'M', path: path)]
  when 'removed'
    diffs = [OhlohScm::Diff.new(action: 'D', path: path)]
  end
  diffs.each do |d|
    d.path = strip_trailing_asterisk(d.path)
  end
  diffs
end
remove_dupes(diffs) click to toggle source
# File lib/ohloh_scm/parser/bzr_xml_parser.rb, line 122
def remove_dupes(diffs)
  BzrXmlParser.remove_dupes(diffs)
end
strip_trailing_asterisk(path) click to toggle source

rubocop:enable Metrics/MethodLength

# File lib/ohloh_scm/parser/bzr_xml_parser.rb, line 118
def strip_trailing_asterisk(path)
  path[-1..-1] == '*' ? path[0..-2] : path
end