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