diff options
| author | Jack Nagel | 2014-12-06 12:29:16 -0500 | 
|---|---|---|
| committer | Jack Nagel | 2014-12-06 15:02:49 -0500 | 
| commit | fd4eebcb23d72df9dd6253751b637d2eac81faae (patch) | |
| tree | 791e002f89e9d885b3e90785a88b10f809c54bde | |
| parent | 61982489384e55ad7214383e014c72c7a9f00e9b (diff) | |
| download | homebrew-fd4eebcb23d72df9dd6253751b637d2eac81faae.tar.bz2 | |
Move fetch implementation into VCS strategy superclass
| -rw-r--r-- | Library/Homebrew/download_strategy.rb | 103 | 
1 files changed, 20 insertions, 83 deletions
| diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index d18971d05..5ffe1109d 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -46,6 +46,21 @@ class VCSDownloadStrategy < AbstractDownloadStrategy      @clone = HOMEBREW_CACHE.join(cache_filename)    end +  def fetch +    ohai "Cloning #{@url}" + +    if cached_location.exist? && repo_valid? +      puts "Updating #{cached_location}" +      update +    elsif cached_location.exist? +      puts "Removing invalid repository from cache" +      clear_cache +      clone_repo +    else +      clone_repo +    end +  end +    def cached_location      @clone    end @@ -372,15 +387,11 @@ class SubversionDownloadStrategy < VCSDownloadStrategy    end    def fetch -    ohai "Checking out #{@url}" - -    clear_cache unless @url.chomp("/") == repo_url or quiet_system 'svn', 'switch', @url, @clone - -    if @clone.exist? and not repo_valid? -      puts "Removing invalid SVN repo from cache" -      clear_cache -    end +    clear_cache unless @url.chomp("/") == repo_url or quiet_system "svn", "switch", @url, @clone +    super +  end +  def clone_repo      case @ref_type      when :revision        fetch_repo @clone, @url, @ref @@ -396,6 +407,7 @@ class SubversionDownloadStrategy < VCSDownloadStrategy        fetch_repo @clone, @url      end    end +  alias_method :update, :clone_repo    def stage      quiet_safe_system 'svn', 'export', '--force', @clone, Dir.pwd @@ -468,21 +480,6 @@ class GitDownloadStrategy < VCSDownloadStrategy      @shallow = resource.specs.fetch(:shallow) { true }    end -  def fetch -    ohai "Cloning #@url" - -    if @clone.exist? && repo_valid? -      puts "Updating #@clone" -      update -    elsif @clone.exist? -      puts "Removing invalid .git repo from cache" -      clear_cache -      clone_repo -    else -      clone_repo -    end -  end -    def stage      dst = Dir.getwd      @clone.cd do @@ -597,21 +594,6 @@ class GitDownloadStrategy < VCSDownloadStrategy  end  class CVSDownloadStrategy < VCSDownloadStrategy -  def fetch -    ohai "Checking out #{@url}" - -    if @clone.exist? && repo_valid? -      puts "Updating #{@clone}" -      update -    elsif @clone.exist? -      puts "Removing invalid CVS repo from cache" -      clear_cache -      clone_repo -    else -      clone_repo -    end -  end -    def stage      FileUtils.cp_r Dir[@clone+"{.}"], Dir.pwd    end @@ -661,21 +643,6 @@ class CVSDownloadStrategy < VCSDownloadStrategy  end  class MercurialDownloadStrategy < VCSDownloadStrategy -  def fetch -    ohai "Cloning #{@url}" - -    if @clone.exist? && repo_valid? -      puts "Updating #{@clone}" -      update -    elsif @clone.exist? -      puts "Removing invalid hg repo from cache" -      clear_cache -      clone_repo -    else -      clone_repo -    end -  end -    def stage      dst = Dir.getwd      @clone.cd do @@ -717,21 +684,6 @@ class MercurialDownloadStrategy < VCSDownloadStrategy  end  class BazaarDownloadStrategy < VCSDownloadStrategy -  def fetch -    ohai "Cloning #{@url}" - -    if @clone.exist? && repo_valid? -      puts "Updating #{@clone}" -      update -    elsif @clone.exist? -      puts "Removing invalid bzr repo from cache" -      clear_cache -      clone_repo -    else -      clone_repo -    end -  end -    def stage      # FIXME: The export command doesn't work on checkouts      # See https://bugs.launchpad.net/bzr/+bug/897511 @@ -768,21 +720,6 @@ class BazaarDownloadStrategy < VCSDownloadStrategy  end  class FossilDownloadStrategy < VCSDownloadStrategy -  def fetch -    ohai "Cloning #{@url}" - -    if @clone.exist? && repo_valid? -      puts "Updating #{@clone}" -      update -    elsif @clone.exist? -      puts "Removing invalid fossil repo from cache" -      clear_cache -      clone_repo -    else -      clone_repo -    end -  end -    def stage      # TODO: The 'open' and 'checkout' commands are very noisy and have no '-q' option.      safe_system fossilpath, 'open', @clone | 
