Skip to content
Snippets Groups Projects
Commit 8ed7ac9d authored by Douwe Maan's avatar Douwe Maan
Browse files

Use project.commit convenience method.

parent 84a15902
No related branches found
No related tags found
No related merge requests found
Showing
with 24 additions and 24 deletions
Loading
@@ -36,6 +36,6 @@ class Projects::CommitController < Projects::ApplicationController
Loading
@@ -36,6 +36,6 @@ class Projects::CommitController < Projects::ApplicationController
end end
   
def commit def commit
@commit ||= @project.repository.commit(params[:id]) @commit ||= @project.commit(params[:id])
end end
end end
Loading
@@ -146,7 +146,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
Loading
@@ -146,7 +146,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
   
def branch_to def branch_to
@target_project = selected_target_project @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 end
   
def update_branches def update_branches
Loading
Loading
Loading
@@ -290,7 +290,7 @@ class Note < ActiveRecord::Base
Loading
@@ -290,7 +290,7 @@ class Note < ActiveRecord::Base
# +mentioner+. # +mentioner+.
def noteable_project_id(noteable, mentioning_project) def noteable_project_id(noteable, mentioning_project)
if noteable.is_a?(Commit) 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 # The noteable commit belongs to the mentioner's project
mentioning_project.id mentioning_project.id
else else
Loading
@@ -512,7 +512,7 @@ class Note < ActiveRecord::Base
Loading
@@ -512,7 +512,7 @@ class Note < ActiveRecord::Base
# override to return commits, which are not active record # override to return commits, which are not active record
def noteable def noteable
if for_commit? if for_commit?
project.repository.commit(commit_id) project.commit(commit_id)
else else
super super
end end
Loading
Loading
Loading
@@ -257,7 +257,7 @@ class Project < ActiveRecord::Base
Loading
@@ -257,7 +257,7 @@ class Project < ActiveRecord::Base
@repository ||= Repository.new(path_with_namespace, nil, self) @repository ||= Repository.new(path_with_namespace, nil, self)
end end
   
def commit(id) def commit(id = 'HEAD')
repository.commit(id) repository.commit(id)
end end
   
Loading
Loading
Loading
@@ -18,6 +18,6 @@ class ProtectedBranch < ActiveRecord::Base
Loading
@@ -18,6 +18,6 @@ class ProtectedBranch < ActiveRecord::Base
validates :project, presence: true validates :project, presence: true
   
def commit def commit
project.repository.commit(self.name) project.commit(self.name)
end end
end end
Loading
@@ -38,7 +38,7 @@ class CreateTagService < BaseService
Loading
@@ -38,7 +38,7 @@ class CreateTagService < BaseService
end end
   
def create_push_data(project, user, tag) def create_push_data(project, user, tag)
commits = [project.repository.commit(tag.target)].compact commits = [project.commit(tag.target)].compact
Gitlab::PushDataBuilder. Gitlab::PushDataBuilder.
build(project, user, Gitlab::Git::BLANK_SHA, tag.target, "#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}", commits, tag.message) build(project, user, Gitlab::Git::BLANK_SHA, tag.target, "#{Gitlab::Git::TAG_REF_PREFIX}#{tag.name}", commits, tag.message)
end end
Loading
Loading
Loading
@@ -25,7 +25,7 @@ class GitTagPushService
Loading
@@ -25,7 +25,7 @@ class GitTagPushService
tag_name = Gitlab::Git.ref_name(ref) tag_name = Gitlab::Git.ref_name(ref)
tag = project.repository.find_tag(tag_name) tag = project.repository.find_tag(tag_name)
if tag && tag.target == newrev if tag && tag.target == newrev
commit = project.repository.commit(tag.target) commit = project.commit(tag.target)
commits = [commit].compact commits = [commit].compact
message = tag.message message = tag.message
end end
Loading
Loading
Loading
@@ -22,7 +22,7 @@ module Projects
Loading
@@ -22,7 +22,7 @@ module Projects
merge_request = project.merge_requests.find_by_iid(id) merge_request = project.merge_requests.find_by_iid(id)
merge_request.participants(current_user) if merge_request merge_request.participants(current_user) if merge_request
when "Commit" when "Commit"
commit = project.repository.commit(id) commit = project.commit(id)
commit.participants(project, current_user) if commit commit.participants(project, current_user) if commit
end end
   
Loading
Loading
Loading
@@ -32,7 +32,7 @@ module API
Loading
@@ -32,7 +32,7 @@ module API
# GET /projects/:id/repository/commits/:sha # GET /projects/:id/repository/commits/:sha
get ":id/repository/commits/:sha" do get ":id/repository/commits/:sha" do
sha = params[:sha] sha = params[:sha]
commit = user_project.repository.commit(sha) commit = user_project.commit(sha)
not_found! "Commit" unless commit not_found! "Commit" unless commit
present commit, with: Entities::RepoCommitDetail present commit, with: Entities::RepoCommitDetail
end end
Loading
@@ -46,7 +46,7 @@ module API
Loading
@@ -46,7 +46,7 @@ module API
# GET /projects/:id/repository/commits/:sha/diff # GET /projects/:id/repository/commits/:sha/diff
get ":id/repository/commits/:sha/diff" do get ":id/repository/commits/:sha/diff" do
sha = params[:sha] sha = params[:sha]
commit = user_project.repository.commit(sha) commit = user_project.commit(sha)
not_found! "Commit" unless commit not_found! "Commit" unless commit
commit.diffs commit.diffs
end end
Loading
@@ -60,7 +60,7 @@ module API
Loading
@@ -60,7 +60,7 @@ module API
# GET /projects/:id/repository/commits/:sha/comments # GET /projects/:id/repository/commits/:sha/comments
get ':id/repository/commits/:sha/comments' do get ':id/repository/commits/:sha/comments' do
sha = params[:sha] sha = params[:sha]
commit = user_project.repository.commit(sha) commit = user_project.commit(sha)
not_found! 'Commit' unless commit not_found! 'Commit' unless commit
notes = Note.where(commit_id: commit.id) notes = Note.where(commit_id: commit.id)
present paginate(notes), with: Entities::CommitNote present paginate(notes), with: Entities::CommitNote
Loading
@@ -81,7 +81,7 @@ module API
Loading
@@ -81,7 +81,7 @@ module API
required_attributes! [:note] required_attributes! [:note]
   
sha = params[:sha] sha = params[:sha]
commit = user_project.repository.commit(sha) commit = user_project.commit(sha)
not_found! 'Commit' unless commit not_found! 'Commit' unless commit
opts = { opts = {
note: params[:note], note: params[:note],
Loading
Loading
Loading
@@ -34,7 +34,7 @@ module API
Loading
@@ -34,7 +34,7 @@ module API
ref = attrs.delete(:ref) ref = attrs.delete(:ref)
file_path = attrs.delete(:file_path) file_path = attrs.delete(:file_path)
   
commit = user_project.repository.commit(ref) commit = user_project.commit(ref)
not_found! 'Commit' unless commit not_found! 'Commit' unless commit
   
blob = user_project.repository.blob_at(commit.sha, file_path) blob = user_project.repository.blob_at(commit.sha, file_path)
Loading
Loading
Loading
@@ -62,7 +62,7 @@ module API
Loading
@@ -62,7 +62,7 @@ module API
ref = params[:ref_name] || user_project.try(:default_branch) || 'master' ref = params[:ref_name] || user_project.try(:default_branch) || 'master'
path = params[:path] || nil path = params[:path] || nil
   
commit = user_project.repository.commit(ref) commit = user_project.commit(ref)
not_found!('Tree') unless commit not_found!('Tree') unless commit
   
tree = user_project.repository.tree(commit.id, path) tree = user_project.repository.tree(commit.id, path)
Loading
Loading
Loading
@@ -5,7 +5,7 @@ module Gitlab
Loading
@@ -5,7 +5,7 @@ module Gitlab
def identify(identifier, project, newrev) def identify(identifier, project, newrev)
if identifier.blank? if identifier.blank?
# Local push from gitlab # 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 User.find_by(email: email) if email
   
elsif identifier =~ /\Auser-\d+\Z/ elsif identifier =~ /\Auser-\d+\Z/
Loading
Loading
Loading
@@ -84,7 +84,7 @@ module Gitlab
Loading
@@ -84,7 +84,7 @@ module Gitlab
   
def commit(id) def commit(id)
unless @commit_map[id] unless @commit_map[id]
@commit_map[id] = project.repository.commit(id) @commit_map[id] = project.commit(id)
end end
   
@commit_map[id] @commit_map[id]
Loading
Loading
Loading
@@ -66,7 +66,7 @@ module Gitlab
Loading
@@ -66,7 +66,7 @@ module Gitlab
   
def commit_from_ref(project, commit_ref) def commit_from_ref(project, commit_ref)
if project && project.valid_repo? if project && project.valid_repo?
project.repository.commit(commit_ref) project.commit(commit_ref)
end end
end end
   
Loading
Loading
Loading
@@ -69,7 +69,7 @@ module Gitlab
Loading
@@ -69,7 +69,7 @@ module Gitlab
   
def build_data_for_commit(project, user, note) def build_data_for_commit(project, user, note)
# commit_id is the SHA hash # commit_id is the SHA hash
commit = project.repository.commit(note.commit_id) commit = project.commit(note.commit_id)
commit.hook_attrs(project) commit.hook_attrs(project)
end end
end end
Loading
Loading
Loading
@@ -3,7 +3,7 @@ require 'spec_helper'
Loading
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Projects::CommitController do describe Projects::CommitController do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:commit) { project.repository.commit("master") } let(:commit) { project.commit("master") }
   
before do before do
sign_in(user) sign_in(user)
Loading
Loading
Loading
@@ -14,7 +14,7 @@ describe "GitLab Flavored Markdown", feature: true do
Loading
@@ -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") Commit.any_instance.stub(title: "fix ##{issue.iid}\n\nask @#{fred.username} for details")
end end
   
let(:commit) { project.repository.commit } let(:commit) { project.commit }
   
before do before do
login_as :user login_as :user
Loading
Loading
Loading
@@ -4,7 +4,7 @@ describe DiffHelper do
Loading
@@ -4,7 +4,7 @@ describe DiffHelper do
include RepoHelpers include RepoHelpers
   
let(:project) { create(:project) } 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) { commit.diffs.first }
let(:diff_file) { Gitlab::Diff::File.new(diff) } let(:diff_file) { Gitlab::Diff::File.new(diff) }
   
Loading
Loading
Loading
@@ -6,7 +6,7 @@ describe GitlabMarkdownHelper do
Loading
@@ -6,7 +6,7 @@ describe GitlabMarkdownHelper do
let!(:project) { create(:project) } let!(:project) { create(:project) }
   
let(:user) { create(:user, username: 'gfm') } let(:user) { create(:user, username: 'gfm') }
let(:commit) { project.repository.commit } let(:commit) { project.commit }
let(:issue) { create(:issue, project: project) } let(:issue) { create(:issue, project: project) }
let(:merge_request) { create(:merge_request, source_project: project, target_project: project) } let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let(:snippet) { create(:project_snippet, project: project) } let(:snippet) { create(:project_snippet, project: project) }
Loading
Loading
Loading
@@ -6,7 +6,7 @@ describe TreeHelper do
Loading
@@ -6,7 +6,7 @@ describe TreeHelper do
   
before { before {
@repository = project.repository @repository = project.repository
@commit = project.repository.commit("e56497bb") @commit = project.commit("e56497bb")
} }
   
context "on a directory containing more than one file/directory" do context "on a directory containing more than one file/directory" do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment