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