2011-11-20 21:32:12 +01:00
|
|
|
class Commit
|
2012-01-28 15:47:55 +01:00
|
|
|
include ActiveModel::Conversion
|
2012-04-11 22:03:56 +02:00
|
|
|
include Gitlabhq::Encode
|
2012-01-28 15:47:55 +01:00
|
|
|
extend ActiveModel::Naming
|
2011-11-28 10:46:41 +01:00
|
|
|
|
2011-11-27 16:35:49 +01:00
|
|
|
attr_accessor :commit
|
|
|
|
attr_accessor :head
|
2012-01-04 07:17:41 +01:00
|
|
|
attr_accessor :refs
|
2011-11-27 16:35:49 +01:00
|
|
|
|
|
|
|
delegate :message,
|
2012-01-12 00:12:49 +01:00
|
|
|
:authored_date,
|
2011-11-27 16:35:49 +01:00
|
|
|
:committed_date,
|
|
|
|
:parents,
|
|
|
|
:sha,
|
|
|
|
:date,
|
2012-01-12 00:12:49 +01:00
|
|
|
:committer,
|
2011-11-27 16:35:49 +01:00
|
|
|
:author,
|
|
|
|
:message,
|
|
|
|
:diffs,
|
|
|
|
:tree,
|
|
|
|
:id,
|
|
|
|
:to => :commit
|
|
|
|
|
2012-03-09 20:43:46 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2012-01-28 15:47:55 +01:00
|
|
|
def persisted?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2011-11-27 16:35:49 +01:00
|
|
|
def initialize(raw_commit, head = nil)
|
|
|
|
@commit = raw_commit
|
|
|
|
@head = head
|
|
|
|
end
|
|
|
|
|
|
|
|
def safe_message
|
2012-04-11 22:03:56 +02:00
|
|
|
utf8 message
|
2011-11-27 16:35:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def created_at
|
|
|
|
committed_date
|
|
|
|
end
|
|
|
|
|
|
|
|
def author_email
|
2011-12-30 14:41:39 +01:00
|
|
|
author.email
|
2011-11-27 16:35:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def author_name
|
2012-04-11 22:03:56 +02:00
|
|
|
utf8 author.name
|
2011-11-27 16:35:49 +01:00
|
|
|
end
|
2011-11-29 19:06:37 +01:00
|
|
|
|
2012-01-12 00:12:49 +01:00
|
|
|
def committer_name
|
2012-04-11 22:03:56 +02:00
|
|
|
utf8 committer.name
|
2012-01-12 00:12:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def committer_email
|
|
|
|
committer.email
|
|
|
|
end
|
|
|
|
|
2011-11-29 19:06:37 +01:00
|
|
|
def prev_commit
|
|
|
|
parents.first
|
|
|
|
end
|
2012-02-29 22:34:06 +01:00
|
|
|
|
|
|
|
def prev_commit_id
|
|
|
|
prev_commit.id
|
|
|
|
end
|
2011-11-20 21:32:12 +01:00
|
|
|
end
|