Memoize GitHubGitDownloadStrategy#default_branch

and then remove `yield_self` from `default_refspec` in favor of relying on `default_branch`'s memoization
This commit is contained in:
Bob Lail 2021-10-25 08:18:03 -05:00
parent b7426b4d51
commit dd3b0d244f

View File

@ -1078,17 +1078,17 @@ class GitHubGitDownloadStrategy < GitDownloadStrategy
sig { returns(String) }
def default_refspec
default_branch.yield_self do |branch|
if branch
"+refs/heads/#{branch}:refs/remotes/origin/#{branch}"
if default_branch
"+refs/heads/#{default_branch}:refs/remotes/origin/#{default_branch}"
else
super
end
end
end
sig { returns(String) }
def default_branch
return @default_branch if defined?(@default_branch)
command! "git",
args: ["remote", "set-head", "origin", "--auto"],
chdir: cached_location
@ -1097,7 +1097,7 @@ class GitHubGitDownloadStrategy < GitDownloadStrategy
args: ["symbolic-ref", "refs/remotes/origin/HEAD"],
chdir: cached_location
result.stdout[%r{^refs/remotes/origin/(.*)$}, 1]
@default_branch = result.stdout[%r{^refs/remotes/origin/(.*)$}, 1]
end
end