Skip to content

Commit 87f5509

Browse files
authored
[GitSource]: Only fetch() if the repository doesn't contain the hash (#120)
Flexing a _tiny_ bit of `LibGit2`-fu, we can avoid expensive (and race-triggering) `fetch()` calls on repositories that already contain the hash we desire.
1 parent e1e18b4 commit 87f5509

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Sources.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,12 @@ function download_source(source::GitSource; verbose::Bool = false, downloads_dir
162162
@info "Cached repository found in $(src_path)"
163163
# If we didn't just mercilessly obliterate the cached git repo, use it!
164164
LibGit2.with(LibGit2.GitRepo(src_path)) do repo
165-
LibGit2.fetch(repo)
165+
# Only bother to fetch the remote repository if it doesn't already have
166+
# the hash we want to build within it; this is not only faster, it avoids
167+
# race conditions when we have multiple builders on the same machine.
168+
if !LibGit2.iscommit(source.hash, repo)
169+
LibGit2.fetch(repo)
170+
end
166171
end
167172
else
168173
@info "Cloning $(source.url) to $(src_path)..."

0 commit comments

Comments
 (0)