class Gitlab::Git::LogParser

Public Class Methods

parse_log(log_from_git) click to toggle source

Parses the log file into a collection of commits Data model:

{author_name, author_email, date, additions, deletions}
# File lib/gitlab_git/log_parser.rb, line 7
def self.parse_log(log_from_git)
  log = log_from_git.split("\n")
  collection = []

  log.each_slice(5) do |slice|
    entry = {}
    entry[:author_name] = slice[0].force_encoding('UTF-8')
    entry[:author_email] = slice[1].force_encoding('UTF-8')
    entry[:date] = slice[2]

    if slice[4]
      changes = slice[4]

      entry[:additions] = $1.to_i if changes =~ /(\d+) insertion/
      entry[:deletions] = $1.to_i if changes =~ /(\d+) deletion/
    end

    collection.push(entry)
  end

  collection
end