summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-21 15:13:40 +0200
committerDouwe Maan <douwe@gitlab.com>2015-04-24 12:29:36 +0200
commit8ed7ac9d443563a62a6aa03a2ec72b9fcb0d2df1 (patch)
treeb787add194486ac4346c2de2874b32db6d37c635
parent84a1590252c63c710bceaa7a394799cdc5109505 (diff)
downloadgitlab-ce-8ed7ac9d443563a62a6aa03a2ec72b9fcb0d2df1.tar.gz
Use project.commit convenience method.
-rw-r--r--app/controllers/projects/commit_controller.rb2
-rw-r--r--app/controllers/projects/merge_requests_controller.rb2
-rw-r--r--app/models/note.rb4
-rw-r--r--app/models/project.rb2
-rw-r--r--app/models/protected_branch.rb2
-rw-r--r--app/services/create_tag_service.rb2
-rw-r--r--app/services/git_tag_push_service.rb2
-rw-r--r--app/services/projects/participants_service.rb2
-rw-r--r--lib/api/commits.rb8
-rw-r--r--lib/api/files.rb2
-rw-r--r--lib/api/repositories.rb2
-rw-r--r--lib/gitlab/identifier.rb2
-rw-r--r--lib/gitlab/markdown/commit_range_reference_filter.rb2
-rw-r--r--lib/gitlab/markdown/commit_reference_filter.rb2
-rw-r--r--lib/gitlab/note_data_builder.rb2
-rw-r--r--spec/controllers/commit_controller_spec.rb2
-rw-r--r--spec/features/gitlab_flavored_markdown_spec.rb2
-rw-r--r--spec/helpers/diff_helper_spec.rb2
-rw-r--r--spec/helpers/gitlab_markdown_helper_spec.rb2
-rw-r--r--spec/helpers/tree_helper_spec.rb2
-rw-r--r--spec/lib/gitlab/diff/file_spec.rb2
-rw-r--r--spec/lib/gitlab/diff/parser_spec.rb2
-rw-r--r--spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb8
-rw-r--r--spec/lib/gitlab/markdown/commit_reference_filter_spec.rb4
-rw-r--r--spec/lib/gitlab/reference_extractor_spec.rb6
-rw-r--r--spec/mailers/notify_spec.rb2
-rw-r--r--spec/models/commit_spec.rb2
-rw-r--r--spec/models/note_spec.rb6
-rw-r--r--spec/services/git_push_service_spec.rb6
-rw-r--r--spec/services/git_tag_push_service_spec.rb2
30 files changed, 44 insertions, 44 deletions
diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb
index 8a1b7899be3..35df421e09d 100644
--- a/app/controllers/projects/commit_controller.rb
+++ b/app/controllers/projects/commit_controller.rb
@@ -36,6 +36,6 @@ class Projects::CommitController < Projects::ApplicationController
end
def commit
- @commit ||= @project.repository.commit(params[:id])
+ @commit ||= @project.commit(params[:id])
end
end
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index ab75f2ddb73..41b4e55a598 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -146,7 +146,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def branch_to
@target_project = selected_target_project
- @commit = @target_project.repository.commit(params[:ref]) if params[:ref].present?
+ @commit = @target_project.commit(params[:ref]) if params[:ref].present?
end
def update_branches
diff --git a/app/models/note.rb b/app/models/note.rb
index e3c571a1574..99e86ac0250 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -290,7 +290,7 @@ class Note < ActiveRecord::Base
# +mentioner+.
def noteable_project_id(noteable, mentioning_project)
if noteable.is_a?(Commit)
- if mentioning_project.repository.commit(noteable.id)
+ if mentioning_project.commit(noteable.id)
# The noteable commit belongs to the mentioner's project
mentioning_project.id
else
@@ -512,7 +512,7 @@ class Note < ActiveRecord::Base
# override to return commits, which are not active record
def noteable
if for_commit?
- project.repository.commit(commit_id)
+ project.commit(commit_id)
else
super
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 4c1404ee9f8..293ee04f228 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -257,7 +257,7 @@ class Project < ActiveRecord::Base
@repository ||= Repository.new(path_with_namespace, nil, self)
end
- def commit(id)
+ def commit(id = 'HEAD')
repository.commit(id)
end
diff --git a/app/models/protected_branch.rb b/app/models/protected_branch.rb
index 97207ba1272..8ebd790a89e 100644
--- a/app/models/protected_branch.rb
+++ b/app/models/protected_branch.rb
@@ -18,6 +18,6 @@ class ProtectedBranch < ActiveRecord::Base
validates :project, presence: true
def commit
- project.repository.commit(self.name)
+ project.commit(self.name)
end
end
diff --git a/app/services/create_tag_service.rb b/app/services/create_tag_service.rb
index 25f9e203246..1a7318048b3 100644
--- a/app/services/create_tag_service.rb
+++ b/app/services/create_tag_service.rb
@@ -38,7 +38,7 @@ class CreateTagService < BaseService
end
def create_push_data(project, user, tag)
- commits = [project.repository.commit(tag.target)].compact
+ commits = [project.commit(tag.target)].compact
Gitlab::PushDataBuilder.
build(project, user, Gitlab::Git::BLANK_SHA, tag.target, "#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}", commits, tag.message)
end
diff --git a/app/services/git_tag_push_service.rb b/app/services/git_tag_push_service.rb
index bf203bbd692..075a6118da2 100644
--- a/app/services/git_tag_push_service.rb
+++ b/app/services/git_tag_push_service.rb
@@ -25,7 +25,7 @@ class GitTagPushService
tag_name = Gitlab::Git.ref_name(ref)
tag = project.repository.find_tag(tag_name)
if tag && tag.target == newrev
- commit = project.repository.commit(tag.target)
+ commit = project.commit(tag.target)
commits = [commit].compact
message = tag.message
end
diff --git a/app/services/projects/participants_service.rb b/app/services/projects/participants_service.rb
index c2d8f48f6e4..05106fa7898 100644
--- a/app/services/projects/participants_service.rb
+++ b/app/services/projects/participants_service.rb
@@ -22,7 +22,7 @@ module Projects
merge_request = project.merge_requests.find_by_iid(id)
merge_request.participants(current_user) if merge_request
when "Commit"
- commit = project.repository.commit(id)
+ commit = project.commit(id)
commit.participants(project, current_user) if commit
end
diff --git a/lib/api/commits.rb b/lib/api/commits.rb
index 0de4e720ffe..23270b1c0f4 100644
--- a/lib/api/commits.rb
+++ b/lib/api/commits.rb
@@ -32,7 +32,7 @@ module API
# GET /projects/:id/repository/commits/:sha
get ":id/repository/commits/:sha" do
sha = params[:sha]
- commit = user_project.repository.commit(sha)
+ commit = user_project.commit(sha)
not_found! "Commit" unless commit
present commit, with: Entities::RepoCommitDetail
end
@@ -46,7 +46,7 @@ module API
# GET /projects/:id/repository/commits/:sha/diff
get ":id/repository/commits/:sha/diff" do
sha = params[:sha]
- commit = user_project.repository.commit(sha)
+ commit = user_project.commit(sha)
not_found! "Commit" unless commit
commit.diffs
end
@@ -60,7 +60,7 @@ module API
# GET /projects/:id/repository/commits/:sha/comments
get ':id/repository/commits/:sha/comments' do
sha = params[:sha]
- commit = user_project.repository.commit(sha)
+ commit = user_project.commit(sha)
not_found! 'Commit' unless commit
notes = Note.where(commit_id: commit.id)
present paginate(notes), with: Entities::CommitNote
@@ -81,7 +81,7 @@ module API
required_attributes! [:note]
sha = params[:sha]
- commit = user_project.repository.commit(sha)
+ commit = user_project.commit(sha)
not_found! 'Commit' unless commit
opts = {
note: params[:note],
diff --git a/lib/api/files.rb b/lib/api/files.rb
index 3176ef0e256..e0ea6d7dd1d 100644
--- a/lib/api/files.rb
+++ b/lib/api/files.rb
@@ -34,7 +34,7 @@ module API
ref = attrs.delete(:ref)
file_path = attrs.delete(:file_path)
- commit = user_project.repository.commit(ref)
+ commit = user_project.commit(ref)
not_found! 'Commit' unless commit
blob = user_project.repository.blob_at(commit.sha, file_path)
diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb
index 1fbf3dca3c6..2d96c9666d2 100644
--- a/lib/api/repositories.rb
+++ b/lib/api/repositories.rb
@@ -62,7 +62,7 @@ module API
ref = params[:ref_name] || user_project.try(:default_branch) || 'master'
path = params[:path] || nil
- commit = user_project.repository.commit(ref)
+ commit = user_project.commit(ref)
not_found!('Tree') unless commit
tree = user_project.repository.tree(commit.id, path)
diff --git a/lib/gitlab/identifier.rb b/lib/gitlab/identifier.rb
index 6e4de197eeb..3e5d728f3bc 100644
--- a/lib/gitlab/identifier.rb
+++ b/lib/gitlab/identifier.rb
@@ -5,7 +5,7 @@ module Gitlab
def identify(identifier, project, newrev)
if identifier.blank?
# Local push from gitlab
- email = project.repository.commit(newrev).author_email rescue nil
+ email = project.commit(newrev).author_email rescue nil
User.find_by(email: email) if email
elsif identifier =~ /\Auser-\d+\Z/
diff --git a/lib/gitlab/markdown/commit_range_reference_filter.rb b/lib/gitlab/markdown/commit_range_reference_filter.rb
index 1128c1bed7a..baa97bee9bf 100644
--- a/lib/gitlab/markdown/commit_range_reference_filter.rb
+++ b/lib/gitlab/markdown/commit_range_reference_filter.rb
@@ -84,7 +84,7 @@ module Gitlab
def commit(id)
unless @commit_map[id]
- @commit_map[id] = project.repository.commit(id)
+ @commit_map[id] = project.commit(id)
end
@commit_map[id]
diff --git a/lib/gitlab/markdown/commit_reference_filter.rb b/lib/gitlab/markdown/commit_reference_filter.rb
index 745de6402cf..66598127f6e 100644
--- a/lib/gitlab/markdown/commit_reference_filter.rb
+++ b/lib/gitlab/markdown/commit_reference_filter.rb
@@ -66,7 +66,7 @@ module Gitlab
def commit_from_ref(project, commit_ref)
if project && project.valid_repo?
- project.repository.commit(commit_ref)
+ project.commit(commit_ref)
end
end
diff --git a/lib/gitlab/note_data_builder.rb b/lib/gitlab/note_data_builder.rb
index 644dec45dca..0f2abd1b49c 100644
--- a/lib/gitlab/note_data_builder.rb
+++ b/lib/gitlab/note_data_builder.rb
@@ -69,7 +69,7 @@ module Gitlab
def build_data_for_commit(project, user, note)
# commit_id is the SHA hash
- commit = project.repository.commit(note.commit_id)
+ commit = project.commit(note.commit_id)
commit.hook_attrs(project)
end
end
diff --git a/spec/controllers/commit_controller_spec.rb b/spec/controllers/commit_controller_spec.rb
index 3394a1f863f..2cfa399a047 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) }
let(:user) { create(:user) }
- let(:commit) { project.repository.commit("master") }
+ let(:commit) { project.commit("master") }
before do
sign_in(user)
diff --git a/spec/features/gitlab_flavored_markdown_spec.rb b/spec/features/gitlab_flavored_markdown_spec.rb
index fca1a06eb88..133beba7b98 100644
--- a/spec/features/gitlab_flavored_markdown_spec.rb
+++ b/spec/features/gitlab_flavored_markdown_spec.rb
@@ -14,7 +14,7 @@ describe "GitLab Flavored Markdown", feature: true do
Commit.any_instance.stub(title: "fix ##{issue.iid}\n\nask @#{fred.username} for details")
end
- let(:commit) { project.repository.commit }
+ let(:commit) { project.commit }
before do
login_as :user
diff --git a/spec/helpers/diff_helper_spec.rb b/spec/helpers/diff_helper_spec.rb
index 5bd09793b11..95719b4b49f 100644
--- a/spec/helpers/diff_helper_spec.rb
+++ b/spec/helpers/diff_helper_spec.rb
@@ -4,7 +4,7 @@ describe DiffHelper do
include RepoHelpers
let(:project) { create(:project) }
- let(:commit) { project.repository.commit(sample_commit.id) }
+ let(:commit) { project.commit(sample_commit.id) }
let(:diff) { commit.diffs.first }
let(:diff_file) { Gitlab::Diff::File.new(diff) }
diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb
index 64f130e4ae4..e309dbb6a2f 100644
--- a/spec/helpers/gitlab_markdown_helper_spec.rb
+++ b/spec/helpers/gitlab_markdown_helper_spec.rb
@@ -6,7 +6,7 @@ describe GitlabMarkdownHelper do
let!(:project) { create(:project) }
let(:user) { create(:user, username: 'gfm') }
- let(:commit) { project.repository.commit }
+ let(:commit) { project.commit }
let(:issue) { create(:issue, project: project) }
let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let(:snippet) { create(:project_snippet, project: project) }
diff --git a/spec/helpers/tree_helper_spec.rb b/spec/helpers/tree_helper_spec.rb
index 8271e00f41b..2013b3e4c2a 100644
--- a/spec/helpers/tree_helper_spec.rb
+++ b/spec/helpers/tree_helper_spec.rb
@@ -6,7 +6,7 @@ describe TreeHelper do
before {
@repository = project.repository
- @commit = project.repository.commit("e56497bb")
+ @commit = project.commit("e56497bb")
}
context "on a directory containing more than one file/directory" do
diff --git a/spec/lib/gitlab/diff/file_spec.rb b/spec/lib/gitlab/diff/file_spec.rb
index 40eb45e37ca..8b7946f3117 100644
--- a/spec/lib/gitlab/diff/file_spec.rb
+++ b/spec/lib/gitlab/diff/file_spec.rb
@@ -4,7 +4,7 @@ describe Gitlab::Diff::File do
include RepoHelpers
let(:project) { create(:project) }
- let(:commit) { project.repository.commit(sample_commit.id) }
+ let(:commit) { project.commit(sample_commit.id) }
let(:diff) { commit.diffs.first }
let(:diff_file) { Gitlab::Diff::File.new(diff) }
diff --git a/spec/lib/gitlab/diff/parser_spec.rb b/spec/lib/gitlab/diff/parser_spec.rb
index 918f6d0ead4..4d5d1431683 100644
--- a/spec/lib/gitlab/diff/parser_spec.rb
+++ b/spec/lib/gitlab/diff/parser_spec.rb
@@ -4,7 +4,7 @@ describe Gitlab::Diff::Parser do
include RepoHelpers
let(:project) { create(:project) }
- let(:commit) { project.repository.commit(sample_commit.id) }
+ let(:commit) { project.commit(sample_commit.id) }
let(:diff) { commit.diffs.first }
let(:parser) { Gitlab::Diff::Parser.new }
diff --git a/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb b/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
index 5ebdc8926e2..f0804ce0056 100644
--- a/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
@@ -5,8 +5,8 @@ module Gitlab::Markdown
include ReferenceFilterSpecHelper
let(:project) { create(:project) }
- let(:commit1) { project.repository.commit }
- let(:commit2) { project.repository.commit("HEAD~2") }
+ let(:commit1) { project.commit }
+ let(:commit2) { project.commit("HEAD~2") }
it 'requires project context' do
expect { described_class.call('Commit Range 1c002d..d200c1', {}) }.
@@ -86,8 +86,8 @@ module Gitlab::Markdown
context 'cross-project reference' do
let(:namespace) { create(:namespace, name: 'cross-reference') }
let(:project2) { create(:project, namespace: namespace) }
- let(:commit1) { project.repository.commit }
- let(:commit2) { project.repository.commit("HEAD~2") }
+ let(:commit1) { project.commit }
+ let(:commit2) { project.commit("HEAD~2") }
let(:reference) { "#{project2.path_with_namespace}@#{commit1.id}...#{commit2.id}" }
context 'when user can access reference' do
diff --git a/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb b/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
index 71fd2db2c58..f792d7f696e 100644
--- a/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
@@ -5,7 +5,7 @@ module Gitlab::Markdown
include ReferenceFilterSpecHelper
let(:project) { create(:project) }
- let(:commit) { project.repository.commit }
+ let(:commit) { project.commit }
it 'requires project context' do
expect { described_class.call('Commit 1c002d', {}) }.
@@ -80,7 +80,7 @@ module Gitlab::Markdown
context 'cross-project reference' do
let(:namespace) { create(:namespace, name: 'cross-reference') }
let(:project2) { create(:project, namespace: namespace) }
- let(:commit) { project.repository.commit }
+ let(:commit) { project.commit }
let(:reference) { "#{project2.path_with_namespace}@#{commit.id}" }
context 'when user can access reference' do
diff --git a/spec/lib/gitlab/reference_extractor_spec.rb b/spec/lib/gitlab/reference_extractor_spec.rb
index 6fba140f69d..0f4ea2a24ed 100644
--- a/spec/lib/gitlab/reference_extractor_spec.rb
+++ b/spec/lib/gitlab/reference_extractor_spec.rb
@@ -125,7 +125,7 @@ describe Gitlab::ReferenceExtractor do
end
it 'accesses valid commits' do
- commit = project.repository.commit('master')
+ commit = project.commit('master')
subject.analyze("this references commits #{commit.sha[0..6]} and 012345")
extracted = subject.commits
@@ -135,8 +135,8 @@ describe Gitlab::ReferenceExtractor do
end
it 'accesses valid commit ranges' do
- commit = project.repository.commit('master')
- earlier_commit = project.repository.commit('master~2')
+ commit = project.commit('master')
+ earlier_commit = project.commit('master~2')
subject.analyze("this references commits #{earlier_commit.sha[0..6]}...#{commit.sha[0..6]}")
extracted = subject.commit_ranges
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb
index 6f7f5835b94..d28b4768545 100644
--- a/spec/mailers/notify_spec.rb
+++ b/spec/mailers/notify_spec.rb
@@ -466,7 +466,7 @@ describe Notify do
end
describe 'on a commit' do
- let(:commit) { project.repository.commit }
+ let(:commit) { project.commit }
before(:each) { allow(note).to receive(:noteable).and_return(commit) }
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index 506bc3339b6..9c37c036eae 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
describe Commit do
let(:project) { create :project }
- let(:commit) { project.repository.commit }
+ let(:commit) { project.commit }
describe '#title' do
it "returns no_commit_message when safe_message is blank" do
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index e7e6717e775..095eb1500a9 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -329,7 +329,7 @@ describe Note do
let(:author) { create(:user) }
let(:issue) { create(:issue, project: project) }
let(:mergereq) { create(:merge_request, :simple, target_project: project, source_project: project) }
- let(:commit) { project.repository.commit }
+ let(:commit) { project.commit }
# Test all of {issue, merge request, commit} in both the referenced and referencing
# roles, to ensure that the correct information can be inferred from any argument.
@@ -482,8 +482,8 @@ describe Note do
let(:project) { create :project }
let(:author) { create :user }
let(:issue) { create :issue }
- let(:commit0) { project.repository.commit }
- let(:commit1) { project.repository.commit('HEAD~2') }
+ let(:commit0) { project.commit }
+ let(:commit1) { project.commit('HEAD~2') }
before do
Note.create_cross_reference_note(issue, commit0, author, project)
diff --git a/spec/services/git_push_service_spec.rb b/spec/services/git_push_service_spec.rb
index aa9b15dd9ec..246bc1cc33d 100644
--- a/spec/services/git_push_service_spec.rb
+++ b/spec/services/git_push_service_spec.rb
@@ -44,7 +44,7 @@ describe GitPushService do
before do
service.execute(project, user, @oldrev, @newrev, @ref)
@push_data = service.push_data
- @commit = project.repository.commit(@newrev)
+ @commit = project.commit(@newrev)
end
subject { @push_data }
@@ -151,7 +151,7 @@ describe GitPushService do
describe "cross-reference notes" do
let(:issue) { create :issue, project: project }
let(:commit_author) { create :user }
- let(:commit) { project.repository.commit }
+ let(:commit) { project.commit }
before do
commit.stub({
@@ -198,7 +198,7 @@ describe GitPushService do
let(:issue) { create :issue, project: project }
let(:other_issue) { create :issue, project: project }
let(:commit_author) { create :user }
- let(:closing_commit) { project.repository.commit }
+ let(:closing_commit) { project.commit }
before do
closing_commit.stub({
diff --git a/spec/services/git_tag_push_service_spec.rb b/spec/services/git_tag_push_service_spec.rb
index a050fdf6c0e..76f69b396e0 100644
--- a/spec/services/git_tag_push_service_spec.rb
+++ b/spec/services/git_tag_push_service_spec.rb
@@ -19,7 +19,7 @@ describe GitTagPushService do
@push_data = service.push_data
@tag_name = Gitlab::Git.ref_name(@ref)
@tag = project.repository.find_tag(@tag_name)
- @commit = project.repository.commit(@tag.target)
+ @commit = project.commit(@tag.target)
end
subject { @push_data }