From e5cc33ae8a4ae24f6cd7e4902b640a4ab266b4d7 Mon Sep 17 00:00:00 2001 From: Seeker Date: Mon, 20 Jul 2020 07:44:42 -0700 Subject: [PATCH] bump-formula-pr: cleanup --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 94 ++++++++------------- docs/Manpage.md | 2 - manpages/brew.1 | 4 - 3 files changed, 36 insertions(+), 64 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 37e7d71e02e35..951d5207f0069 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -28,8 +28,6 @@ def bump_formula_pr_args URL-and-SHA-256 style specification into a tag-and-revision style specification, nor vice versa. It must use whichever style specification the formula already uses. EOS - switch "--devel", - description: "Bump the development rather than stable version. The development spec must already exist." switch "-n", "--dry-run", description: "Print what would be done rather than doing it." switch "--write", @@ -123,7 +121,7 @@ def bump_formula_pr formula = args.formulae.first new_url = args.url - formula ||= determine_formula_from_url(new_url, args.devel?) if new_url + formula ||= determine_formula_from_url(new_url) if new_url raise FormulaUnspecifiedError unless formula tap_full_name, origin_branch, previous_branch = use_correct_linux_tap(formula) @@ -132,12 +130,8 @@ def bump_formula_pr new_version = args.version check_all_pull_requests(formula, tap_full_name, version: new_version) if new_version - requested_spec, formula_spec = if args.devel? - devel_message = " (devel)" - [:devel, formula.devel] - else - [:stable, formula.stable] - end + requested_spec = :stable + formula_spec = formula.stable odie "#{formula}: no #{requested_spec} specification found!" unless formula_spec hash_type, old_hash = if (checksum = formula_spec.checksum) @@ -149,7 +143,7 @@ def bump_formula_pr new_revision = args.revision new_mirrors ||= args.mirror new_mirror ||= case new_url - when requested_spec != :devel && %r{.*ftp.gnu.org/gnu.*} + when %r{.*ftp.gnu.org/gnu.*} new_url.sub "ftp.gnu.org/gnu", "ftpmirror.gnu.org" when %r{.*download.savannah.gnu.org/*} new_url.sub "download.savannah.gnu.org", "download-mirror.savannah.gnu.org" @@ -175,7 +169,7 @@ def bump_formula_pr new_tag ||= old_tag.gsub(old_version, new_version) if new_tag == old_tag odie <<~EOS - You probably need to bump this formula manually since the new tag + You need to bump this formula manually since the new tag and old tag are both #{new_tag}. EOS end @@ -190,7 +184,7 @@ def bump_formula_pr new_url ||= old_url.gsub(old_version, new_version) if new_url == old_url odie <<~EOS - You probably need to bump this formula manually since the new URL + You need to bump this formula manually since the new URL and old URL are both: #{new_url} EOS @@ -272,43 +266,27 @@ def bump_formula_pr end if forced_version && new_version != "0" - case requested_spec - when :stable - replacement_pairs << if File.read(formula.path).include?("version \"#{old_formula_version}\"") - [ - old_formula_version.to_s, - new_version, - ] - elsif new_mirrors - [ - /^( +)(mirror "#{Regexp.escape(new_mirrors.last)}"\n)/m, - "\\1\\2\\1version \"#{new_version}\"\n", - ] - else - [ - /^( +)(url "#{Regexp.escape(new_url)}"\n)/m, - "\\1\\2\\1version \"#{new_version}\"\n", - ] - end - when :devel - replacement_pairs << [ - /( devel do.+?version ")#{old_formula_version}("\n.+?end\n)/m, - "\\1#{new_version}\\2", + replacement_pairs << if File.read(formula.path).include?("version \"#{old_formula_version}\"") + [ + old_formula_version.to_s, + new_version, ] - end - elsif forced_version && new_version == "0" - case requested_spec - when :stable - replacement_pairs << [ - /^ version "[\w.\-+]+"\n/m, - "", + elsif new_mirrors + [ + /^( +)(mirror "#{Regexp.escape(new_mirrors.last)}"\n)/m, + "\\1\\2\\1version \"#{new_version}\"\n", ] - when :devel - replacement_pairs << [ - /( devel do.+?)^ +version "[^\n]+"\n(.+?end\n)/m, - "\\1\\2", + else + [ + /^( +)(url "#{Regexp.escape(new_url)}"\n)/m, + "\\1\\2\\1version \"#{new_version}\"\n", ] end + elsif forced_version && new_version == "0" + replacement_pairs << [ + /^ version "[\w.\-+]+"\n/m, + "", + ] end new_contents = inreplace_pairs(formula.path, replacement_pairs.uniq) @@ -328,13 +306,13 @@ def bump_formula_pr if new_formula_version < old_formula_version formula.path.atomic_write(old_contents) unless args.dry_run? odie <<~EOS - You probably need to bump this formula manually since changing the + You need to bump this formula manually since changing the version from #{old_formula_version} to #{new_formula_version} would be a downgrade. EOS elsif new_formula_version == old_formula_version formula.path.atomic_write(old_contents) unless args.dry_run? odie <<~EOS - You probably need to bump this formula manually since the new version + You need to bump this formula manually since the new version and old version are both #{new_formula_version}. EOS end @@ -360,7 +338,7 @@ def bump_formula_pr ohai "git add #{alias_rename.first} #{alias_rename.last}" if alias_rename.present? ohai "git checkout --no-track -b #{branch} #{origin_branch}" ohai "git commit --no-edit --verbose --message='#{formula.name} " \ - "#{new_formula_version}#{devel_message}' -- #{changed_files.join(" ")}" + "#{new_formula_version}' -- #{changed_files.join(" ")}" ohai "git push --set-upstream $HUB_REMOTE #{branch}:#{branch}" ohai "git checkout --quiet #{previous_branch}" ohai "create pull request with GitHub API" @@ -377,7 +355,7 @@ def bump_formula_pr safe_system "git", "add", *alias_rename if alias_rename.present? safe_system "git", "checkout", "--no-track", "-b", branch, origin_branch safe_system "git", "commit", "--no-edit", "--verbose", - "--message=#{formula.name} #{new_formula_version}#{devel_message}", + "--message=#{formula.name} #{new_formula_version}", "--", *changed_files safe_system "git", "push", "--set-upstream", remote_url, "#{branch}:#{branch}" safe_system "git", "checkout", "--quiet", previous_branch @@ -392,7 +370,7 @@ def bump_formula_pr #{user_message} EOS end - pr_title = "#{formula.name} #{new_formula_version}#{devel_message}" + pr_title = "#{formula.name} #{new_formula_version}" begin url = GitHub.create_pull_request(tap_full_name, pr_title, @@ -409,7 +387,7 @@ def bump_formula_pr end end - def determine_formula_from_url(url, is_devel) + def determine_formula_from_url(url) # Split the new URL on / and find any formulae that have the same URL # except for the last component, but don't try to match any more than the # first five components since sometimes the last component isn't the only @@ -421,14 +399,10 @@ def determine_formula_from_url(url, is_devel) base_url = /#{Regexp.escape(base_url)}/ guesses = [] Formula.each do |f| - if is_devel && f.devel && f.devel.url && f.devel.url.match(base_url) - guesses << f - elsif f.stable&.url && f.stable.url.match(base_url) - guesses << f - end + guesses << f if f.stable&.url && f.stable.url.match(base_url) end return guesses.shift if guesses.count == 1 - return unless guesses.count > 1 + return if guesses.count <= 1 odie "Couldn't guess formula for sure; could be one of these:\n#{guesses.map(&:name).join(", ")}" end @@ -518,7 +492,11 @@ def check_open_pull_requests(formula, tap_full_name) end def check_all_pull_requests(formula, tap_full_name, version: nil, url: nil, tag: nil) - version ||= Version.detect(url, tag ? { tag: tag } : {}) + unless version + specs = {} + specs[:tag] = tag if tag + version = Version.detect(url, specs) + end # if we haven't already found open requests, try for an exact match across all requests pull_requests = fetch_pull_requests("#{formula.name} #{version}", tap_full_name) if pull_requests.blank? check_for_duplicate_pull_requests(pull_requests) diff --git a/docs/Manpage.md b/docs/Manpage.md index ca46a02513d0d..cc7aba96874df 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -719,8 +719,6 @@ URL-and-SHA-256 style specification into a tag-and-revision style specification, nor vice versa. It must use whichever style specification the formula already uses. -* `--devel`: - Bump the development rather than stable version. The development spec must already exist. * `-n`, `--dry-run`: Print what would be done rather than doing it. * `--write`: diff --git a/manpages/brew.1 b/manpages/brew.1 index e5643fde8249e..dc0d67fd46b36 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -926,10 +926,6 @@ If a \fIversion\fR is specified, a best effort to determine the \fIURL\fR and \f \fINote:\fR this command cannot be used to transition a formula from a URL\-and\-SHA\-256 style specification into a tag\-and\-revision style specification, nor vice versa\. It must use whichever style specification the formula already uses\. . .TP -\fB\-\-devel\fR -Bump the development rather than stable version\. The development spec must already exist\. -. -.TP \fB\-n\fR, \fB\-\-dry\-run\fR Print what would be done rather than doing it\. .