From b92655663c9f066de6a67217ad9a55f38e20cffd Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 5 Aug 2013 16:51:04 +0300 Subject: [PATCH 1/5] Update main calls to gitlab_git --- Gemfile | 2 +- Gemfile.lock | 16 ++++++++++------ app/models/merge_request.rb | 2 +- app/models/repository.rb | 14 ++++++++++---- lib/extracts_path.rb | 4 ---- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index e679f3ee1aa..f5e05a1c8eb 100644 --- a/Gemfile +++ b/Gemfile @@ -23,7 +23,7 @@ gem 'omniauth-github' # Extracting information from a git repository # Provide access to Gitlab::Git library -gem 'gitlab_git', '~> 1.4.1' +gem 'gitlab_git', path: '../gitlab_git'#'~> 1.4.1' # Ruby/Rack Git Smart-HTTP Server Handler gem 'gitlab-grack', '~> 1.0.1', require: 'grack' diff --git a/Gemfile.lock b/Gemfile.lock index 6eedadc74c6..444a3dc8ba1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,6 +12,14 @@ GIT specs: raphael-rails (2.1.0) +PATH + remote: ../gitlab_git + specs: + gitlab_git (1.4.1) + activesupport (~> 3.2.13) + github-linguist (~> 2.3.4) + gitlab-grit (~> 2.6.0) + GEM remote: https://rubygems.org/ specs: @@ -176,10 +184,6 @@ GEM gitlab-pygments.rb (0.3.2) posix-spawn (~> 0.3.6) yajl-ruby (~> 1.1.0) - gitlab_git (1.4.1) - activesupport (~> 3.2.13) - github-linguist (~> 2.3.4) - gitlab-grit (~> 2.6.0) gitlab_meta (6.0) gitlab_omniauth-ldap (1.0.3) net-ldap (~> 0.3.1) @@ -275,7 +279,7 @@ GEM minitest (4.7.4) modernizr (2.6.2) sprockets (~> 2.0) - multi_json (1.7.7) + multi_json (1.7.8) multi_xml (0.5.4) multipart-post (1.2.0) mysql2 (0.3.11) @@ -568,7 +572,7 @@ DEPENDENCIES gitlab-gollum-lib (~> 1.0.1) gitlab-grack (~> 1.0.1) gitlab-pygments.rb (~> 0.3.2) - gitlab_git (~> 1.4.1) + gitlab_git! gitlab_meta (= 6.0) gitlab_omniauth-ldap (= 1.0.3) gon diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 2a476355404..9cd883f421b 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -137,7 +137,7 @@ class MergeRequest < ActiveRecord::Base end def unmerged_diffs - project.repository.diffs_between(source_branch, target_branch) + Gitlab::Git::Diff.between(project.repository, source_branch, target_branch) end def last_commit diff --git a/app/models/repository.rb b/app/models/repository.rb index 588cabfbae0..cd33782a4cc 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -18,19 +18,25 @@ class Repository end def commit(id = nil) - commit = raw_repository.commit(id) + commit = Gitlab::Git::Commit.find(raw_repository, id) commit = Commit.new(commit) if commit commit end def commits(ref, path = nil, limit = nil, offset = nil) - commits = raw_repository.commits(ref, path, limit, offset) + commits = Gitlab::Git::Commit.where( + repo: raw_repository, + ref: ref, + path: path, + limit: limit, + offset: offset, + ) commits = Commit.decorate(commits) if commits.present? commits end - def commits_between(target, source) - commits = raw_repository.commits_between(target, source) + def commits_between(from, to) + commits = Gitlab::Git::Commit.between(raw_repository, from, to) commits = Commit.decorate(commits) if commits.present? commits end diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb index a81c80cfc6f..d1035240cb6 100644 --- a/lib/extracts_path.rb +++ b/lib/extracts_path.rb @@ -95,13 +95,9 @@ module ExtractsPath # resolved (e.g., when a user inserts an invalid path or ref). def assign_ref_vars @id = get_id - @ref, @path = extract_ref(@id) - @repo = @project.repository - @commit = @repo.commit(@ref) - @tree = Tree.new(@repo, @commit.id, @ref, @path) @hex_path = Digest::SHA1.hexdigest(@path) @logs_path = logs_file_project_ref_path(@project, @ref, @path) From bb5e50e0f78ec0dc68d637a43b6ea9889ef1a10d Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 5 Aug 2013 16:55:15 +0300 Subject: [PATCH 2/5] Fix edit files --- app/controllers/projects/edit_tree_controller.rb | 2 +- lib/gitlab/satellite/edit_file_action.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects/edit_tree_controller.rb b/app/controllers/projects/edit_tree_controller.rb index 11c97291296..3b945fc7126 100644 --- a/app/controllers/projects/edit_tree_controller.rb +++ b/app/controllers/projects/edit_tree_controller.rb @@ -10,7 +10,7 @@ class Projects::EditTreeController < Projects::ApplicationController before_filter :edit_requirements, only: [:show, :update] def show - @last_commit = @project.repository.last_commit_for(@ref, @path).sha + @last_commit = Gitlab::Git::Commit.last_for_path(@project.repository, @ref, @path).sha end def update diff --git a/lib/gitlab/satellite/edit_file_action.rb b/lib/gitlab/satellite/edit_file_action.rb index 07570965b1a..d793d0ba8dc 100644 --- a/lib/gitlab/satellite/edit_file_action.rb +++ b/lib/gitlab/satellite/edit_file_action.rb @@ -49,7 +49,7 @@ module Gitlab protected def can_edit?(last_commit) - current_last_commit = @project.repository.last_commit_for(ref, file_path).sha + current_last_commit = Gitlab::Git::Commit.last_for_path(@project.repository, ref, file_path).sha last_commit == current_last_commit end end From 88c741dde062e320ad007a2c5ccb4e7bdc6cdacf Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 5 Aug 2013 17:59:58 +0300 Subject: [PATCH 3/5] Refactor recent branches page --- app/controllers/projects/branches_controller.rb | 4 ++++ app/controllers/projects/repositories_controller.rb | 4 ---- app/models/repository.rb | 6 ++++++ .../{repositories => branches}/_filter.html.haml | 4 ++-- app/views/projects/branches/index.html.haml | 2 +- app/views/projects/branches/recent.html.haml | 8 ++++++++ app/views/projects/commits/_head.html.haml | 2 +- app/views/projects/protected_branches/index.html.haml | 2 +- app/views/projects/repositories/show.html.haml | 9 --------- config/routes.rb | 7 ++++++- 10 files changed, 29 insertions(+), 19 deletions(-) rename app/views/projects/{repositories => branches}/_filter.html.haml (80%) create mode 100644 app/views/projects/branches/recent.html.haml delete mode 100644 app/views/projects/repositories/show.html.haml diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb index 97dbb2bc0c0..aa6914414ce 100644 --- a/app/controllers/projects/branches_controller.rb +++ b/app/controllers/projects/branches_controller.rb @@ -11,6 +11,10 @@ class Projects::BranchesController < Projects::ApplicationController @branches = Kaminari.paginate_array(@repository.branches).page(params[:page]).per(30) end + def recent + @branches = @repository.recent_branches + end + def create @repository.add_branch(params[:branch_name], params[:ref]) diff --git a/app/controllers/projects/repositories_controller.rb b/app/controllers/projects/repositories_controller.rb index 7e6c7016ecf..20e2a9311ee 100644 --- a/app/controllers/projects/repositories_controller.rb +++ b/app/controllers/projects/repositories_controller.rb @@ -4,10 +4,6 @@ class Projects::RepositoriesController < Projects::ApplicationController before_filter :authorize_code_access! before_filter :require_non_empty_project - def show - @activities = @repository.commits_with_refs(20) - end - def stats @stats = Gitlab::Git::Stats.new(@repository.raw, @repository.root_ref) @graph = @stats.graph diff --git a/app/models/repository.rb b/app/models/repository.rb index cd33782a4cc..a2fd91bbec1 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -49,6 +49,12 @@ class Repository tags.find { |tag| tag.name == name } end + def recent_branches(limit = 20) + branches.sort do |a, b| + a.commit.committed_date <=> b.commit.committed_date + end[0..limit] + end + def add_branch(branch_name, ref) Rails.cache.delete(cache_key(:branch_names)) diff --git a/app/views/projects/repositories/_filter.html.haml b/app/views/projects/branches/_filter.html.haml similarity index 80% rename from app/views/projects/repositories/_filter.html.haml rename to app/views/projects/branches/_filter.html.haml index 660d9d25a35..7ea11a74a2b 100644 --- a/app/views/projects/repositories/_filter.html.haml +++ b/app/views/projects/branches/_filter.html.haml @@ -1,6 +1,6 @@ %ul.nav.nav-pills.nav-stacked - = nav_link(path: 'repositories#show') do - = link_to 'Recent', project_repository_path(@project) + = nav_link(path: 'branches#recent') do + = link_to 'Recent', recent_project_branches_path(@project) = nav_link(path: 'protected_branches#index') do = link_to project_protected_branches_path(@project) do Protected diff --git a/app/views/projects/branches/index.html.haml b/app/views/projects/branches/index.html.haml index 4cfafe1a7af..7a0eda6408a 100644 --- a/app/views/projects/branches/index.html.haml +++ b/app/views/projects/branches/index.html.haml @@ -1,7 +1,7 @@ = render "projects/commits/head" .row .span3 - = render "projects/repositories/filter" + = render "filter" .span9 - unless @branches.empty? %ul.bordered-list diff --git a/app/views/projects/branches/recent.html.haml b/app/views/projects/branches/recent.html.haml new file mode 100644 index 00000000000..6cafb47364b --- /dev/null +++ b/app/views/projects/branches/recent.html.haml @@ -0,0 +1,8 @@ += render "projects/commits/head" +.row + .span3 + = render "filter" + .span9 + %ul.bordered-list + - @branches.each do |branch| + = render "projects/branches/branch", branch: branch diff --git a/app/views/projects/commits/_head.html.haml b/app/views/projects/commits/_head.html.haml index 06d69eb5f75..c16abac7f17 100644 --- a/app/views/projects/commits/_head.html.haml +++ b/app/views/projects/commits/_head.html.haml @@ -7,7 +7,7 @@ = link_to 'Compare', project_compare_index_path(@project) = nav_link(html_options: {class: branches_tab_class}) do - = link_to project_repository_path(@project) do + = link_to recent_project_branches_path(@project) do Branches %span.badge= @repository.branches.length diff --git a/app/views/projects/protected_branches/index.html.haml b/app/views/projects/protected_branches/index.html.haml index 9cadb6fb126..8930ec4b30a 100644 --- a/app/views/projects/protected_branches/index.html.haml +++ b/app/views/projects/protected_branches/index.html.haml @@ -1,7 +1,7 @@ = render "projects/commits/head" .row .span3 - = render "projects/repositories/filter" + = render "projects/branches/filter" .span9 .alert.alert-info %p Protected branches designed to prevent push for all except #{link_to "masters", help_permissions_path, class: "vlink"}. diff --git a/app/views/projects/repositories/show.html.haml b/app/views/projects/repositories/show.html.haml deleted file mode 100644 index 611d0eddc4c..00000000000 --- a/app/views/projects/repositories/show.html.haml +++ /dev/null @@ -1,9 +0,0 @@ -= render "projects/commits/head" -.row - .span3 - = render "filter" - .span9 - %ul.bordered-list - - @activities.each do |update| - = render "projects/branches/branch", branch: update.head - diff --git a/config/routes.rb b/config/routes.rb index d303a57d304..c83e18ce4f0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -225,8 +225,13 @@ Gitlab::Application.routes.draw do end end + resources :branches, only: [:index, :new, :create, :destroy] do + collection do + get :recent + end + end + resources :tags, only: [:index, :new, :create, :destroy] - resources :branches, only: [:index, :new, :create, :destroy] resources :protected_branches, only: [:index, :create, :destroy] resources :refs, only: [] do From 128ef337078298966e499365e7dcb6272606b3b5 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 5 Aug 2013 18:16:37 +0300 Subject: [PATCH 4/5] use rubygems for gitlab_git gem --- Gemfile | 2 +- Gemfile.lock | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index f5e05a1c8eb..c865e9f6dd1 100644 --- a/Gemfile +++ b/Gemfile @@ -23,7 +23,7 @@ gem 'omniauth-github' # Extracting information from a git repository # Provide access to Gitlab::Git library -gem 'gitlab_git', path: '../gitlab_git'#'~> 1.4.1' +gem "gitlab_git", "~> 2.0.0.pre" # Ruby/Rack Git Smart-HTTP Server Handler gem 'gitlab-grack', '~> 1.0.1', require: 'grack' diff --git a/Gemfile.lock b/Gemfile.lock index 444a3dc8ba1..b4a2626149f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,14 +12,6 @@ GIT specs: raphael-rails (2.1.0) -PATH - remote: ../gitlab_git - specs: - gitlab_git (1.4.1) - activesupport (~> 3.2.13) - github-linguist (~> 2.3.4) - gitlab-grit (~> 2.6.0) - GEM remote: https://rubygems.org/ specs: @@ -184,6 +176,10 @@ GEM gitlab-pygments.rb (0.3.2) posix-spawn (~> 0.3.6) yajl-ruby (~> 1.1.0) + gitlab_git (2.0.0.pre) + activesupport (~> 3.2.13) + github-linguist (~> 2.3.4) + gitlab-grit (~> 2.6.0) gitlab_meta (6.0) gitlab_omniauth-ldap (1.0.3) net-ldap (~> 0.3.1) @@ -572,7 +568,7 @@ DEPENDENCIES gitlab-gollum-lib (~> 1.0.1) gitlab-grack (~> 1.0.1) gitlab-pygments.rb (~> 0.3.2) - gitlab_git! + gitlab_git (~> 2.0.0.pre) gitlab_meta (= 6.0) gitlab_omniauth-ldap (= 1.0.3) gon From 1e3f09b21f124b15eebf71a23c12cfa41f1e5372 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 5 Aug 2013 18:29:44 +0300 Subject: [PATCH 5/5] Fix tests --- spec/controllers/commit_controller_spec.rb | 2 +- spec/features/security/project_access_spec.rb | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/controllers/commit_controller_spec.rb b/spec/controllers/commit_controller_spec.rb index 87c54143a05..6773e84cbf5 100644 --- a/spec/controllers/commit_controller_spec.rb +++ b/spec/controllers/commit_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Projects::CommitController do let(:project) { create(:project_with_code) } let(:user) { create(:user) } - let(:commit) { project.repository.last_commit_for("master") } + let(:commit) { project.repository.commit("master") } before do sign_in(user) diff --git a/spec/features/security/project_access_spec.rb b/spec/features/security/project_access_spec.rb index 6bc04726a9d..d567fab9958 100644 --- a/spec/features/security/project_access_spec.rb +++ b/spec/features/security/project_access_spec.rb @@ -175,8 +175,8 @@ describe "Application access" do it { should be_denied_for :visitor } end - describe "GET /project_code/repository" do - subject { project_repository_path(project) } + describe "GET /project_code/branches/recent" do + subject { recent_project_branches_path(project) } it { should be_allowed_for master } it { should be_allowed_for reporter } @@ -186,7 +186,7 @@ describe "Application access" do it { should be_denied_for :visitor } end - describe "GET /project_code/repository/branches" do + describe "GET /project_code/branches" do subject { project_branches_path(project) } before do @@ -202,7 +202,7 @@ describe "Application access" do it { should be_denied_for :visitor } end - describe "GET /project_code/repository/tags" do + describe "GET /project_code/tags" do subject { project_tags_path(project) } before do @@ -417,8 +417,8 @@ describe "Application access" do it { should be_denied_for :visitor } end - describe "GET /project_code/repository" do - subject { project_repository_path(project) } + describe "GET /project_code/branches/recent" do + subject { recent_project_branches_path(project) } it { should be_allowed_for master } it { should be_allowed_for reporter } @@ -428,7 +428,7 @@ describe "Application access" do it { should be_denied_for :visitor } end - describe "GET /project_code/repository/branches" do + describe "GET /project_code/branches" do subject { project_branches_path(project) } before do @@ -444,7 +444,7 @@ describe "Application access" do it { should be_denied_for :visitor } end - describe "GET /project_code/repository/tags" do + describe "GET /project_code/tags" do subject { project_tags_path(project) } before do