From f5cd1e38707acdf70412afa8060f3c2857ba204f Mon Sep 17 00:00:00 2001 From: Niclas Carlsson Date: Tue, 5 May 2015 19:02:01 +0300 Subject: [PATCH] Speed up Pkg.update() by adding a vectorized version of Git.iscommit() and using it in Cache.prefetch(). --- base/pkg/cache.jl | 6 ++++-- base/pkg/git.jl | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/base/pkg/cache.jl b/base/pkg/cache.jl index 3850ca5a3058c..f6c0a2be7f308 100644 --- a/base/pkg/cache.jl +++ b/base/pkg/cache.jl @@ -40,12 +40,14 @@ function prefetch(pkg::AbstractString, url::AbstractString, sha1s::Vector) end end Git.set_remote_url(url, dir=cache) - if !all(sha1->Git.iscommit(sha1, dir=cache), sha1s) + in_cache = Git.iscommit(sha1s, dir=cache) + if !all(in_cache) info("Updating cache of $pkg...") Git.success(`remote update`, dir=cache) || error("couldn't update $cache using `git remote update`") + in_cache = Git.iscommit(sha1s, dir=cache) end - filter(sha1->!Git.iscommit(sha1, dir=cache), sha1s) + sha1s[!in_cache] end prefetch(pkg::AbstractString, url::AbstractString, sha1::AbstractString...) = prefetch(pkg, url, AbstractString[sha1...]) diff --git a/base/pkg/git.jl b/base/pkg/git.jl index 28a5b6ea5a2c1..8be26b94a48dc 100644 --- a/base/pkg/git.jl +++ b/base/pkg/git.jl @@ -58,6 +58,10 @@ attached(; dir="") = success(`symbolic-ref -q HEAD`, dir=dir) branch(; dir="") = readchomp(`rev-parse --symbolic-full-name --abbrev-ref HEAD`, dir=dir) head(; dir="") = readchomp(`rev-parse HEAD`, dir=dir) +function iscommit(sha1s::Vector; dir="") + indexin(sha1s,split(readchomp(`log --all --format=%H`, dir=dir),"\n")).!=0 +end + immutable State head::ASCIIString index::ASCIIString