Commit d521cf8d authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

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

parents 5b28bf1e 1e3f09b2
...@@ -23,7 +23,7 @@ gem 'omniauth-github' ...@@ -23,7 +23,7 @@ gem 'omniauth-github'
# Extracting information from a git repository # Extracting information from a git repository
# Provide access to Gitlab::Git library # Provide access to Gitlab::Git library
gem 'gitlab_git', '~> 1.4.1' gem "gitlab_git", "~> 2.0.0.pre"
# Ruby/Rack Git Smart-HTTP Server Handler # Ruby/Rack Git Smart-HTTP Server Handler
gem 'gitlab-grack', '~> 1.0.1', require: 'grack' gem 'gitlab-grack', '~> 1.0.1', require: 'grack'
......
...@@ -176,7 +176,7 @@ GEM ...@@ -176,7 +176,7 @@ GEM
gitlab-pygments.rb (0.3.2) gitlab-pygments.rb (0.3.2)
posix-spawn (~> 0.3.6) posix-spawn (~> 0.3.6)
yajl-ruby (~> 1.1.0) yajl-ruby (~> 1.1.0)
gitlab_git (1.4.1) gitlab_git (2.0.0.pre)
activesupport (~> 3.2.13) activesupport (~> 3.2.13)
github-linguist (~> 2.3.4) github-linguist (~> 2.3.4)
gitlab-grit (~> 2.6.0) gitlab-grit (~> 2.6.0)
...@@ -275,7 +275,7 @@ GEM ...@@ -275,7 +275,7 @@ GEM
minitest (4.7.4) minitest (4.7.4)
modernizr (2.6.2) modernizr (2.6.2)
sprockets (~> 2.0) sprockets (~> 2.0)
multi_json (1.7.7) multi_json (1.7.8)
multi_xml (0.5.4) multi_xml (0.5.4)
multipart-post (1.2.0) multipart-post (1.2.0)
mysql2 (0.3.11) mysql2 (0.3.11)
...@@ -568,7 +568,7 @@ DEPENDENCIES ...@@ -568,7 +568,7 @@ DEPENDENCIES
gitlab-gollum-lib (~> 1.0.1) gitlab-gollum-lib (~> 1.0.1)
gitlab-grack (~> 1.0.1) gitlab-grack (~> 1.0.1)
gitlab-pygments.rb (~> 0.3.2) gitlab-pygments.rb (~> 0.3.2)
gitlab_git (~> 1.4.1) gitlab_git (~> 2.0.0.pre)
gitlab_meta (= 6.0) gitlab_meta (= 6.0)
gitlab_omniauth-ldap (= 1.0.3) gitlab_omniauth-ldap (= 1.0.3)
gon gon
......
...@@ -11,6 +11,10 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -11,6 +11,10 @@ class Projects::BranchesController < Projects::ApplicationController
@branches = Kaminari.paginate_array(@repository.branches).page(params[:page]).per(30) @branches = Kaminari.paginate_array(@repository.branches).page(params[:page]).per(30)
end end
def recent
@branches = @repository.recent_branches
end
def create def create
@repository.add_branch(params[:branch_name], params[:ref]) @repository.add_branch(params[:branch_name], params[:ref])
......
...@@ -10,7 +10,7 @@ class Projects::EditTreeController < Projects::ApplicationController ...@@ -10,7 +10,7 @@ class Projects::EditTreeController < Projects::ApplicationController
before_filter :edit_requirements, only: [:show, :update] before_filter :edit_requirements, only: [:show, :update]
def show 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 end
def update def update
......
...@@ -4,10 +4,6 @@ class Projects::RepositoriesController < Projects::ApplicationController ...@@ -4,10 +4,6 @@ class Projects::RepositoriesController < Projects::ApplicationController
before_filter :authorize_code_access! before_filter :authorize_code_access!
before_filter :require_non_empty_project before_filter :require_non_empty_project
def show
@activities = @repository.commits_with_refs(20)
end
def stats def stats
@stats = Gitlab::Git::Stats.new(@repository.raw, @repository.root_ref) @stats = Gitlab::Git::Stats.new(@repository.raw, @repository.root_ref)
@graph = @stats.graph @graph = @stats.graph
......
...@@ -137,7 +137,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -137,7 +137,7 @@ class MergeRequest < ActiveRecord::Base
end end
def unmerged_diffs def unmerged_diffs
project.repository.diffs_between(source_branch, target_branch) Gitlab::Git::Diff.between(project.repository, source_branch, target_branch)
end end
def last_commit def last_commit
......
...@@ -18,19 +18,25 @@ class Repository ...@@ -18,19 +18,25 @@ class Repository
end end
def commit(id = nil) def commit(id = nil)
commit = raw_repository.commit(id) commit = Gitlab::Git::Commit.find(raw_repository, id)
commit = Commit.new(commit) if commit commit = Commit.new(commit) if commit
commit commit
end end
def commits(ref, path = nil, limit = nil, offset = nil) 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 = Commit.decorate(commits) if commits.present?
commits commits
end end
def commits_between(target, source) def commits_between(from, to)
commits = raw_repository.commits_between(target, source) commits = Gitlab::Git::Commit.between(raw_repository, from, to)
commits = Commit.decorate(commits) if commits.present? commits = Commit.decorate(commits) if commits.present?
commits commits
end end
...@@ -43,6 +49,12 @@ class Repository ...@@ -43,6 +49,12 @@ class Repository
tags.find { |tag| tag.name == name } tags.find { |tag| tag.name == name }
end 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) def add_branch(branch_name, ref)
Rails.cache.delete(cache_key(:branch_names)) Rails.cache.delete(cache_key(:branch_names))
......
%ul.nav.nav-pills.nav-stacked %ul.nav.nav-pills.nav-stacked
= nav_link(path: 'repositories#show') do = nav_link(path: 'branches#recent') do
= link_to 'Recent', project_repository_path(@project) = link_to 'Recent', recent_project_branches_path(@project)
= nav_link(path: 'protected_branches#index') do = nav_link(path: 'protected_branches#index') do
= link_to project_protected_branches_path(@project) do = link_to project_protected_branches_path(@project) do
Protected Protected
......
= render "projects/commits/head" = render "projects/commits/head"
.row .row
.span3 .span3
= render "projects/repositories/filter" = render "filter"
.span9 .span9
- unless @branches.empty? - unless @branches.empty?
%ul.bordered-list %ul.bordered-list
......
...@@ -4,6 +4,5 @@ ...@@ -4,6 +4,5 @@
= render "filter" = render "filter"
.span9 .span9
%ul.bordered-list %ul.bordered-list
- @activities.each do |update| - @branches.each do |branch|
= render "projects/branches/branch", branch: update.head = render "projects/branches/branch", branch: branch
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
= link_to 'Compare', project_compare_index_path(@project) = link_to 'Compare', project_compare_index_path(@project)
= nav_link(html_options: {class: branches_tab_class}) do = 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 Branches
%span.badge= @repository.branches.length %span.badge= @repository.branches.length
......
= render "projects/commits/head" = render "projects/commits/head"
.row .row
.span3 .span3
= render "projects/repositories/filter" = render "projects/branches/filter"
.span9 .span9
.alert.alert-info .alert.alert-info
%p Protected branches designed to prevent push for all except #{link_to "masters", help_permissions_path, class: "vlink"}. %p Protected branches designed to prevent push for all except #{link_to "masters", help_permissions_path, class: "vlink"}.
......
...@@ -225,8 +225,13 @@ Gitlab::Application.routes.draw do ...@@ -225,8 +225,13 @@ Gitlab::Application.routes.draw do
end end
end end
resources :branches, only: [:index, :new, :create, :destroy] do
collection do
get :recent
end
end
resources :tags, only: [:index, :new, :create, :destroy] resources :tags, only: [:index, :new, :create, :destroy]
resources :branches, only: [:index, :new, :create, :destroy]
resources :protected_branches, only: [:index, :create, :destroy] resources :protected_branches, only: [:index, :create, :destroy]
resources :refs, only: [] do resources :refs, only: [] do
......
...@@ -95,13 +95,9 @@ module ExtractsPath ...@@ -95,13 +95,9 @@ module ExtractsPath
# resolved (e.g., when a user inserts an invalid path or ref). # resolved (e.g., when a user inserts an invalid path or ref).
def assign_ref_vars def assign_ref_vars
@id = get_id @id = get_id
@ref, @path = extract_ref(@id) @ref, @path = extract_ref(@id)
@repo = @project.repository @repo = @project.repository
@commit = @repo.commit(@ref) @commit = @repo.commit(@ref)
@tree = Tree.new(@repo, @commit.id, @ref, @path) @tree = Tree.new(@repo, @commit.id, @ref, @path)
@hex_path = Digest::SHA1.hexdigest(@path) @hex_path = Digest::SHA1.hexdigest(@path)
@logs_path = logs_file_project_ref_path(@project, @ref, @path) @logs_path = logs_file_project_ref_path(@project, @ref, @path)
......
...@@ -49,7 +49,7 @@ module Gitlab ...@@ -49,7 +49,7 @@ module Gitlab
protected protected
def can_edit?(last_commit) 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 last_commit == current_last_commit
end end
end end
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe Projects::CommitController do describe Projects::CommitController do
let(:project) { create(:project_with_code) } let(:project) { create(:project_with_code) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:commit) { project.repository.last_commit_for("master") } let(:commit) { project.repository.commit("master") }
before do before do
sign_in(user) sign_in(user)
......
...@@ -175,8 +175,8 @@ describe "Application access" do ...@@ -175,8 +175,8 @@ describe "Application access" do
it { should be_denied_for :visitor } it { should be_denied_for :visitor }
end end
describe "GET /project_code/repository" do describe "GET /project_code/branches/recent" do
subject { project_repository_path(project) } subject { recent_project_branches_path(project) }
it { should be_allowed_for master } it { should be_allowed_for master }
it { should be_allowed_for reporter } it { should be_allowed_for reporter }
...@@ -186,7 +186,7 @@ describe "Application access" do ...@@ -186,7 +186,7 @@ describe "Application access" do
it { should be_denied_for :visitor } it { should be_denied_for :visitor }
end end
describe "GET /project_code/repository/branches" do describe "GET /project_code/branches" do
subject { project_branches_path(project) } subject { project_branches_path(project) }
before do before do
...@@ -202,7 +202,7 @@ describe "Application access" do ...@@ -202,7 +202,7 @@ describe "Application access" do
it { should be_denied_for :visitor } it { should be_denied_for :visitor }
end end
describe "GET /project_code/repository/tags" do describe "GET /project_code/tags" do
subject { project_tags_path(project) } subject { project_tags_path(project) }
before do before do
...@@ -417,8 +417,8 @@ describe "Application access" do ...@@ -417,8 +417,8 @@ describe "Application access" do
it { should be_denied_for :visitor } it { should be_denied_for :visitor }
end end
describe "GET /project_code/repository" do describe "GET /project_code/branches/recent" do
subject { project_repository_path(project) } subject { recent_project_branches_path(project) }
it { should be_allowed_for master } it { should be_allowed_for master }
it { should be_allowed_for reporter } it { should be_allowed_for reporter }
...@@ -428,7 +428,7 @@ describe "Application access" do ...@@ -428,7 +428,7 @@ describe "Application access" do
it { should be_denied_for :visitor } it { should be_denied_for :visitor }
end end
describe "GET /project_code/repository/branches" do describe "GET /project_code/branches" do
subject { project_branches_path(project) } subject { project_branches_path(project) }
before do before do
...@@ -444,7 +444,7 @@ describe "Application access" do ...@@ -444,7 +444,7 @@ describe "Application access" do
it { should be_denied_for :visitor } it { should be_denied_for :visitor }
end end
describe "GET /project_code/repository/tags" do describe "GET /project_code/tags" do
subject { project_tags_path(project) } subject { project_tags_path(project) }
before do before do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment