Project model refactored
This commit is contained in:
parent
9988282e84
commit
cd06d6edac
4 changed files with 82 additions and 68 deletions
|
@ -20,6 +20,66 @@ class Commit
|
|||
:id,
|
||||
:to => :commit
|
||||
|
||||
|
||||
class << self
|
||||
def find_or_first(repo, commit_id = nil)
|
||||
commit = if commit_id
|
||||
repo.commit(commit_id)
|
||||
else
|
||||
repo.commits.first
|
||||
end
|
||||
Commit.new(commit) if commit
|
||||
end
|
||||
|
||||
def fresh_commits(repo, n = 10)
|
||||
commits = repo.heads.map do |h|
|
||||
repo.commits(h.name, n).map { |c| Commit.new(c, h) }
|
||||
end.flatten.uniq { |c| c.id }
|
||||
|
||||
commits.sort! do |x, y|
|
||||
y.committed_date <=> x.committed_date
|
||||
end
|
||||
|
||||
commits[0...n]
|
||||
end
|
||||
|
||||
def commits_with_refs(repo, n = 20)
|
||||
commits = repo.branches.map { |ref| Commit.new(ref.commit, ref) }
|
||||
|
||||
commits.sort! do |x, y|
|
||||
y.committed_date <=> x.committed_date
|
||||
end
|
||||
|
||||
commits[0..n]
|
||||
end
|
||||
|
||||
def commits_since(repo, date)
|
||||
commits = repo.heads.map do |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|
|
||||
y.committed_date <=> x.committed_date
|
||||
end
|
||||
|
||||
commits
|
||||
end
|
||||
|
||||
def commits(repo, 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
|
||||
|
||||
def commits_between(repo, from, to)
|
||||
repo.commits_between(from, to).map { |c| Commit.new(c) }
|
||||
end
|
||||
end
|
||||
|
||||
def persisted?
|
||||
false
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue