From dd3b0d244ff495973fd1266a27b7910912c9206c Mon Sep 17 00:00:00 2001 From: Bob Lail Date: Mon, 25 Oct 2021 08:18:03 -0500 Subject: [PATCH] Memoize `GitHubGitDownloadStrategy#default_branch` and then remove `yield_self` from `default_refspec` in favor of relying on `default_branch`'s memoization --- Library/Homebrew/download_strategy.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index ea8a21162e..7c08865607 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -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}" - else - super - end + if default_branch + "+refs/heads/#{default_branch}:refs/remotes/origin/#{default_branch}" + else + super 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