commit pagination + fixes
This commit is contained in:
parent
6120547800
commit
4f7c51b61f
|
@ -6,12 +6,13 @@ class Git::BlobsController < Git::BaseController
|
||||||
def show
|
def show
|
||||||
if @commit_hash
|
if @commit_hash
|
||||||
@tree = @git_repository.tree(@commit_hash)
|
@tree = @git_repository.tree(@commit_hash)
|
||||||
|
@commit = @git_repository.commits(@treeish, 1).first
|
||||||
else
|
else
|
||||||
@tree = @git_repository.tree(@treeish)
|
@tree = @git_repository.tree(@treeish)
|
||||||
@commit_hash = @git_repository.repo.log(@treeish, @path).first.id
|
|
||||||
end
|
|
||||||
|
|
||||||
@commit = @git_repository.commits(@treeish, 1).first
|
@commit = @git_repository.log(@treeish, @path).first
|
||||||
|
@commit_hash = @commit.id if @commit
|
||||||
|
end
|
||||||
|
|
||||||
@blob = @tree / @path
|
@blob = @tree / @path
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,13 @@ class Git::CommitsController < Git::BaseController
|
||||||
@branch_name = (params[:branch] ? params[:branch] : "master")
|
@branch_name = (params[:branch] ? params[:branch] : "master")
|
||||||
@path = params[:path]
|
@path = params[:path]
|
||||||
|
|
||||||
@commits = @path.present? ? @git_repository.repo.log(@branch_name, @path) : @git_repository.commits(@branch_name)
|
if @path.present?
|
||||||
|
@commits = @git_repository.repo.log(@branch_name, @path)
|
||||||
|
@render_paginate = false
|
||||||
|
else
|
||||||
|
@commits, @page, @last_page = @git_repository.paginate_commits(@branch_name, :page => params[:page])
|
||||||
|
@render_paginate = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|
|
@ -7,7 +7,8 @@ class Git::TreesController < Git::BaseController
|
||||||
@tree = @git_repository.tree(@treeish)
|
@tree = @git_repository.tree(@treeish)
|
||||||
|
|
||||||
@commit = @git_repository.commits(@treeish, 1).first
|
@commit = @git_repository.commits(@treeish, 1).first
|
||||||
# @commit = @git_repository.commit(@treeish) unless @commit
|
# Raises Grit::Git::GitTimeout
|
||||||
|
# @commit = @git_repository.log(@treeish).first
|
||||||
|
|
||||||
@tree = @tree / @path if @path
|
@tree = @tree / @path if @path
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class Git::Repository
|
class Git::Repository
|
||||||
delegate :commits, :commit, :tree, :tags, :heads, :to => :repo
|
delegate :commits, :commit, :tree, :tags, :heads, :commit_count, :log, :to => :repo
|
||||||
|
|
||||||
attr_accessor :path, :name
|
attr_accessor :path, :name
|
||||||
|
|
||||||
|
@ -24,4 +24,17 @@ class Git::Repository
|
||||||
repo.enable_daemon_serve
|
repo.enable_daemon_serve
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
end
|
|
@ -12,10 +12,11 @@
|
||||||
\:
|
\:
|
||||||
= @project.name
|
= @project.name
|
||||||
|
|
||||||
.block
|
- if @commit
|
||||||
.content
|
.block
|
||||||
.inner
|
.content
|
||||||
= render :partial => "git/commits/commits", :object => [@commit]
|
.inner
|
||||||
|
= render :partial => "git/commits/commits", :object => [@commit]
|
||||||
|
|
||||||
.block
|
.block
|
||||||
.content
|
.content
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
- if @page == 1
|
||||||
|
%span.prev_page.disabled « Previous
|
||||||
|
- else
|
||||||
|
%a.next_page{ :rel => "prev", :href => commits_path(@platform, @repository, @project, :treeish => @treeish, :page => (@page - 1)) } « Previous
|
||||||
|
|
||||||
|
- if @last_page
|
||||||
|
%span.next_page.disabled Next »
|
||||||
|
- else
|
||||||
|
%a.next_page{ :rel => "next", :href => commits_path(@platform, @repository, @project, :treeish => @treeish, :page => (@page + 1)) } Next »
|
|
@ -17,4 +17,9 @@
|
||||||
.inner
|
.inner
|
||||||
= render :partial => "git/commits/commits", :object => @commits
|
= render :partial => "git/commits/commits", :object => @commits
|
||||||
|
|
||||||
|
- if @render_paginate
|
||||||
|
.actions-bar.wat-cf
|
||||||
|
.pagination
|
||||||
|
= render :partial => "git/commits/paginate"
|
||||||
|
|
||||||
- content_for :sidebar, render(:partial => 'git/shared/sidebar')
|
- content_for :sidebar, render(:partial => 'git/shared/sidebar')
|
||||||
|
|
|
@ -12,10 +12,11 @@
|
||||||
\:
|
\:
|
||||||
= @project.name
|
= @project.name
|
||||||
|
|
||||||
.block
|
- if @commit
|
||||||
.content
|
.block
|
||||||
.inner
|
.content
|
||||||
= render :partial => "git/commits/commits", :object => [@commit]
|
.inner
|
||||||
|
= render :partial => "git/commits/commits", :object => [@commit]
|
||||||
|
|
||||||
.block
|
.block
|
||||||
.content
|
.content
|
||||||
|
|
Loading…
Reference in New Issue