Created
June 25, 2013 18:01
-
-
Save nagachika/5860778 to your computer and use it in GitHub Desktop.
svn.rb
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
#!/usr/bin/env ruby | |
module Svn | |
class Revision | |
def initialize(str) | |
unless /r(\d+) \| (\S+) \| (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \S+)/ =~ str | |
raise "unrecognized svn log message #{str}" | |
end | |
@revision = Regexp.last_match(1) | |
@developer = Regexp.last_match(2) | |
@time = Regexp.last_match(3) | |
@revision = Integer(@revision) | |
@msg = str.split(/\n/)[2..-1].join("\n") | |
end | |
attr_reader :revision, :developer, :time, :msg | |
end | |
module Log | |
def format_time(time) | |
"{\"#{time.strftime("%Y-%m-%d %H:%M:%S")}\"}" | |
end | |
module_function :format_time | |
def revisions(root, from, to="HEAD", branch="trunk") | |
if from.is_a?(Time) | |
from = format_time(from) | |
end | |
if to.is_a?(Time) | |
to = format_time(to) | |
end | |
msg = `svn log --revision #{from}:#{to} #{root}/#{branch}` | |
revs = msg.split(/^-{72}$/).select{|l| /\S+/ =~ l } | |
revs.map{|msg| Revision.new(msg) } | |
end | |
module_function :revisions | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment