From 99bb068ca734c7096bf82c72730f1babc7f72431 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Wed, 24 Jan 2018 06:37:27 -0800 Subject: [PATCH 1/6] bump-formula-pr: improve formula name guessing. --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 7069a48167..334269a0ae 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -137,9 +137,16 @@ module Homebrew new_url = ARGV.value("url") if new_url && !formula - is_devel = ARGV.include?("--devel") - base_url = new_url.split("/")[0..4].join("/") + # 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 + # one to change. + new_url_split = new_url.split("/") + maximum_url_components_to_match = 5 + components_to_match = [new_url_split.count - 1, maximum_url_components_to_match].min + base_url = new_url_split.first(components_to_match).join("/") base_url = /#{Regexp.escape(base_url)}/ + is_devel = ARGV.include?("--devel") guesses = [] Formula.each do |f| if is_devel && f.devel && f.devel.url && f.devel.url.match(base_url) From e46fbdd18d7e3f39350073debeca1d59487e1af1 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Wed, 24 Jan 2018 06:49:31 -0800 Subject: [PATCH 2/6] bump-formula-pr: update GNU mirror handling. homebrew/core now uses ftp.gnu.org/gnu for the primary url and ftpmirror.gnu.org for the mirror. --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 334269a0ae..e536d03be3 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -191,13 +191,10 @@ module Homebrew elsif !new_url odie "#{formula}: no --url= argument specified!" else - resource_url = if requested_spec != :devel && new_url =~ /.*ftpmirror.gnu.*/ - new_mirror = new_url.sub "ftpmirror.gnu.org", "ftp.gnu.org/gnu" - new_mirror - else - new_url + new_mirror = if requested_spec != :devel && new_url =~ %r{.*ftp.gnu.org/gnu.*} + new_url.sub "ftp.gnu.org/gnu", "ftpmirror.gnu.org" end - resource = Resource.new { @url = resource_url } + resource = Resource.new { @url = new_url } resource.download_strategy = CurlDownloadStrategy resource.owner = Resource.new(formula.name) resource.version = forced_version if forced_version From 6460a34e6580260a0392f8945fd31213678a1b34 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Wed, 24 Jan 2018 06:54:14 -0800 Subject: [PATCH 3/6] bump-formula-pr: add Debian mirror handling. --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index e536d03be3..510650806f 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -191,8 +191,11 @@ module Homebrew elsif !new_url odie "#{formula}: no --url= argument specified!" else - new_mirror = if requested_spec != :devel && new_url =~ %r{.*ftp.gnu.org/gnu.*} + new_mirror = case new_url + when requested_spec != :devel && %r{.*ftp.gnu.org/gnu.*} new_url.sub "ftp.gnu.org/gnu", "ftpmirror.gnu.org" + when %r{.*mirrors.ocf.berkeley.edu/debian.*} + new_url.sub "mirrors.ocf.berkeley.edu/debian", "mirrorservice.org/sites/ftp.debian.org/debian" end resource = Resource.new { @url = new_url } resource.download_strategy = CurlDownloadStrategy From edd1c76d409e224e329131bbd635d944cdf6fe1f Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Wed, 24 Jan 2018 06:55:55 -0800 Subject: [PATCH 4/6] bump-formula-pr: detect download strategy from url. Previously, CurlDownloadStrategy was hard coded. --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 510650806f..1f60412ed4 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -198,7 +198,7 @@ module Homebrew new_url.sub "mirrors.ocf.berkeley.edu/debian", "mirrorservice.org/sites/ftp.debian.org/debian" end resource = Resource.new { @url = new_url } - resource.download_strategy = CurlDownloadStrategy + resource.download_strategy = DownloadStrategyDetector.detect_from_url(new_url) resource.owner = Resource.new(formula.name) resource.version = forced_version if forced_version odie "No --version= argument specified!" unless resource.version From 98e48a9da7b0f1444d95f942fb3c1804cbc80991 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Wed, 24 Jan 2018 07:00:41 -0800 Subject: [PATCH 5/6] bump-formula-pr: regex escape urls in replacements. --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 1f60412ed4..ca3f4cfe89 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -232,12 +232,12 @@ module Homebrew end replacement_pairs += formula_spec.mirrors.map do |mirror| - [/ +mirror \"#{mirror}\"\n/m, ""] + [/ +mirror \"#{Regexp.escape(mirror)}\"\n/m, ""] end replacement_pairs += if new_url_hash [ - [formula_spec.url, new_url], + [/#{Regexp.escape(formula_spec.url)}/, new_url], [old_hash, new_hash], ] else @@ -250,7 +250,7 @@ module Homebrew backup_file = File.read(formula.path) unless ARGV.dry_run? if new_mirror - replacement_pairs << [/^( +)(url \"#{new_url}\"\n)/m, "\\1\\2\\1mirror \"#{new_mirror}\"\n"] + replacement_pairs << [/^( +)(url \"#{Regexp.escape(new_url)}\"\n)/m, "\\1\\2\\1mirror \"#{new_mirror}\"\n"] end if forced_version && forced_version != "0" From ccbe4945adbd9781433aaf688e457f4cd10cb6dc Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Wed, 24 Jan 2018 07:01:20 -0800 Subject: [PATCH 6/6] bump-formula-pr: improve version formula component regex. --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index ca3f4cfe89..7da0f93213 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -267,7 +267,7 @@ module Homebrew end elsif forced_version && forced_version == "0" if requested_spec == :stable - replacement_pairs << [/^ version \"[a-z\d+\.]+\"\n/m, ""] + replacement_pairs << [/^ version \"[\w\.\-\+]+\"\n/m, ""] elsif requested_spec == :devel replacement_pairs << [/( devel do.+?)^ +version \"[^\n]+\"\n(.+?end\n)/m, "\\1\\2"] end