Created
June 30, 2010 14:57
-
-
Save danlynn/458759 to your computer and use it in GitHub Desktop.
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
def get_owner_or_init_from_svn | |
unless self.owner | |
owner_name = Source.get_owner_from_svn_log(self.path) | |
if owner_name | |
self.owner = Owner.find_or_create_by_name(owner_name) | |
self.save! | |
end | |
end | |
return self.owner | |
end | |
# call-seq | |
# get_owner_from_svn_log(Pathname("path/to/source.java")) => owner_name | |
# | |
# if 'pathname' doesn't exist or there is no commit history then returns nil | |
def self.get_owner_from_svn_log(pathname) | |
log = `svn log #{pathname}` | |
first_commit_time = nil | |
committers = Hash.new(0) | |
log.reverse_each do |line| | |
if line =~ /^\w+? \| (\w+?) \| (.+?) \(.+?\) \| / | |
first_commit_time ||= Time.parse($2) | |
committers[$1] += (Time.parse($2) - first_commit_time) / 86400 | |
end | |
end | |
committers.sort {|a,b| a[1] <=> b[1]}.last[0] rescue nil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment