diff --git a/app/controllers/git/blobs_controller.rb b/app/controllers/git/blobs_controller.rb index 64fdcc000..ad72d595d 100644 --- a/app/controllers/git/blobs_controller.rb +++ b/app/controllers/git/blobs_controller.rb @@ -6,12 +6,13 @@ class Git::BlobsController < Git::BaseController def show if @commit_hash @tree = @git_repository.tree(@commit_hash) + @commit = @git_repository.commits(@treeish, 1).first else @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 end diff --git a/app/controllers/git/commits_controller.rb b/app/controllers/git/commits_controller.rb index 4496ef17a..5da67079d 100644 --- a/app/controllers/git/commits_controller.rb +++ b/app/controllers/git/commits_controller.rb @@ -4,7 +4,13 @@ class Git::CommitsController < Git::BaseController @branch_name = (params[:branch] ? params[:branch] : "master") @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 def show diff --git a/app/controllers/git/trees_controller.rb b/app/controllers/git/trees_controller.rb index a82d78a2e..dbf40fde9 100644 --- a/app/controllers/git/trees_controller.rb +++ b/app/controllers/git/trees_controller.rb @@ -7,7 +7,8 @@ class Git::TreesController < Git::BaseController @tree = @git_repository.tree(@treeish) @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 diff --git a/app/models/git/repository.rb b/app/models/git/repository.rb index 6a59959fc..8272ac8ce 100644 --- a/app/models/git/repository.rb +++ b/app/models/git/repository.rb @@ -1,5 +1,5 @@ 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 @@ -24,4 +24,17 @@ class Git::Repository repo.enable_daemon_serve 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 \ No newline at end of file diff --git a/app/views/git/blobs/show.html.haml b/app/views/git/blobs/show.html.haml index 01aaa6fb5..c77d63b34 100644 --- a/app/views/git/blobs/show.html.haml +++ b/app/views/git/blobs/show.html.haml @@ -12,10 +12,11 @@ \: = @project.name -.block - .content - .inner - = render :partial => "git/commits/commits", :object => [@commit] +- if @commit + .block + .content + .inner + = render :partial => "git/commits/commits", :object => [@commit] .block .content diff --git a/app/views/git/commits/_paginate.html.haml b/app/views/git/commits/_paginate.html.haml new file mode 100644 index 000000000..81a051710 --- /dev/null +++ b/app/views/git/commits/_paginate.html.haml @@ -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 » \ No newline at end of file diff --git a/app/views/git/commits/index.html.haml b/app/views/git/commits/index.html.haml index 2e38a3840..97ecc937b 100644 --- a/app/views/git/commits/index.html.haml +++ b/app/views/git/commits/index.html.haml @@ -17,4 +17,9 @@ .inner = 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') diff --git a/app/views/git/repositories/show.html.haml b/app/views/git/repositories/show.html.haml index 107738550..2db6215b7 100644 --- a/app/views/git/repositories/show.html.haml +++ b/app/views/git/repositories/show.html.haml @@ -12,10 +12,11 @@ \: = @project.name -.block - .content - .inner - = render :partial => "git/commits/commits", :object => [@commit] +- if @commit + .block + .content + .inner + = render :partial => "git/commits/commits", :object => [@commit] .block .content