Class: Dolt::Git::Commit

Inherits:
Object
  • Object
show all
Defined in:
lib/libdolt/git/commit.rb

Class Method Summary collapse

Class Method Details

.extract_commit(lines) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/libdolt/git/commit.rb', line 30

def self.extract_commit(lines)
  commit = { :oid => lines.shift.split(" ")[1] }
  while (line = lines.shift) != ""
    pieces = line.split(": ")
    extract_property(commit, pieces[0], pieces[1])
  end

  commit[:summary] = extract_commit_summary(lines)
  commit[:message] = extract_commit_message(lines)
  commit
end

.extract_commit_message(lines) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/libdolt/git/commit.rb', line 62

def self.extract_commit_message(lines)
  message = ""

  while !lines.first.nil? && lines.first !~ /^commit [a-z0-9]{40}$/
    message << lines.shift
  end

  message
end

.extract_commit_summary(lines) ⇒ Object



56
57
58
59
60
# File 'lib/libdolt/git/commit.rb', line 56

def self.extract_commit_summary(lines)
  summary = lines.shift
  lines.shift if lines.first == ""
  summary.sub(/^    /, "")
end

.extract_property(hash, name, value) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/libdolt/git/commit.rb', line 42

def self.extract_property(hash, name, value)
  key = name.downcase.to_sym

  case key
  when :author
    pieces = value.match(/(.*)\s<(.*)>/)
    value = { :name => pieces[1], :email => pieces[2] }
  when :date
    value = Time.parse(value)
  end

  hash[key] = value
end

.parse_log(log) ⇒ Object



23
24
25
26
27
28
# File 'lib/libdolt/git/commit.rb', line 23

def self.parse_log(log)
  commits = []
  lines = log.split("\n")
  commits << extract_commit(lines) while lines.length > 0
  commits
end