forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.jl
28 lines (24 loc) · 852 Bytes
/
cache.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Cache
using Base.Git, ..Types
path(pkg::String) = abspath(".cache", pkg)
function prefetch{S<:String}(pkg::String, url::String, sha1s::Vector{S})
isdir(".cache") || mkdir(".cache")
cache = path(pkg)
if !isdir(cache)
info("Cloning cache of $pkg from $url")
try Git.run(`clone -q --mirror $url $cache`)
catch
run(`rm -rf $cache`)
rethrow()
end
end
Git.set_remote_url(url, dir=cache)
if !all(sha1->Git.iscommit(sha1, dir=cache), sha1s)
info("Updating cache of $pkg...")
Git.success(`remote update`, dir=cache) ||
error("couldn't update $cache using `git remote update`")
end
filter(sha1->!Git.iscommit(sha1, dir=cache), sha1s)
end
prefetch(pkg::String, url::String, sha1::String...) = prefetch(pkg, url, String[sha1...])
end # module