Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Tap#repo_var to Tap#repo_var_suffix. #16732

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Library/Homebrew/cmd/update-report.rb
Expand Up @@ -428,11 +428,11 @@ def initialize(tap, api_names_txt: nil, api_names_before_txt: nil, api_dir_prefi
@api_names_before_txt = api_names_before_txt
@api_dir_prefix = api_dir_prefix
else
initial_revision_var = "HOMEBREW_UPDATE_BEFORE#{tap.repo_var}"
initial_revision_var = "HOMEBREW_UPDATE_BEFORE#{tap.repo_var_suffix}"
@initial_revision = ENV[initial_revision_var].to_s
raise ReporterRevisionUnsetError, initial_revision_var if @initial_revision.empty?

current_revision_var = "HOMEBREW_UPDATE_AFTER#{tap.repo_var}"
current_revision_var = "HOMEBREW_UPDATE_AFTER#{tap.repo_var_suffix}"
@current_revision = ENV[current_revision_var].to_s
raise ReporterRevisionUnsetError, current_revision_var if @current_revision.empty?
end
Expand Down
20 changes: 10 additions & 10 deletions Library/Homebrew/cmd/update.sh
Expand Up @@ -92,18 +92,18 @@ git_init_if_necessary() {
fi
}

repo_var() {
local repo_var
repo_var_suffix() {
local repo_dir="${1}"
reitermarkus marked this conversation as resolved.
Show resolved Hide resolved
local repo_var_suffix

repo_var="$1"
if [[ "${repo_var}" == "${HOMEBREW_REPOSITORY}" ]]
if [[ "${repo_dir}" == "${HOMEBREW_REPOSITORY}" ]]
then
repo_var=""
repo_var_suffix=""
else
repo_var="${repo_var#"${HOMEBREW_LIBRARY}/Taps"}"
repo_var="$(echo -n "${repo_var}" | tr -C "A-Za-z0-9" "_" | tr "[:lower:]" "[:upper:]")"
repo_var_suffix="${repo_dir#"${HOMEBREW_LIBRARY}/Taps"}"
repo_var_suffix="$(echo -n "${repo_var_suffix}" | tr -C "A-Za-z0-9" "_" | tr "[:lower:]" "[:upper:]")"
fi
echo "${repo_var}"
echo "${repo_var_suffix}"
}

upstream_branch() {
Expand Down Expand Up @@ -600,7 +600,7 @@ EOS
echo "Checking if we need to fetch ${DIR}..."
fi

TAP_VAR="$(repo_var "${DIR}")"
TAP_VAR="$(repo_var_suffix "${DIR}")"
UPSTREAM_BRANCH_DIR="$(upstream_branch)"
declare UPSTREAM_BRANCH"${TAP_VAR}"="${UPSTREAM_BRANCH_DIR}"
declare PREFETCH_REVISION"${TAP_VAR}"="$(git rev-parse -q --verify refs/remotes/origin/"${UPSTREAM_BRANCH_DIR}")"
Expand Down Expand Up @@ -774,7 +774,7 @@ EOS
continue
fi

TAP_VAR="$(repo_var "${DIR}")"
TAP_VAR="$(repo_var_suffix "${DIR}")"
UPSTREAM_BRANCH_VAR="UPSTREAM_BRANCH${TAP_VAR}"
UPSTREAM_BRANCH="${!UPSTREAM_BRANCH_VAR}"
CURRENT_REVISION="$(read_current_revision)"
Expand Down
14 changes: 8 additions & 6 deletions Library/Homebrew/tap.rb
Expand Up @@ -122,7 +122,7 @@ def initialize(user, repo)
# Clear internal cache.
def clear_cache
@remote = nil
@repo_var = nil
@repo_var_suffix = nil
@formula_dir = nil
@cask_dir = nil
@command_dir = nil
Expand Down Expand Up @@ -175,11 +175,13 @@ def default_remote
"https://github.com/#{full_name}"
end

def repo_var
@repo_var ||= path.to_s
.delete_prefix(TAP_DIRECTORY.to_s)
.tr("^A-Za-z0-9", "_")
.upcase
# @private
sig { returns(String) }
def repo_var_suffix
@repo_var_suffix ||= path.to_s
.delete_prefix(TAP_DIRECTORY.to_s)
.tr("^A-Za-z0-9", "_")
.upcase
end

# True if this {Tap} is a Git repository.
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/test/cmd/update-report_spec.rb
Expand Up @@ -15,8 +15,8 @@
def initialize(tap)
@tap = tap

ENV["HOMEBREW_UPDATE_BEFORE#{tap.repo_var}"] = "12345678"
ENV["HOMEBREW_UPDATE_AFTER#{tap.repo_var}"] = "abcdef00"
ENV["HOMEBREW_UPDATE_BEFORE#{tap.repo_var_suffix}"] = "12345678"
ENV["HOMEBREW_UPDATE_AFTER#{tap.repo_var_suffix}"] = "abcdef00"

super(tap)
end
Expand Down
11 changes: 11 additions & 0 deletions Library/Homebrew/test/tap_spec.rb
Expand Up @@ -588,4 +588,15 @@ class Foo < Formula
expect(core_tap.pypi_formula_mappings).to eq formula_list_file_contents
end
end

describe "#repo_var_suffix" do
it "converts the repo directory to an environment variable suffix" do
expect(CoreTap.instance.repo_var_suffix).to eq "_HOMEBREW_HOMEBREW_CORE"
end

it "converts non-alphanumeric characters to underscores" do
expect(described_class.fetch("my", "tap-with-dashes").repo_var_suffix).to eq "_MY_HOMEBREW_TAP_WITH_DASHES"
expect(described_class.fetch("my", "tap-with-@-symbol").repo_var_suffix).to eq "_MY_HOMEBREW_TAP_WITH___SYMBOL"
end
end
end