Faster branch contains detection for commit
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
2ebd2d41a5
commit
88b1e0ffcd
3 changed files with 33 additions and 7 deletions
|
@ -12,13 +12,7 @@ class Projects::CommitController < Projects::ApplicationController
|
|||
return git_not_found! unless @commit
|
||||
|
||||
@line_notes = project.notes.for_commit_id(commit.id).inline
|
||||
|
||||
@branches = begin
|
||||
project.repository.branch_names_contains(commit.id)
|
||||
rescue Grit::Git::GitTimeout
|
||||
[]
|
||||
end
|
||||
|
||||
@branches = project.repository.branch_names_contains(commit.id)
|
||||
@diffs = @commit.diffs
|
||||
@note = project.build_commit_note(commit)
|
||||
@notes_count = project.notes.for_commit_id(commit.id).count
|
||||
|
|
|
@ -284,4 +284,21 @@ class Repository
|
|||
blob_at(commit.parent_id, diff.old_path)
|
||||
end
|
||||
end
|
||||
|
||||
def branch_names_contains(sha)
|
||||
args = %W(git branch --contains #{sha})
|
||||
names = Gitlab::Popen.popen(args, path_to_repo).first
|
||||
|
||||
if names.respond_to?(:split)
|
||||
names = names.split("\n").map(&:strip)
|
||||
|
||||
names.each do |name|
|
||||
name.slice! '* '
|
||||
end
|
||||
|
||||
names
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
15
spec/models/repository_spec.rb
Normal file
15
spec/models/repository_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Repository do
|
||||
include RepoHelpers
|
||||
|
||||
let(:repository) { create(:project).repository }
|
||||
|
||||
describe :branch_names_contains do
|
||||
subject { repository.branch_names_contains(sample_commit.id) }
|
||||
|
||||
it { should include('master') }
|
||||
it { should_not include('feature') }
|
||||
it { should_not include('fix') }
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue