2011-03-10 12:38:42 +00:00
|
|
|
class Git::Repository
|
2011-04-04 17:00:24 +01:00
|
|
|
delegate :commits, :commit, :tree, :tags, :heads, :commit_count, :log, :branches, :to => :repo
|
2011-03-10 12:38:42 +00:00
|
|
|
|
|
|
|
attr_accessor :path, :name
|
|
|
|
|
2011-03-10 14:07:37 +00:00
|
|
|
def initialize(path)
|
2011-03-10 12:38:42 +00:00
|
|
|
@path = path
|
|
|
|
end
|
|
|
|
|
|
|
|
def master
|
2011-04-01 02:42:48 +01:00
|
|
|
commits('master', 1).first
|
2011-03-10 12:38:42 +00:00
|
|
|
end
|
2011-04-01 01:36:34 +01:00
|
|
|
|
2011-03-10 12:38:42 +00:00
|
|
|
def to_s
|
|
|
|
name
|
|
|
|
end
|
|
|
|
|
|
|
|
def repo
|
2011-03-10 14:07:37 +00:00
|
|
|
@repo ||= Grit::Repo.new(path)
|
2011-03-10 12:38:42 +00:00
|
|
|
end
|
|
|
|
|
2011-03-15 11:24:45 +00:00
|
|
|
def self.create(path)
|
|
|
|
repo = Grit::Repo.init_bare(path)
|
|
|
|
repo.enable_daemon_serve
|
|
|
|
end
|
|
|
|
|
2011-04-04 14:49:08 +01:00
|
|
|
def paginate_commits(treeish, options = {})
|
|
|
|
options[:page] = 1 unless options[:page].present?
|
|
|
|
options[:page] = options[:page].to_i
|
|
|
|
|
|
|
|
options[:per_page] = 20 unless options[:per_page].present?
|
|
|
|
options[:per_page] = options[:per_page].to_i
|
|
|
|
|
|
|
|
skip = options[:per_page] * (options[:page] - 1)
|
|
|
|
last_page = (skip + options[:per_page]) >= commit_count(treeish)
|
|
|
|
|
|
|
|
[commits(treeish, options[:per_page], skip), options[:page], last_page]
|
|
|
|
end
|
|
|
|
|
2011-03-10 12:38:42 +00:00
|
|
|
end
|