Commit, network graph refactoring

This commit is contained in:
Dmitriy Zaporozhets 2011-11-27 17:35:49 +02:00
parent 1b2fba08fe
commit a031813887
14 changed files with 125 additions and 97 deletions

View file

@ -1,2 +1,37 @@
class Commit
attr_accessor :commit
attr_accessor :head
delegate :message,
:committed_date,
:parents,
:sha,
:date,
:author,
:message,
:diffs,
:tree,
:id,
:to => :commit
def initialize(raw_commit, head = nil)
@commit = raw_commit
@head = head
end
def safe_message
message.force_encoding(Encoding::UTF_8)
end
def created_at
committed_date
end
def author_email
author.email.force_encoding(Encoding::UTF_8)
end
def author_name
author.name.force_encoding(Encoding::UTF_8)
end
end

View file

@ -64,16 +64,17 @@ class Repository
end
def commit(commit_id = nil)
if commit_id
repo.commits(commit_id).first
else
repo.commits.first
end
commit = if commit_id
repo.commits(commit_id).first
else
repo.commits.first
end
Commit.new(commit) if commit
end
def fresh_commits(n = 10)
commits = heads.map do |h|
repo.commits(h.name, n).each { |c| c.head = h }
repo.commits(h.name, n).map { |c| Commit.new(c, h) }
end.flatten.uniq { |c| c.id }
commits.sort! do |x, y|
@ -85,7 +86,7 @@ class Repository
def commits_since(date)
commits = heads.map do |h|
repo.log(h.name, nil, :since => date).each { |c| c.head = h }
repo.log(h.name, nil, :since => date).each { |c| Commit.new(c, h) }
end.flatten.uniq { |c| c.id }
commits.sort! do |x, y|
@ -94,4 +95,14 @@ class Repository
commits
end
def commits(ref, path = nil, limit = nil, offset = nil)
if path
repo.log(ref, path, :max_count => limit, :skip => offset)
elsif limit && offset
repo.commits(ref, limit, offset)
else
repo.commits(ref)
end.map{ |c| Commit.new(c) }
end
end