rosa-build/app/models/git/repository.rb

40 lines
892 B
Ruby
Raw Normal View History

class Git::Repository
2011-04-04 17:00:24 +01:00
delegate :commits, :commit, :tree, :tags, :heads, :commit_count, :log, :branches, :to => :repo
attr_accessor :path, :name
2011-03-10 14:07:37 +00:00
def initialize(path)
@path = path
end
def master
2011-04-01 02:42:48 +01:00
commits('master', 1).first
end
2011-04-01 01:36:34 +01:00
def to_s
name
end
def repo
2011-03-10 14:07:37 +00:00
@repo ||= Grit::Repo.new(path)
end
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
end