summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2018-07-04 14:42:24 +0200
committerJacob Vosmaer <jacob@gitlab.com>2018-07-06 12:06:54 +0200
commitff112ce641a93f38647e67e4ed92b685ccc2430a (patch)
treecd06666c03a091f7c1df1535a60870f296f81526 /lib
parentafb3caac797f5c90af9ff4989a3730299d39e3f1 (diff)
downloadgitlab-ce-ff112ce641a93f38647e67e4ed92b685ccc2430a.tar.gz
Add Repository#set_config and #delete_config
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/git/repository.rb12
-rw-r--r--lib/gitlab/gitaly_client/repository_service.rb49
2 files changed, 55 insertions, 6 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index bbfe6ab1d95..29b3663a52a 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -1115,8 +1115,18 @@ module Gitlab
# This guard avoids Gitaly log/error spam
raise NoRepository, 'repository does not exist' unless exists?
+ set_config('gitlab.fullpath' => full_path)
+ end
+
+ def set_config(entries)
+ wrapped_gitaly_errors do
+ gitaly_repository_client.set_config(entries)
+ end
+ end
+
+ def delete_config(*keys)
wrapped_gitaly_errors do
- gitaly_repository_client.write_config(full_path: full_path)
+ gitaly_repository_client.delete_config(keys)
end
end
diff --git a/lib/gitlab/gitaly_client/repository_service.rb b/lib/gitlab/gitaly_client/repository_service.rb
index 982f8d0963b..64b9af4d70c 100644
--- a/lib/gitlab/gitaly_client/repository_service.rb
+++ b/lib/gitlab/gitaly_client/repository_service.rb
@@ -265,17 +265,39 @@ module Gitlab
true
end
- def write_config(full_path:)
- request = Gitaly::WriteConfigRequest.new(repository: @gitaly_repo, full_path: full_path)
- response = GitalyClient.call(
+ def set_config(entries)
+ return if entries.empty?
+
+ request = Gitaly::SetConfigRequest.new(repository: @gitaly_repo)
+ entries.each do |key, value|
+ request.entries << build_set_config_entry(key, value)
+ end
+
+ GitalyClient.call(
+ @storage,
+ :repository_service,
+ :set_config,
+ request,
+ timeout: GitalyClient.fast_timeout
+ )
+
+ nil
+ end
+
+ def delete_config(keys)
+ return if keys.empty?
+
+ request = Gitaly::DeleteConfigRequest.new(repository: @gitaly_repo, keys: keys)
+
+ GitalyClient.call(
@storage,
:repository_service,
- :write_config,
+ :delete_config,
request,
timeout: GitalyClient.fast_timeout
)
- raise Gitlab::Git::OSError.new(response.error) unless response.error.empty?
+ nil
end
def license_short_name
@@ -352,6 +374,23 @@ module Gitlab
timeout: timeout
)
end
+
+ def build_set_config_entry(key, value)
+ entry = Gitaly::SetConfigRequest::Entry.new(key: key)
+
+ case value
+ when String
+ entry.value_str = value
+ when Integer
+ entry.value_int32 = value
+ when TrueClass, FalseClass
+ entry.value_bool = value
+ else
+ raise InvalidArgument, "invalid git config value: #{value.inspect}"
+ end
+
+ entry
+ end
end
end
end