Guest User

Untitled

a guest
Apr 27th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. module SourceControl
  2. class Git
  3. class LogParser
  4. def parse(log)
  5. @log = log
  6. revisions = []
  7. revision = nil
  8.  
  9. log.each do |line|
  10. next if line.blank?
  11. line.chomp!
  12. case line
  13. when /^commit /
  14. revisions << revision = Revision.new
  15. revision.number = line.split[1][0..6]
  16.  
  17. when /^author /
  18. revision.author, revision.time = read_author_and_time(line)
  19.  
  20. when /^ /
  21. (revision.message ||= []) << line.strip
  22.  
  23. when /^ /
  24. (revision.changeset ||= []) << line.strip
  25.  
  26. when /^tree /
  27. when /^parent /
  28. when /^committer /
  29. # don't care
  30.  
  31. # else
  32. # raise "don't know how to parse #{line}"
  33. end
  34. end
  35.  
  36. revisions.each do |revision|
  37. revision.message = revision.message.join("\n") if revision.message
  38. revision.summary = revision.changeset.pop if revision.changeset
  39. end
  40. revisions
  41. end
  42.  
  43. private
  44.  
  45. def read_author_and_time(line)
  46. author, seconds_from_epoch = line.match(/^author (.+) (\d+) [-+]\d{4}$/)[1, 2]
  47. [author, Time.at(seconds_from_epoch.to_i)]
  48. end
  49. end
  50. end
  51. end
Add Comment
Please, Sign In to add comment