2019-07-17 09:06:19 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
class SubmoduleLinks
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
def initialize(repository)
|
|
|
|
@repository = repository
|
2019-10-16 11:06:17 -04:00
|
|
|
@cache_store = {}
|
2019-07-17 09:06:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def for(submodule, sha)
|
2019-07-25 18:01:17 -04:00
|
|
|
submodule_url = submodule_url_for(sha, submodule.path)
|
2019-07-17 09:06:19 -04:00
|
|
|
SubmoduleHelper.submodule_links_for_url(submodule.id, submodule_url, repository)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :repository
|
|
|
|
|
2019-07-25 18:01:17 -04:00
|
|
|
def submodule_urls_for(sha)
|
2019-10-16 11:06:17 -04:00
|
|
|
@cache_store.fetch(sha) do
|
|
|
|
submodule_urls = repository.submodule_urls_for(sha)
|
|
|
|
@cache_store[sha] = submodule_urls
|
2019-07-17 09:06:19 -04:00
|
|
|
end
|
|
|
|
end
|
2019-07-25 18:01:17 -04:00
|
|
|
|
|
|
|
def submodule_url_for(sha, path)
|
|
|
|
urls = submodule_urls_for(sha)
|
|
|
|
urls && urls[path]
|
|
|
|
end
|
2019-07-17 09:06:19 -04:00
|
|
|
end
|
|
|
|
end
|