Adding CVS and Mercurial download strategies.

This commit is contained in:
Austin Ziegler 2009-09-27 19:30:39 -04:00 committed by Max Howell
parent c61d96529c
commit 668e3ee080
2 changed files with 69 additions and 0 deletions

View File

@ -129,3 +129,70 @@ class GitDownloadStrategy <AbstractDownloadStrategy
end end
end end
end end
class CVSDownloadStrategy <AbstractDownloadStrategy
def fetch
ohai "Checking out #{@url}"
@co=HOMEBREW_CACHE+@unique_token
# URL of cvs cvs://:pserver:anoncvs@www.gccxml.org:/cvsroot/GCC_XML:gccxml
# will become:
# cvs -d :pserver:anoncvs@www.gccxml.org:/cvsroot/GCC_XML login
# cvs -d :pserver:anoncvs@www.gccxml.org:/cvsroot/GCC_XML co gccxml
mod, url = split_url(@url)
unless @co.exist?
Dir.chdir HOMEBREW_CACHE do
safe_system '/usr/bin/cvs', '-d', url, 'login'
safe_system '/usr/bin/cvs', '-d', url, 'checkout', '-d', @unique_token, mod
end
else
# TODO cvs up?
puts "Repository already checked out"
end
end
def stage
FileUtils.cp_r(Dir[HOMEBREW_CACHE+@unique_token+"*"], Dir.pwd)
require 'find'
Find.find(Dir.pwd) do |path|
if FileTest.directory?(path) && File.basename(path) == "CVS"
Find.prune
FileUtil.rm_r path, :force => true
end
end
end
private
def split_url(in_url)
parts=in_url.sub(%r[^cvs://], '').split(/:/)
mod=parts.pop
url=parts.join(':')
[ mod, url ]
end
end
class MercurialDownloadStrategy <AbstractDownloadStrategy
def fetch
ohai "Cloning #{@url}"
@clone=HOMEBREW_CACHE+@unique_token
url=@url.sub(%r[^hg://], '')
unless @clone.exist?
safe_system 'hg', 'clone', url, @clone
else
# TODO hg pull?
puts "Repository already cloned"
end
end
def stage
dst=Dir.getwd
Dir.chdir @clone do
# http://stackoverflow.com/questions/160608/how-to-do-a-git-export-like-svn-export
safe_system 'hg', 'archive', '-y', '-t', 'files', dst
end
end
end

View File

@ -101,6 +101,8 @@ class Formula
# reimplement if we don't autodetect the download strategy you require # reimplement if we don't autodetect the download strategy you require
def download_strategy def download_strategy
case url case url
when %r[^cvs://] then CVSDownloadStrategy
when %r[^hg://] then MercurialDownloadStrategy
when %r[^svn://] then SubversionDownloadStrategy when %r[^svn://] then SubversionDownloadStrategy
when %r[^git://] then GitDownloadStrategy when %r[^git://] then GitDownloadStrategy
when %r[^http://(.+?\.)?googlecode\.com/svn] then SubversionDownloadStrategy when %r[^http://(.+?\.)?googlecode\.com/svn] then SubversionDownloadStrategy