Skip to content
Snippets Groups Projects
Commit 4f668368 authored by Yorick Peterse's avatar Yorick Peterse
Browse files

Merge branch 'compare-lazy-load-commits' into 'master'

Lazy load compare commits

See merge request !113
parents e282c440 36f97f00
No related branches found
No related tags found
1 merge request!113Lazy load compare commits
Pipeline #
v 10.4.4
- Lazy load compare commits
v 10.4.3
- Cleanup local branches after creation to make rspec pass
- rubocop-rspec version compatible with ruby 2.1
- Add deltas_only option for DiffCollection
v 10.4.2
- Improve performance of a decorated DiffCollection instance
 
Loading
Loading
module Gitlab
module Git
class Compare
attr_reader :commits, :same, :head, :base
attr_reader :head, :base
 
def initialize(repository, base, head)
@commits = []
@same = false
@repository = repository
 
return unless base && head
Loading
Loading
@@ -13,14 +11,18 @@ module Gitlab
@base = Gitlab::Git::Commit.find(repository, base.try(:strip))
@head = Gitlab::Git::Commit.find(repository, head.try(:strip))
 
return unless @base && @head
@commits = [] unless @base && @head
@commits = [] if same
end
 
if @base.id == @head.id
@same = true
return
end
def same
@base && @head && @base.id == @head.id
end
def commits
return @commits if defined?(@commits)
 
@commits = Gitlab::Git::Commit.between(repository, @base.id, @head.id)
@commits = Gitlab::Git::Commit.between(@repository, @base.id, @head.id)
end
 
def diffs(options = {})
Loading
Loading
Loading
Loading
@@ -14,6 +14,24 @@ describe Gitlab::Git::Compare do
end
it { is_expected.to include(SeedRepo::Commit::PARENT_ID) }
it { is_expected.not_to include(SeedRepo::BigCommit::PARENT_ID) }
context 'non-existing base ref' do
let(:compare) { Gitlab::Git::Compare.new(repository, 'no-such-branch', SeedRepo::Commit::ID) }
it { is_expected.to be_empty }
end
context 'non-existing head ref' do
let(:compare) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, '1234567890') }
it { is_expected.to be_empty }
end
context 'base ref is equal to head ref' do
let(:compare) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, SeedRepo::BigCommit::ID) }
it { is_expected.to be_empty }
end
end
 
describe :diffs do
Loading
Loading
@@ -26,12 +44,31 @@ describe Gitlab::Git::Compare do
end
it { is_expected.to include('files/ruby/popen.rb') }
it { is_expected.not_to include('LICENSE') }
context 'non-existing base ref' do
let(:compare) { Gitlab::Git::Compare.new(repository, 'no-such-branch', SeedRepo::Commit::ID) }
it { is_expected.to be_empty }
end
context 'non-existing head ref' do
let(:compare) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, '1234567890') }
it { is_expected.to be_empty }
end
end
 
describe 'non-existing refs' do
let(:compare) { Gitlab::Git::Compare.new(repository, 'no-such-branch', '1234567890') }
describe :same do
subject do
compare.same
end
it { is_expected.to eq(false) }
 
it { expect(compare.commits).to be_empty }
it { expect(compare.diffs).to be_empty }
context 'base ref is equal to head ref' do
let(:compare) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, SeedRepo::BigCommit::ID) }
it { is_expected.to eq(true) }
end
end
end
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