Created
October 6, 2014 08:10
-
-
Save psyomn/ce25f7cf790bb670f16d to your computer and use it in GitHub Desktop.
Parse git logs to simple objects
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| # Small crappy script to parse git logs | |
| # Simon Symeonidis | |
| str = 'git --git-dir ~/programming/ruby/wlog/.git log' | |
| result = `#{str}` | |
| class GitLog | |
| def initialize | |
| @commit = @author = @shortlog = @message = "" | |
| end | |
| attr_accessor :commit, :author, :shortlog, :message | |
| end | |
| cur = nil | |
| inmessage = false | |
| gitlogs = [] | |
| result.lines.each do |line| | |
| case line | |
| when /^commit/i | |
| inmessage = false | |
| gitlogs.push cur if cur | |
| cur = GitLog.new | |
| cur.commit = line.split[1].strip | |
| when /^author/i | |
| cur.author = line.split[1].strip | |
| when /^date/i, /^\n$/ | |
| next | |
| else | |
| if inmessage | |
| cur.message.concat(line) | |
| cur.message.strip! | |
| else | |
| cur.shortlog = line | |
| cur.shortlog.strip! | |
| inmessage = true | |
| end | |
| end | |
| end | |
| gitlogs.push cur if cur | |
| p gitlogs.first | |
| p 'aaaaaaaaaaaaaaaaaaaaa' | |
| p gitlogs.last |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment