Created
April 16, 2009 19:04
-
-
Save marksim/96597 to your computer and use it in GitHub Desktop.
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/ruby | |
require 'rubygems' | |
require 'xmlsimple' | |
require 'date' | |
def print_array(array, prefix="") | |
puts "#{prefix}[" | |
array.each do |v| | |
if v.is_a? Hash | |
print_hash(v, "#{prefix}\t") | |
elsif v.is_a? Array | |
print_array(v, "#{prefix}\t") | |
else | |
print "#{prefix}\t#{v.to_s}\n" | |
end | |
end | |
puts "#{prefix}]" | |
end | |
def print_hash(hash, prefix="") | |
puts "#{prefix}{" | |
hash.each_pair do |k,v| | |
print "#{prefix}\t#{k} => " | |
if v.is_a? Hash | |
print "\n" | |
print_hash(v, "#{prefix}\t") | |
elsif v.is_a? Array | |
print "\n" | |
print_array(v, "#{prefix}\t") | |
else | |
print "#{v.to_s}\n" | |
end | |
end | |
puts "#{prefix}}" | |
end | |
class Revision | |
attr_reader :branch, :message, :date, :author, :revision, :paths | |
def initialize(options) | |
@branch = options['branch'] | |
@message = options['msg'][0] | |
@date = Date.parse(options['date'][0]) | |
@author = options['author'][0] | |
@revision = options['revision'].to_i | |
@paths = [] | |
options['paths'][0]['path'].each do |pathhash| | |
@paths << pathhash | |
end | |
end | |
def to_s | |
paths = [] | |
@paths.each do |p| | |
paths << "#{p['action']} #{p['content'][0..61]}#{p['content'].length > 61 ? "..." : ""}" | |
end | |
"#{@branch}\n\t\t#{@revision} on #{@date} by #{@author}\n\t\t\t#{@message}\n\t\t\t#{paths.join("\n\t\t\t")}" | |
end | |
def <=>(o) | |
return @revision <=> o.revision | |
end | |
end | |
def parse(filenames) | |
results = [] | |
filenames.each do |filename| | |
doc = XmlSimple.xml_in(filename) | |
doc['logentry'].each do |entry| | |
results << Revision.new(entry.merge('branch' => filename)) | |
end | |
end | |
results.sort.reverse | |
end | |
print_array(parse(ARGV)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment