diff options
author | Robert Speicher <rspeicher@gmail.com> | 2020-04-20 18:36:55 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2020-04-20 18:36:55 +0300 |
commit | 960b5ce6680c722db8360aca51887503921cc778 (patch) | |
tree | 14db7fa979cb4e62ec8c89e7168a138b730acb3f | |
parent | 44baa4513541671ae64601173466c425ce28e5fb (diff) |
`Ref` objects receive the `canonical_name` from Rugged
The `Gitlab::Git::Ref` initializer, which `Branch` inherits, already
removes the `refs/heads|tags/` prefix from the provided name via
`Gitlab::Git.ref_name`, so there should be no functional difference to
providing the "canonical name".
In a future commit, we'll store the canonical name in addition to the
non-prefixed name.
-rw-r--r-- | changelogs/unreleased/rs-divergent-refs-response.yml | 5 | ||||
-rw-r--r-- | internal/service/remote/update_remote_mirror_test.go | 3 | ||||
-rw-r--r-- | proto/go/gitalypb/remote.pb.go | 107 | ||||
-rw-r--r-- | proto/remote.proto | 4 | ||||
-rw-r--r-- | ruby/lib/gitaly_server/remote_service.rb | 7 | ||||
-rw-r--r-- | ruby/lib/gitlab/git/ref.rb | 4 | ||||
-rw-r--r-- | ruby/lib/gitlab/git/remote_mirror.rb | 14 | ||||
-rw-r--r-- | ruby/lib/gitlab/git/repository.rb | 8 | ||||
-rw-r--r-- | ruby/proto/gitaly/remote_pb.rb | 1 | ||||
-rw-r--r-- | ruby/spec/lib/gitaly_server/remote_service_spec.rb | 21 |
10 files changed, 117 insertions, 57 deletions
diff --git a/changelogs/unreleased/rs-divergent-refs-response.yml b/changelogs/unreleased/rs-divergent-refs-response.yml new file mode 100644 index 000000000..e85e96ecf --- /dev/null +++ b/changelogs/unreleased/rs-divergent-refs-response.yml @@ -0,0 +1,5 @@ +--- +title: Add DivergentRefs to UpdateRemoteMirrorResponse +merge_request: 2028 +author: +type: added diff --git a/internal/service/remote/update_remote_mirror_test.go b/internal/service/remote/update_remote_mirror_test.go index 499c40b13..5242fc0df 100644 --- a/internal/service/remote/update_remote_mirror_test.go +++ b/internal/service/remote/update_remote_mirror_test.go @@ -223,8 +223,9 @@ func TestSuccessfulUpdateRemoteMirrorRequestWithKeepDivergentRefs(t *testing.T) require.NoError(t, err) require.NoError(t, stream.Send(firstRequest)) - _, err = stream.CloseAndRecv() + response, err := stream.CloseAndRecv() require.NoError(t, err) + require.ElementsMatch(t, response.DivergentRefs, [][]byte{[]byte("refs/heads/master")}) mirrorRefs := string(testhelper.MustRunCommand(t, nil, "git", "-C", mirrorPath, "for-each-ref")) diff --git a/proto/go/gitalypb/remote.pb.go b/proto/go/gitalypb/remote.pb.go index 9ac3909f5..68b26f61e 100644 --- a/proto/go/gitalypb/remote.pb.go +++ b/proto/go/gitalypb/remote.pb.go @@ -371,6 +371,7 @@ func (m *UpdateRemoteMirrorRequest) GetKeepDivergentRefs() bool { } type UpdateRemoteMirrorResponse struct { + DivergentRefs [][]byte `protobuf:"bytes,1,rep,name=divergent_refs,json=divergentRefs,proto3" json:"divergent_refs,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -401,6 +402,13 @@ func (m *UpdateRemoteMirrorResponse) XXX_DiscardUnknown() { var xxx_messageInfo_UpdateRemoteMirrorResponse proto.InternalMessageInfo +func (m *UpdateRemoteMirrorResponse) GetDivergentRefs() [][]byte { + if m != nil { + return m.DivergentRefs + } + return nil +} + type FindRemoteRepositoryRequest struct { Remote string `protobuf:"bytes,1,opt,name=remote,proto3" json:"remote,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -721,55 +729,56 @@ func init() { func init() { proto.RegisterFile("remote.proto", fileDescriptor_eefc82927d57d89b) } var fileDescriptor_eefc82927d57d89b = []byte{ - // 759 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xc9, 0x6e, 0xd3, 0x40, - 0x18, 0x96, 0x93, 0x34, 0xcb, 0x9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- 0xf9, 0x67, 0x5e, 0x6e, 0x08, 0x00, 0x00, + // 772 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xcb, 0x6e, 0xd3, 0x4c, + 0x14, 0x96, 0x93, 0x34, 0x97, 0x93, 0xb4, 0x4a, 0x26, 0x55, 0x7f, 0xc7, 0xa9, 0xf4, 0xa7, 0x86, + 0x4a, 0x59, 0xd0, 0xa4, 0x2a, 0x17, 0xb1, 0x40, 0x42, 0x14, 0x84, 0xca, 0xa5, 0x15, 0x18, 0xba, + 0x61, 0x63, 0x9c, 0x64, 0x92, 0x58, 0x71, 0x3c, 0x66, 0x66, 0x52, 0xc8, 0x5b, 0xb0, 0x2b, 0x0b, + 0x5e, 0x80, 0x0d, 0x8f, 0xc1, 0x43, 0x75, 0x85, 0xc6, 0x33, 0x4e, 0x9c, 0xd4, 0x09, 0x8b, 0xc2, + 0xce, 0x73, 0x2e, 0xdf, 0xf9, 0xce, 0x55, 0x86, 0x12, 0xc5, 0x63, 0xc2, 0x71, 0x2b, 0xa0, 0x84, + 0x13, 0x94, 0x1d, 0xb8, 0xdc, 0xf1, 0xa6, 0x06, 0x78, 0xae, 0xcf, 0xa5, 0xcc, 0x28, 0xb1, 0xa1, + 0x43, 0x71, 0x4f, 0xbe, 0xcc, 0x9f, 0x1a, 0x94, 0x9f, 0xf4, 0x7a, 0x56, 0xe8, 0x65, 0xe1, 0x4f, + 0x13, 0xcc, 0x38, 0x7a, 0x08, 0x40, 0x71, 0x40, 0x98, 0xcb, 0x09, 0x9d, 0xea, 0x5a, 0x43, 0x6b, + 0x16, 0x8f, 0x50, 0x4b, 0x62, 0xb5, 0xac, 0x99, 0xe6, 0x38, 0xf3, 0xed, 0xd7, 0x1d, 0xcd, 0x8a, + 0xd9, 0x22, 0x04, 0x19, 0xdf, 0x19, 0x63, 0x3d, 0xd5, 0xd0, 0x9a, 0x05, 0x2b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, 0x11, 0xde, 0xa1, 0x76, 0x7c, 0xf8, 0x41, 0xd8, 0x79, 0x4e, 0xa7, 0xd5, 0x25, 0xe3, + 0xb6, 0xfc, 0x3c, 0x20, 0x74, 0xd0, 0x96, 0xde, 0xed, 0xf0, 0x87, 0xa2, 0x3d, 0x20, 0xea, 0x1d, + 0x74, 0x3a, 0xd9, 0x50, 0x74, 0xf7, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x49, 0x23, 0x90, 0x30, + 0x95, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/proto/remote.proto b/proto/remote.proto index 624f826fd..67cb012f8 100644 --- a/proto/remote.proto +++ b/proto/remote.proto @@ -87,7 +87,9 @@ message UpdateRemoteMirrorRequest { bool keep_divergent_refs = 6; } -message UpdateRemoteMirrorResponse {} +message UpdateRemoteMirrorResponse { + repeated bytes divergent_refs = 1; +} message FindRemoteRepositoryRequest { string remote = 1; diff --git a/ruby/lib/gitaly_server/remote_service.rb b/ruby/lib/gitaly_server/remote_service.rb index fa62ec092..66a2d6b7d 100644 --- a/ruby/lib/gitaly_server/remote_service.rb +++ b/ruby/lib/gitaly_server/remote_service.rb @@ -2,6 +2,9 @@ module GitalyServer class RemoteService < Gitaly::RemoteService::Service include Utils + # Maximum number of divergent refs to return in UpdateRemoteMirrorResponse + DIVERGENT_REF_LIMIT = 100 + def add_remote(request, call) repo = Gitlab::Git::Repository.from_gitaly(request.repository, call) @@ -38,7 +41,9 @@ module GitalyServer remote_mirror.update - Gitaly::UpdateRemoteMirrorResponse.new + Gitaly::UpdateRemoteMirrorResponse.new( + divergent_refs: remote_mirror.divergent_refs.take(DIVERGENT_REF_LIMIT) + ) end end end diff --git a/ruby/lib/gitlab/git/ref.rb b/ruby/lib/gitlab/git/ref.rb index fdf35e473..e45bec404 100644 --- a/ruby/lib/gitlab/git/ref.rb +++ b/ruby/lib/gitlab/git/ref.rb @@ -5,6 +5,9 @@ module Gitlab class Ref include Gitlab::EncodingHelper + # Canonical refname, including `refs/heads|tags/` prefix + attr_reader :refname + # Branch or tag name # without "refs/tags|heads" prefix attr_reader :name @@ -34,6 +37,7 @@ module Gitlab end def initialize(_repository, name, target, dereferenced_target) + @refname = name @name = Gitlab::Git.ref_name(name) @dereferenced_target = dereferenced_target @target = if target.respond_to?(:oid) diff --git a/ruby/lib/gitlab/git/remote_mirror.rb b/ruby/lib/gitlab/git/remote_mirror.rb index 2ad02bb26..02a35026d 100644 --- a/ruby/lib/gitlab/git/remote_mirror.rb +++ b/ruby/lib/gitlab/git/remote_mirror.rb @@ -3,12 +3,19 @@ module Gitlab class RemoteMirror attr_reader :repository, :remote_name, :ssh_auth, :only_branches_matching + # An Array of local refnames that have diverged on the remote + # + # Only populated when `keep_divergent_refs` is enabled + attr_reader :divergent_refs + def initialize(repository, remote_name, ssh_auth:, only_branches_matching:, keep_divergent_refs:) @repository = repository @remote_name = remote_name @ssh_auth = ssh_auth @only_branches_matching = only_branches_matching @keep_divergent_refs = keep_divergent_refs + + @divergent_refs = [] end def update @@ -71,7 +78,12 @@ module Gitlab false elsif @keep_divergent_refs # Mirror the ref if its remote counterpart hasn't diverged - repository.ancestor?(remote_target&.id, local_target&.id) + if repository.ancestor?(remote_target&.id, local_target&.id) + true + else + @divergent_refs << ref.refname + false + end else # Attempt to overwrite whatever's on the remote; push rules and # protected branches may still prevent this diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb index 326c4c563..80b4c24ef 100644 --- a/ruby/lib/gitlab/git/repository.rb +++ b/ruby/lib/gitlab/git/repository.rb @@ -181,7 +181,7 @@ module Gitlab target_commit = Gitlab::Git::Commit.find(self, ref.target) Gitlab::Git::Tag.new(self, - name: ref.name, + name: ref.canonical_name, target: ref.target, target_commit: target_commit, message: message) @@ -543,7 +543,7 @@ module Gitlab rugged_ref = rugged.branches[name] if rugged_ref target_commit = Gitlab::Git::Commit.find(self, rugged_ref.target) - Gitlab::Git::Branch.new(self, rugged_ref.name, rugged_ref.target, target_commit) + Gitlab::Git::Branch.new(self, rugged_ref.canonical_name, rugged_ref.target, target_commit) end end @@ -552,7 +552,7 @@ module Gitlab return unless rugged_ref - Gitlab::Git::Ref.new(self, rugged_ref.name, rugged_ref.target, rugged_ref.target_id) + Gitlab::Git::Ref.new(self, rugged_ref.canonical_name, rugged_ref.target, rugged_ref.target_id) end # Delete the specified branch from the repository @@ -798,7 +798,7 @@ module Gitlab branches = rugged.branches.each(filter).map do |rugged_ref| begin target_commit = Gitlab::Git::Commit.find(self, rugged_ref.target) - Gitlab::Git::Branch.new(self, rugged_ref.name, rugged_ref.target, target_commit) + Gitlab::Git::Branch.new(self, rugged_ref.canonical_name, rugged_ref.target, target_commit) rescue Rugged::ReferenceError # Omit invalid branch end diff --git a/ruby/proto/gitaly/remote_pb.rb b/ruby/proto/gitaly/remote_pb.rb index 6f03c83a4..36f985412 100644 --- a/ruby/proto/gitaly/remote_pb.rb +++ b/ruby/proto/gitaly/remote_pb.rb @@ -38,6 +38,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do optional :keep_divergent_refs, :bool, 6 end add_message "gitaly.UpdateRemoteMirrorResponse" do + repeated :divergent_refs, :bytes, 1 end add_message "gitaly.FindRemoteRepositoryRequest" do optional :remote, :string, 1 diff --git a/ruby/spec/lib/gitaly_server/remote_service_spec.rb b/ruby/spec/lib/gitaly_server/remote_service_spec.rb new file mode 100644 index 000000000..511b4f008 --- /dev/null +++ b/ruby/spec/lib/gitaly_server/remote_service_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitalyServer::RemoteService do + describe '#update_remote_mirror' do + it 'assigns a limited number of divergent refs' do + stub_const("#{described_class}::DIVERGENT_REF_LIMIT", 2) + + mirror = double( + divergent_refs: %w[refs/heads/master refs/heads/develop refs/heads/stable] + ).as_null_object + stub_const('Gitlab::Git::RemoteMirror', mirror) + + call = double(to_a: [], to_ary: []).as_null_object + response = described_class.new.update_remote_mirror(call) + + expect(response.divergent_refs).to eq(%w[refs/heads/master refs/heads/develop]) + end + end +end |