Skip to content

Instantly share code, notes, and snippets.

@danlynn
Created June 30, 2010 14:57
Show Gist options
  • Save danlynn/458759 to your computer and use it in GitHub Desktop.
Save danlynn/458759 to your computer and use it in GitHub Desktop.
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