class Capillary::LogParser

Attributes

branches[R]

Public Class Methods

new() click to toggle source
# File lib/capillary/log_parser.rb, line 24
def initialize
  @commit_count = 0
  @branches = []
  @seq_ids = {}
  @commit_positions = {}
end

Public Instance Methods

<<(commit) click to toggle source
# File lib/capillary/log_parser.rb, line 31
def <<(commit)
  commit = Capillary::Commit.parse(commit) if String === commit
  return if commit.nil?

  seq_id = @commit_count
  @commit_count += 1

  commit.parent_ids.each do |parent_id|
    place_commit(CommitNode.new(seq_id, commit, parent_id))
  end

  place_commit(CommitNode.new(seq_id, commit, nil)) if commit.parent_ids.empty?
end
to_json() click to toggle source
# File lib/capillary/log_parser.rb, line 45
def to_json
  branches_json = branches.collect do |b|
    "[" + b.collect { |c| "#{c.to_json}" }.join(",") + "]"
  end

  "[#{branches_json.join(', ')}]"
end

Private Instance Methods

place_commit(commit) click to toggle source
# File lib/capillary/log_parser.rb, line 54
def place_commit(commit)
  col = 0

  placed = branches.inject(false) do |was_placed, branch|
    if !branch.last.closed? && branch.last.parent_id == commit.id
      save_commit_pos(col, commit)
      was_placed = true
    end

    col += 1
    was_placed
  end

  unless placed
    save_commit_pos(col, commit)
  end
end
save_commit_pos(col, commit) click to toggle source
# File lib/capillary/log_parser.rb, line 72
def save_commit_pos(col, commit)
  branch = branches[col]
  prev_commit = branch && branch.last
  pos = prev_commit && @commit_positions[prev_commit.parent_id]

  if !pos
    branches << [] if branches.length <= col
    @commit_positions[commit.id] = [col, branches[col].length]
  end

  branches[col] << commit
end