modify the commit_count by hx

This commit is contained in:
houxiang 2015-11-23 19:48:20 +08:00
parent 56519389d2
commit b3d36705d2
1 changed files with 20 additions and 32 deletions

View File

@ -315,19 +315,17 @@ update
#Modified by young #Modified by young
# (show_error_not_found; return) unless @entries # (show_error_not_found; return) unless @entries
g = Gitlab.client g = Gitlab.client
if g.commits(@project.gpid , :page=>25).count==0
# count = 0 count = count_commits(@project.gpid , 0 , 25)
# (0..100).each do |page| elsif g.commits(@project.gpid , :page=>50).count ==0
# if g.commits(@project.gpid,:page => page).count == 0 count = count_commits(@project.gpid , 25 , 50)+ 25 * 20
# break elsif g.commits(@project.gpid , :page=>75).count ==0
# else count = count_commits(@project.gpid , 50 , 75)+ 50 * 20
# count = count + g.commits(@project.gpid,:page => page).count elsif g.commits(@project.gpid , :page=>100).count== 0
# end count = count_commits(@project.gpid , 75 , 100) + 75 * 20
# end else
count = count_commits(@project.gpid , 100 , 125) + 100 * 20
#add by hx end
pages , last_page_count = binarySearch(@project.gpid)
count = (pages-1)*20 + last_page_count
@changesets = g.commits(@project.gpid) @changesets = g.commits(@project.gpid)
# @changesets = @repository.latest_changesets(@path, @rev) # @changesets = @repository.latest_changesets(@path, @rev)
@ -355,28 +353,18 @@ update
alias_method :browse, :show alias_method :browse, :show
#add by hx def count_commits(project_id , left , right)
def binarySearch(project_id ,left=0 , right=30 ) count = 0
#如果right页面有数据,直接递归将right改left,right=right+100 (left..right).each do |page|
if $g.commits(project_id,:page=>right.to_s).count>0 if $g.commits(project_id,:page => page).count == 0
binarySearch(project_id,right,right+100) break
end else
#取自己默认页面数的中间页面数 count = count + $g.commits(project_id,:page => page).count
median = (left + right)/2 end
#判断是否为最后一个页面
if $g.commits(project_id,:page=>median.to_s).count >0 && $g.commits(project_id,:page=>(median+1).to_s).count==0
#返回前面的页面数,和最后一个页面的commits_count
return median , $g.commits(project_id,:page=>median.to_s)
#左边查找
elsif $g.commits(project_id,:page=>median.to_s).count == 0
binarySearch(project_id,left,median-1)
#右边查找
elsif $g.commits(project_id,:page=>(median+1).to_s).count > 0
binarySearch(project_id,median+1,right)
end end
return count
end end
def changes def changes
@entry = @repository.entry(@path, @rev) @entry = @repository.entry(@path, @rev)
(show_error_not_found; return) unless @entry (show_error_not_found; return) unless @entry