Skip to content

Commit

Permalink
Merge pull request #4418 from reitermarkus/vcs-strategies
Browse files Browse the repository at this point in the history
Refactor and fix VCS download strategies.
  • Loading branch information
MikeMcQuaid authored Jul 4, 2018
2 parents 319baa7 + 74ac070 commit 08cbbfa
Showing 1 changed file with 20 additions and 37 deletions.
57 changes: 20 additions & 37 deletions Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,39 +104,6 @@ def lzippath
def lhapath
"#{HOMEBREW_PREFIX}/opt/lha/bin/lha"
end

def cvspath
@cvspath ||= %W[
/usr/bin/cvs
#{HOMEBREW_PREFIX}/bin/cvs
#{HOMEBREW_PREFIX}/opt/cvs/bin/cvs
#{which("cvs")}
].find { |p| File.executable? p }
end

def hgpath
@hgpath ||= %W[
#{which("hg")}
#{HOMEBREW_PREFIX}/bin/hg
#{HOMEBREW_PREFIX}/opt/mercurial/bin/hg
].find { |p| File.executable? p }
end

def bzrpath
@bzrpath ||= %W[
#{which("bzr")}
#{HOMEBREW_PREFIX}/bin/bzr
#{HOMEBREW_PREFIX}/opt/bazaar/bin/bzr
].find { |p| File.executable? p }
end

def fossilpath
@fossilpath ||= %W[
#{which("fossil")}
#{HOMEBREW_PREFIX}/bin/fossil
#{HOMEBREW_PREFIX}/opt/fossil/bin/fossil
].find { |p| File.executable? p }
end
end

class VCSDownloadStrategy < AbstractDownloadStrategy
Expand Down Expand Up @@ -992,6 +959,10 @@ def initialize(name, resource)
end
end

def cvspath
@cvspath ||= which("cvs", PATH.new("/usr/bin", Formula["cvs"].opt_bin, ENV["PATH"]))
end

def source_modified_time
# Filter CVS's files because the timestamp for each of them is the moment
# of clone.
Expand Down Expand Up @@ -1045,6 +1016,10 @@ def initialize(name, resource)
@url = @url.sub(%r{^hg://}, "")
end

def hgpath
@hgpath ||= which("hg", PATH.new(Formula["mercurial"].opt_bin, ENV["PATH"]))
end

def stage
super

Expand Down Expand Up @@ -1093,6 +1068,10 @@ def initialize(name, resource)
ENV["BZR_HOME"] = HOMEBREW_TEMP
end

def bzrpath
@bzrpath ||= which("bzr", PATH.new(Formula["bazaar"].opt_bin, ENV["PATH"]))
end

def stage
# The export command doesn't work on checkouts
# See https://bugs.launchpad.net/bzr/+bug/897511
Expand All @@ -1101,13 +1080,13 @@ def stage
end

def source_modified_time
timestamp = Utils.popen_read("bzr", "log", "-l", "1", "--timezone=utc", cached_location.to_s)[/^timestamp: (.+)$/, 1]
timestamp = Utils.popen_read(bzrpath, "log", "-l", "1", "--timezone=utc", cached_location.to_s)[/^timestamp: (.+)$/, 1]
raise "Could not get any timestamps from bzr!" if timestamp.to_s.empty?
Time.parse timestamp
end

def last_commit
Utils.popen_read("bzr", "revno", cached_location.to_s).chomp
Utils.popen_read(bzrpath, "revno", cached_location.to_s).chomp
end

private
Expand Down Expand Up @@ -1136,6 +1115,10 @@ def initialize(name, resource)
@url = @url.sub(%r{^fossil://}, "")
end

def fossilpath
@fossilpath ||= which("fossil", PATH.new(Formula["fossil"].opt_bin, ENV["PATH"]))
end

def stage
super
args = [fossilpath, "open", cached_location]
Expand All @@ -1144,11 +1127,11 @@ def stage
end

def source_modified_time
Time.parse Utils.popen_read("fossil", "info", "tip", "-R", cached_location.to_s)[/^uuid: +\h+ (.+)$/, 1]
Time.parse Utils.popen_read(fossilpath, "info", "tip", "-R", cached_location.to_s)[/^uuid: +\h+ (.+)$/, 1]
end

def last_commit
Utils.popen_read("fossil", "info", "tip", "-R", cached_location.to_s)[/^uuid: +(\h+) .+$/, 1]
Utils.popen_read(fossilpath, "info", "tip", "-R", cached_location.to_s)[/^uuid: +(\h+) .+$/, 1]
end

private
Expand Down

0 comments on commit 08cbbfa

Please sign in to comment.