diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 167514865..36deafde4 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -315,19 +315,17 @@ update #Modified by young # (show_error_not_found; return) unless @entries g = Gitlab.client - - # count = 0 - # (0..100).each do |page| - # if g.commits(@project.gpid,:page => page).count == 0 - # break - # else - # count = count + g.commits(@project.gpid,:page => page).count - # end - # end - - #add by hx - pages , last_page_count = binarySearch(@project.gpid) - count = (pages-1)*20 + last_page_count + if g.commits(@project.gpid , :page=>25).count==0 + count = count_commits(@project.gpid , 0 , 25) + elsif g.commits(@project.gpid , :page=>50).count ==0 + count = count_commits(@project.gpid , 25 , 50)+ 25 * 20 + elsif g.commits(@project.gpid , :page=>75).count ==0 + count = count_commits(@project.gpid , 50 , 75)+ 50 * 20 + elsif g.commits(@project.gpid , :page=>100).count== 0 + count = count_commits(@project.gpid , 75 , 100) + 75 * 20 + else + count = count_commits(@project.gpid , 100 , 125) + 100 * 20 + end @changesets = g.commits(@project.gpid) # @changesets = @repository.latest_changesets(@path, @rev) @@ -355,28 +353,18 @@ update alias_method :browse, :show - #add by hx - def binarySearch(project_id ,left=0 , right=30 ) - #如果right页面有数据,直接递归将right改left,right=right+100 - if $g.commits(project_id,:page=>right.to_s).count>0 - binarySearch(project_id,right,right+100) - end - #取自己默认页面数的中间页面数 - median = (left + right)/2 - #判断是否为最后一个页面 - 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) + def count_commits(project_id , left , right) + count = 0 + (left..right).each do |page| + if $g.commits(project_id,:page => page).count == 0 + break + else + count = count + $g.commits(project_id,:page => page).count + end end + return count end - def changes @entry = @repository.entry(@path, @rev) (show_error_not_found; return) unless @entry