Commit d521cf8d011d91d494b25a5944d16a2466f5f264

Authored by Dmitriy Zaporozhets
2 parents 5b28bf1e 1e3f09b2

Merge branch 'refactor/gitlab_git_2' of /home/git/repositories/gitlab/gitlabhq

Gemfile
... ... @@ -23,7 +23,7 @@ gem 'omniauth-github'
23 23  
24 24 # Extracting information from a git repository
25 25 # Provide access to Gitlab::Git library
26   -gem 'gitlab_git', '~> 1.4.1'
  26 +gem "gitlab_git", "~> 2.0.0.pre"
27 27  
28 28 # Ruby/Rack Git Smart-HTTP Server Handler
29 29 gem 'gitlab-grack', '~> 1.0.1', require: 'grack'
... ...
Gemfile.lock
... ... @@ -176,7 +176,7 @@ GEM
176 176 gitlab-pygments.rb (0.3.2)
177 177 posix-spawn (~> 0.3.6)
178 178 yajl-ruby (~> 1.1.0)
179   - gitlab_git (1.4.1)
  179 + gitlab_git (2.0.0.pre)
180 180 activesupport (~> 3.2.13)
181 181 github-linguist (~> 2.3.4)
182 182 gitlab-grit (~> 2.6.0)
... ... @@ -275,7 +275,7 @@ GEM
275 275 minitest (4.7.4)
276 276 modernizr (2.6.2)
277 277 sprockets (~> 2.0)
278   - multi_json (1.7.7)
  278 + multi_json (1.7.8)
279 279 multi_xml (0.5.4)
280 280 multipart-post (1.2.0)
281 281 mysql2 (0.3.11)
... ... @@ -568,7 +568,7 @@ DEPENDENCIES
568 568 gitlab-gollum-lib (~> 1.0.1)
569 569 gitlab-grack (~> 1.0.1)
570 570 gitlab-pygments.rb (~> 0.3.2)
571   - gitlab_git (~> 1.4.1)
  571 + gitlab_git (~> 2.0.0.pre)
572 572 gitlab_meta (= 6.0)
573 573 gitlab_omniauth-ldap (= 1.0.3)
574 574 gon
... ...
app/controllers/projects/branches_controller.rb
... ... @@ -11,6 +11,10 @@ class Projects::BranchesController < Projects::ApplicationController
11 11 @branches = Kaminari.paginate_array(@repository.branches).page(params[:page]).per(30)
12 12 end
13 13  
  14 + def recent
  15 + @branches = @repository.recent_branches
  16 + end
  17 +
14 18 def create
15 19 @repository.add_branch(params[:branch_name], params[:ref])
16 20  
... ...
app/controllers/projects/edit_tree_controller.rb
... ... @@ -10,7 +10,7 @@ class Projects::EditTreeController < Projects::ApplicationController
10 10 before_filter :edit_requirements, only: [:show, :update]
11 11  
12 12 def show
13   - @last_commit = @project.repository.last_commit_for(@ref, @path).sha
  13 + @last_commit = Gitlab::Git::Commit.last_for_path(@project.repository, @ref, @path).sha
14 14 end
15 15  
16 16 def update
... ...
app/controllers/projects/repositories_controller.rb
... ... @@ -4,10 +4,6 @@ class Projects::RepositoriesController < Projects::ApplicationController
4 4 before_filter :authorize_code_access!
5 5 before_filter :require_non_empty_project
6 6  
7   - def show
8   - @activities = @repository.commits_with_refs(20)
9   - end
10   -
11 7 def stats
12 8 @stats = Gitlab::Git::Stats.new(@repository.raw, @repository.root_ref)
13 9 @graph = @stats.graph
... ...
app/models/merge_request.rb
... ... @@ -137,7 +137,7 @@ class MergeRequest < ActiveRecord::Base
137 137 end
138 138  
139 139 def unmerged_diffs
140   - project.repository.diffs_between(source_branch, target_branch)
  140 + Gitlab::Git::Diff.between(project.repository, source_branch, target_branch)
141 141 end
142 142  
143 143 def last_commit
... ...
app/models/repository.rb
... ... @@ -18,19 +18,25 @@ class Repository
18 18 end
19 19  
20 20 def commit(id = nil)
21   - commit = raw_repository.commit(id)
  21 + commit = Gitlab::Git::Commit.find(raw_repository, id)
22 22 commit = Commit.new(commit) if commit
23 23 commit
24 24 end
25 25  
26 26 def commits(ref, path = nil, limit = nil, offset = nil)
27   - commits = raw_repository.commits(ref, path, limit, offset)
  27 + commits = Gitlab::Git::Commit.where(
  28 + repo: raw_repository,
  29 + ref: ref,
  30 + path: path,
  31 + limit: limit,
  32 + offset: offset,
  33 + )
28 34 commits = Commit.decorate(commits) if commits.present?
29 35 commits
30 36 end
31 37  
32   - def commits_between(target, source)
33   - commits = raw_repository.commits_between(target, source)
  38 + def commits_between(from, to)
  39 + commits = Gitlab::Git::Commit.between(raw_repository, from, to)
34 40 commits = Commit.decorate(commits) if commits.present?
35 41 commits
36 42 end
... ... @@ -43,6 +49,12 @@ class Repository
43 49 tags.find { |tag| tag.name == name }
44 50 end
45 51  
  52 + def recent_branches(limit = 20)
  53 + branches.sort do |a, b|
  54 + a.commit.committed_date <=> b.commit.committed_date
  55 + end[0..limit]
  56 + end
  57 +
46 58 def add_branch(branch_name, ref)
47 59 Rails.cache.delete(cache_key(:branch_names))
48 60  
... ...
app/views/projects/branches/_filter.html.haml 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +%ul.nav.nav-pills.nav-stacked
  2 + = nav_link(path: 'branches#recent') do
  3 + = link_to 'Recent', recent_project_branches_path(@project)
  4 + = nav_link(path: 'protected_branches#index') do
  5 + = link_to project_protected_branches_path(@project) do
  6 + Protected
  7 + %i.icon-lock
  8 + = nav_link(path: 'branches#index') do
  9 + = link_to 'All branches', project_branches_path(@project)
  10 +
  11 +
  12 +%hr
  13 +- if can? current_user, :push_code, @project
  14 + = link_to new_project_branch_path(@project), class: 'btn btn-create' do
  15 + %i.icon-add-sign
  16 + New branch
  17 +
... ...
app/views/projects/branches/index.html.haml
1 1 = render "projects/commits/head"
2 2 .row
3 3 .span3
4   - = render "projects/repositories/filter"
  4 + = render "filter"
5 5 .span9
6 6 - unless @branches.empty?
7 7 %ul.bordered-list
... ...
app/views/projects/branches/recent.html.haml 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 += render "projects/commits/head"
  2 +.row
  3 + .span3
  4 + = render "filter"
  5 + .span9
  6 + %ul.bordered-list
  7 + - @branches.each do |branch|
  8 + = render "projects/branches/branch", branch: branch
... ...
app/views/projects/commits/_head.html.haml
... ... @@ -7,7 +7,7 @@
7 7 = link_to 'Compare', project_compare_index_path(@project)
8 8  
9 9 = nav_link(html_options: {class: branches_tab_class}) do
10   - = link_to project_repository_path(@project) do
  10 + = link_to recent_project_branches_path(@project) do
11 11 Branches
12 12 %span.badge= @repository.branches.length
13 13  
... ...
app/views/projects/protected_branches/index.html.haml
1 1 = render "projects/commits/head"
2 2 .row
3 3 .span3
4   - = render "projects/repositories/filter"
  4 + = render "projects/branches/filter"
5 5 .span9
6 6 .alert.alert-info
7 7 %p Protected branches designed to prevent push for all except #{link_to "masters", help_permissions_path, class: "vlink"}.
... ...
app/views/projects/repositories/_filter.html.haml
... ... @@ -1,17 +0,0 @@
1   -%ul.nav.nav-pills.nav-stacked
2   - = nav_link(path: 'repositories#show') do
3   - = link_to 'Recent', project_repository_path(@project)
4   - = nav_link(path: 'protected_branches#index') do
5   - = link_to project_protected_branches_path(@project) do
6   - Protected
7   - %i.icon-lock
8   - = nav_link(path: 'branches#index') do
9   - = link_to 'All branches', project_branches_path(@project)
10   -
11   -
12   -%hr
13   -- if can? current_user, :push_code, @project
14   - = link_to new_project_branch_path(@project), class: 'btn btn-create' do
15   - %i.icon-add-sign
16   - New branch
17   -
app/views/projects/repositories/show.html.haml
... ... @@ -1,9 +0,0 @@
1   -= render "projects/commits/head"
2   -.row
3   - .span3
4   - = render "filter"
5   - .span9
6   - %ul.bordered-list
7   - - @activities.each do |update|
8   - = render "projects/branches/branch", branch: update.head
9   -
config/routes.rb
... ... @@ -225,8 +225,13 @@ Gitlab::Application.routes.draw do
225 225 end
226 226 end
227 227  
  228 + resources :branches, only: [:index, :new, :create, :destroy] do
  229 + collection do
  230 + get :recent
  231 + end
  232 + end
  233 +
228 234 resources :tags, only: [:index, :new, :create, :destroy]
229   - resources :branches, only: [:index, :new, :create, :destroy]
230 235 resources :protected_branches, only: [:index, :create, :destroy]
231 236  
232 237 resources :refs, only: [] do
... ...
lib/extracts_path.rb
... ... @@ -95,13 +95,9 @@ module ExtractsPath
95 95 # resolved (e.g., when a user inserts an invalid path or ref).
96 96 def assign_ref_vars
97 97 @id = get_id
98   -
99 98 @ref, @path = extract_ref(@id)
100   -
101 99 @repo = @project.repository
102   -
103 100 @commit = @repo.commit(@ref)
104   -
105 101 @tree = Tree.new(@repo, @commit.id, @ref, @path)
106 102 @hex_path = Digest::SHA1.hexdigest(@path)
107 103 @logs_path = logs_file_project_ref_path(@project, @ref, @path)
... ...
lib/gitlab/satellite/edit_file_action.rb
... ... @@ -49,7 +49,7 @@ module Gitlab
49 49 protected
50 50  
51 51 def can_edit?(last_commit)
52   - current_last_commit = @project.repository.last_commit_for(ref, file_path).sha
  52 + current_last_commit = Gitlab::Git::Commit.last_for_path(@project.repository, ref, file_path).sha
53 53 last_commit == current_last_commit
54 54 end
55 55 end
... ...
spec/controllers/commit_controller_spec.rb
... ... @@ -3,7 +3,7 @@ require &#39;spec_helper&#39;
3 3 describe Projects::CommitController do
4 4 let(:project) { create(:project_with_code) }
5 5 let(:user) { create(:user) }
6   - let(:commit) { project.repository.last_commit_for("master") }
  6 + let(:commit) { project.repository.commit("master") }
7 7  
8 8 before do
9 9 sign_in(user)
... ...
spec/features/security/project_access_spec.rb
... ... @@ -175,8 +175,8 @@ describe &quot;Application access&quot; do
175 175 it { should be_denied_for :visitor }
176 176 end
177 177  
178   - describe "GET /project_code/repository" do
179   - subject { project_repository_path(project) }
  178 + describe "GET /project_code/branches/recent" do
  179 + subject { recent_project_branches_path(project) }
180 180  
181 181 it { should be_allowed_for master }
182 182 it { should be_allowed_for reporter }
... ... @@ -186,7 +186,7 @@ describe &quot;Application access&quot; do
186 186 it { should be_denied_for :visitor }
187 187 end
188 188  
189   - describe "GET /project_code/repository/branches" do
  189 + describe "GET /project_code/branches" do
190 190 subject { project_branches_path(project) }
191 191  
192 192 before do
... ... @@ -202,7 +202,7 @@ describe &quot;Application access&quot; do
202 202 it { should be_denied_for :visitor }
203 203 end
204 204  
205   - describe "GET /project_code/repository/tags" do
  205 + describe "GET /project_code/tags" do
206 206 subject { project_tags_path(project) }
207 207  
208 208 before do
... ... @@ -417,8 +417,8 @@ describe &quot;Application access&quot; do
417 417 it { should be_denied_for :visitor }
418 418 end
419 419  
420   - describe "GET /project_code/repository" do
421   - subject { project_repository_path(project) }
  420 + describe "GET /project_code/branches/recent" do
  421 + subject { recent_project_branches_path(project) }
422 422  
423 423 it { should be_allowed_for master }
424 424 it { should be_allowed_for reporter }
... ... @@ -428,7 +428,7 @@ describe &quot;Application access&quot; do
428 428 it { should be_denied_for :visitor }
429 429 end
430 430  
431   - describe "GET /project_code/repository/branches" do
  431 + describe "GET /project_code/branches" do
432 432 subject { project_branches_path(project) }
433 433  
434 434 before do
... ... @@ -444,7 +444,7 @@ describe &quot;Application access&quot; do
444 444 it { should be_denied_for :visitor }
445 445 end
446 446  
447   - describe "GET /project_code/repository/tags" do
  447 + describe "GET /project_code/tags" do
448 448 subject { project_tags_path(project) }
449 449  
450 450 before do
... ...