Skip to content
Snippets Groups Projects
Commit 43f5700b authored by Alejandro Rodríguez's avatar Alejandro Rodríguez
Browse files

Refactor Ref's `target` to be consistent with Rugged

!103 introduced an optimization where a Refs target would point to the
dereferenced object, which saved us a lot operations, but became
inconsistent with Rugged's API, where target would always reference the
immediate object pointed at. These changes add a new property,
dereference_target to be consistent with Rugged but still be able to get
the target efficiently.
parent 382275e1
No related branches found
No related tags found
1 merge request!131Resolve "Ref's interface is inconsistent with Rugged's API"
Pipeline #
v 10.7.0
- Refactor Ref's `target` fields to be consistent with Rugged implementation
v 10.6.10
- Ignore invalid encodings when parsing Git attribute files
- Revert to previous diff pruning behavior
Loading
Loading
Loading
Loading
@@ -12,6 +12,10 @@ module Gitlab
# when tag reference on other tag it can be tag sha
attr_reader :target
 
# Dereferenced target
# Commit object to which the Ref points to
attr_reader :dereferenced_target
# Extract branch name from full ref path
#
# Ex.
Loading
Loading
@@ -29,8 +33,16 @@ module Gitlab
def initialize(repository, name, target)
encode! name
@name = name.gsub(/\Arefs\/(tags|heads)\//, '')
@target = Commit.find(repository, target)
@dereferenced_target = Commit.find(repository, target)
@target = if target.respond_to?(:oid)
target.oid
elsif target.respond_to?(:name)
target.name
elsif target.is_a? String
target
else
nil
end
end
end
end
Loading
Loading
Loading
Loading
@@ -116,17 +116,14 @@ module Gitlab
message = nil
 
if ref.target.is_a?(Rugged::Tag::Annotation)
object = ref.target
tag_message = ref.target.message
 
if tag_message.respond_to?(:chomp)
message = tag_message.chomp
end
else
object = nil # Lightweight tags aren't git objects
end
 
Tag.new(self, object, ref.name, ref.target, message)
Tag.new(self, ref.name, ref.target, message)
end.sort_by(&:name)
end
 
Loading
Loading
Loading
Loading
@@ -3,23 +3,17 @@ module Gitlab
class Tag < Ref
attr_reader :object_sha
 
def initialize(repository, object, name, target, message = nil)
def initialize(repository, name, target, message = nil)
super(repository, name, target)
@object_sha = if object.respond_to?(:oid)
object.oid
elsif object.respond_to?(:name)
object.name
elsif object.is_a? String
object
else
nil
end
@message = message
end
 
def message
encode! @message
end
private
end
end
end
Loading
Loading
@@ -16,7 +16,7 @@ describe Gitlab::Git::Branch do
let(:branch) { repository.branches.first }
 
it { expect(branch.name).to eq(SeedRepo::Repo::BRANCHES.first) }
it { expect(branch.target.sha).to eq("0b4bc9a49b562e85de7cc9e834518ea6828729b9") }
it { expect(branch.dereferenced_target.sha).to eq("0b4bc9a49b562e85de7cc9e834518ea6828729b9") }
end
 
describe 'master branch' do
Loading
Loading
@@ -24,7 +24,7 @@ describe Gitlab::Git::Branch do
repository.branches.find { |branch| branch.name == 'master' }
end
 
it { expect(branch.target.sha).to eq(SeedRepo::LastCommit::ID) }
it { expect(branch.dereferenced_target.sha).to eq(SeedRepo::LastCommit::ID) }
end
 
it { expect(repository.branches.size).to eq(SeedRepo::Repo::BRANCHES.size) }
Loading
Loading
Loading
Loading
@@ -140,7 +140,7 @@ describe Gitlab::Git::Repository do
end
 
context :commit do
subject { heads.first.target.sha }
subject { heads.first.dereferenced_target.sha }
 
it { is_expected.to eq("0b4bc9a49b562e85de7cc9e834518ea6828729b9") }
end
Loading
Loading
@@ -1139,6 +1139,6 @@ index 0000000..e69de29
def create_remote_branch(remote_name, branch_name, source_branch_name)
source_branch = @repo.branches.find { |branch| branch.name == source_branch_name }
rugged = @repo.rugged
rugged.references.create("refs/remotes/#{remote_name}/#{branch_name}", source_branch.target.sha)
rugged.references.create("refs/remotes/#{remote_name}/#{branch_name}", source_branch.dereferenced_target.sha)
end
end
Loading
Loading
@@ -7,8 +7,8 @@ describe Gitlab::Git::Tag do
let(:tag) { repository.tags.first }
 
it { expect(tag.name).to eq("v1.0.0") }
it { expect(tag.object_sha).to eq("f4e6814c3e4e7a0de82a9e7cd20c626cc963a2f8") }
it { expect(tag.target.sha).to eq("6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9") }
it { expect(tag.target).to eq("f4e6814c3e4e7a0de82a9e7cd20c626cc963a2f8") }
it { expect(tag.dereferenced_target.sha).to eq("6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9") }
it { expect(tag.message).to eq("Release") }
end
 
Loading
Loading
@@ -16,8 +16,8 @@ describe Gitlab::Git::Tag do
let(:tag) { repository.tags.last }
 
it { expect(tag.name).to eq("v1.2.1") }
it { expect(tag.object_sha).to eq("2ac1f24e253e08135507d0830508febaaccf02ee") }
it { expect(tag.target.sha).to eq("fa1b1e6c004a68b7d8763b86455da9e6b23e36d6") }
it { expect(tag.target).to eq("2ac1f24e253e08135507d0830508febaaccf02ee") }
it { expect(tag.dereferenced_target.sha).to eq("fa1b1e6c004a68b7d8763b86455da9e6b23e36d6") }
it { expect(tag.message).to eq("Version 1.2.1") }
end
 
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