class Git::Repository::Logging::Private::RawLogParser
Parser for ‘git log –pretty=raw` output into commit hashes
@api private
Public Class Methods
Source
# File lib/git/repository/logging.rb, line 276 def initialize(lines) @lines = lines @commits = [] @current_commit = nil @in_message = false @last_metadata_key = nil end
Initializes a parser for raw git log output lines
@param lines [Array<String>] raw output lines from ‘git log –pretty=raw`
@return [void]
Public Instance Methods
Source
# File lib/git/repository/logging.rb, line 288 def parse @lines.each { |line| process_line(line.chomp) } finalize_commit @commits end
Parse raw ‘git log –pretty=raw` lines into commit hashes
@return [Array<Hash>] the parsed commits in command output order
Private Instance Methods
Source
# File lib/git/repository/logging.rb, line 349 def dispatch_metadata_key(key, value) case key when 'commit' start_new_commit(value) when 'parent' @current_commit['parent'] << value else @current_commit[key] = value @last_metadata_key = key end end
Applies a metadata key/value pair to the current commit
@param key [String] the metadata key from the raw log line
@param value [String] the parsed metadata value
@return [void]
Source
# File lib/git/repository/logging.rb, line 377 def finalize_commit @commits << @current_commit if @current_commit end
Appends the current commit to the parsed results when present
@return [void]
Source
# File lib/git/repository/logging.rb, line 302 def process_line(line) if line.empty? @in_message = !@in_message return end @in_message = false if @in_message && !line.start_with?(' ') @in_message ? process_message_line(line) : process_metadata_line(line) end
Routes a raw line to message or metadata parsing
@param line [String] the current raw log output line
@return [void]
Source
# File lib/git/repository/logging.rb, line 319 def process_message_line(line) @current_commit['message'] << "#{line[4..]}\n" end
Appends a commit message line to the current commit buffer
@param line [String] an indented message line from raw output
@return [void]
Source
# File lib/git/repository/logging.rb, line 329 def process_metadata_line(line) if line.start_with?(' ') && @last_metadata_key @current_commit[@last_metadata_key] << "\n#{line[1..]}" return end key, *value = line.split value = value.join(' ') @last_metadata_key = nil dispatch_metadata_key(key, value) end
Parses metadata lines and multi-line metadata continuations
@param line [String] a metadata line from raw output
@return [void]
Source
# File lib/git/repository/logging.rb, line 367 def start_new_commit(sha) finalize_commit @current_commit = { 'sha' => sha, 'message' => +'', 'parent' => [] } @last_metadata_key = nil end
Starts a new commit record in the parser state
@param sha [String] the commit SHA for the new record
@return [void]