Created
January 8, 2010 11:49
-
-
Save konrad/272005 to your computer and use it in GitHub Desktop.
This "solves" a problem with the git log parser of CruiseControl.rb and ISO-8859-1 encoding.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SourceControl | |
class Git | |
class LogParser | |
def parse(log) | |
@log = log | |
revisions = [] | |
revision = nil | |
log.each do |line| | |
next if line.blank? | |
line.chomp! | |
case line | |
when /^commit / | |
revisions << revision = Revision.new | |
revision.number = line.split[1][0..6] | |
when /^author / | |
revision.author, revision.time = read_author_and_time(line) | |
when /^ / | |
(revision.message ||= []) << line.strip | |
when /^ / | |
(revision.changeset ||= []) << line.strip | |
when /^tree / | |
when /^parent / | |
when /^committer / | |
# don't care | |
# else | |
# raise "don't know how to parse #{line}" | |
end | |
end | |
revisions.each do |revision| | |
revision.message = revision.message.join("\n") if revision.message | |
revision.summary = revision.changeset.pop if revision.changeset | |
end | |
revisions | |
end | |
private | |
def read_author_and_time(line) | |
author, seconds_from_epoch = line.match(/^author (.+) (\d+) [-+]\d{4}$/)[1, 2] | |
[author, Time.at(seconds_from_epoch.to_i)] | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment