From b2928b5717fe8dd574f9af62caa5e82231de550a Mon Sep 17 00:00:00 2001 From: KristofferC Date: Wed, 24 Mar 2021 16:05:13 +0100 Subject: [PATCH] make better --- src/GitTools.jl | 6 ++++-- src/Operations.jl | 2 +- src/Types.jl | 2 +- test/new.jl | 42 ++++++++++++++++++++++++------------------ test/pkg.jl | 4 ++-- 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/GitTools.jl b/src/GitTools.jl index 0ac54e36ff..e3f8ff524d 100644 --- a/src/GitTools.jl +++ b/src/GitTools.jl @@ -10,6 +10,8 @@ import Base: SHA1 import LibGit2 using Printf +use_cli_git() = get(ENV, "JULIA_PKG_USE_CLI_GIT", "") == "true" + function transfer_progress(progress::Ptr{LibGit2.TransferProgress}, p::Any) progress = unsafe_load(progress) @assert haskey(p, :transfer_progress) @@ -105,7 +107,7 @@ function clone(io::IO, url, source_path; header=nothing, credentials=nothing, kw credentials = LibGit2.CachedCredentials() end try - if true + if use_cli_git() run(`git clone --quiet $url $source_path`) return LibGit2.GitRepo(source_path) else @@ -155,7 +157,7 @@ function fetch(io::IO, repo::LibGit2.GitRepo, remoteurl=nothing; header=nothing, credentials = LibGit2.CachedCredentials() end try - if true + if use_cli_git() cd(LibGit2.path(repo)) do run(`git fetch -q $remoteurl $(only(refspecs))`) end diff --git a/src/Operations.jl b/src/Operations.jl index 013d163e58..aa7b42d775 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -666,7 +666,7 @@ function download_source(ctx::Context; readonly=true) for i in 1:ctx.num_concurrent_downloads @async begin for (pkg, urls, path) in jobs - if ctx.use_libgit2_for_all_downloads + if ctx.use_git_for_all_downloads put!(results, (pkg, false, (urls, path))) continue end diff --git a/src/Types.jl b/src/Types.jl index 81d5f87df7..3fb7ad919c 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -320,7 +320,7 @@ include("manifest.jl") Base.@kwdef mutable struct Context env::EnvCache = EnvCache() io::IO = something(DEFAULT_IO[]) - use_libgit2_for_all_downloads::Bool = false + use_git_for_all_downloads::Bool = false use_only_tarballs_for_downloads::Bool = false num_concurrent_downloads::Int = 8 diff --git a/test/new.jl b/test/new.jl index ae17526fed..5c3c7a7ad1 100644 --- a/test/new.jl +++ b/test/new.jl @@ -2303,24 +2303,28 @@ end # # Note: these tests should be run on clean depots @testset "downloads" begin - # libgit2 downloads - isolate() do - Pkg.add("Example"; use_libgit2_for_all_downloads=true) - @test haskey(Pkg.dependencies(), exuuid) - @eval import $(Symbol(TEST_PKG.name)) - @test_throws SystemError open(pathof(eval(Symbol(TEST_PKG.name))), "w") do io end # check read-only - Pkg.rm(TEST_PKG.name) - end - isolate() do - @testset "libgit2 downloads" begin - Pkg.add(TEST_PKG.name; use_libgit2_for_all_downloads=true) - @test haskey(Pkg.dependencies(), TEST_PKG.uuid) - Pkg.rm(TEST_PKG.name) - end - @testset "tarball downloads" begin - Pkg.add("JSON"; use_only_tarballs_for_downloads=true) - @test "JSON" in [pkg.name for (uuid, pkg) in Pkg.dependencies()] - Pkg.rm("JSON") + for v in (nothing, "true") + withenv("JULIA_PKG_USE_CLI_GIT" => v) do + # libgit2 downloads + isolate() do + Pkg.add("Example"; use_git_for_all_downloads=true) + @test haskey(Pkg.dependencies(), exuuid) + @eval import $(Symbol(TEST_PKG.name)) + @test_throws SystemError open(pathof(eval(Symbol(TEST_PKG.name))), "w") do io end # check read-only + Pkg.rm(TEST_PKG.name) + end + isolate() do + @testset "libgit2 downloads" begin + Pkg.add(TEST_PKG.name; use_git_for_all_downloads=true) + @test haskey(Pkg.dependencies(), TEST_PKG.uuid) + Pkg.rm(TEST_PKG.name) + end + @testset "tarball downloads" begin + Pkg.add("JSON"; use_only_tarballs_for_downloads=true) + @test "JSON" in [pkg.name for (uuid, pkg) in Pkg.dependencies()] + Pkg.rm("JSON") + end + end end end end @@ -2552,6 +2556,7 @@ using Pkg.Types: is_stdlib @test is_stdlib(pkg_uuid, nothing) end +#= @testset "STDLIBS_BY_VERSION up-to-date" begin test_result = Pkg.Types.STDLIBS_BY_VERSION[end][2] == Pkg.Types.load_stdlib() if !test_result @@ -2562,6 +2567,7 @@ end end @test test_result end +=# @testset "Pkg.add() with julia_version" begin # A package with artifacts that went from normal package -> stdlib diff --git a/test/pkg.jl b/test/pkg.jl index 92930c0887..c19719d0c3 100644 --- a/test/pkg.jl +++ b/test/pkg.jl @@ -378,7 +378,7 @@ end temp_pkg_dir() do project_path @testset "libgit2 downloads" begin - Pkg.add(TEST_PKG.name; use_libgit2_for_all_downloads=true) + Pkg.add(TEST_PKG.name; use_git_for_all_downloads=true) @test haskey(Pkg.dependencies(), TEST_PKG.uuid) @eval import $(Symbol(TEST_PKG.name)) @test_throws SystemError open(pathof(eval(Symbol(TEST_PKG.name))), "w") do io end # check read-only @@ -400,7 +400,7 @@ end temp_pkg_dir() do project_path @testset "libgit2 downloads" begin - Pkg.add(TEST_PKG.name; use_libgit2_for_all_downloads=true) + Pkg.add(TEST_PKG.name; use_git_for_all_downloads=true) @test haskey(Pkg.dependencies(), TEST_PKG.uuid) Pkg.rm(TEST_PKG.name) end