class Git::BlameColor::Application

Public Instance Methods

run(argv) click to toggle source
# File lib/git-blame-color/application.rb, line 20
def run(argv)
  Rainbow.enabled = true
  die 1, 'git blame-color does not support the --incremental option' if ARGV.incremental?
  stdout, stderr, status = Open3.capture3('git', 'blame', '--line-porcelain', *ARGV)
  die status.exitstatus, stderr unless status.success?
  lines = stdout.split($/)
  stats = nil
  if ARGV.show_stats?
    stats = lines.last(3)
    lines = lines.drop_last(3)
  end
  commits = parse_commits(lines, [])
  author_width = longest_author_name_width(commits)
  line_width = max_line_number_width(commits)
  opts = {
    :show_boundary_commits => !ARGV.blank_boundary_commits?,
    :long_hashes => ARGV.long_hash?,
    :raw_timestamps => ARGV.raw_timestamps?,
  }
  formatter = Git::BlameColor::Formatter.new(author_width, line_width, opts)
  page
  commits.each do |c|
    puts formatter.format(c)
  end
  puts stats.join("\n") if stats
end

Private Instance Methods

die(status, msg) click to toggle source
# File lib/git-blame-color/application.rb, line 49
def die(status, msg)
  STDERR.puts msg
  exit status
end
longest_author_name_width(commits) click to toggle source
# File lib/git-blame-color/application.rb, line 64
def longest_author_name_width(commits)
  commits.longest_string_length_by_key(:author)
end
max_line_number_width(commits) click to toggle source
# File lib/git-blame-color/application.rb, line 68
def max_line_number_width(commits)
  commits.longest_string_length_by_key(:line_number)
end
parse_commits(commits, acc) click to toggle source
# File lib/git-blame-color/application.rb, line 54
def parse_commits(commits, acc)
  return acc if commits.empty?
  lines = commits.take_while { |line| line =~ /^[^\t]/ }
  lines << commits.find { |line| line =~ /^\t/ }
  commit = Git::BlameColor::Commit.new(lines)
  acc << commit
  commits = commits.drop(lines.count)
  parse_commits(commits, acc)
end