From c45ae5d50559a3d4ea343235f0f1106d830c7e86 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Fri, 3 Aug 2018 22:55:41 -0500 Subject: [PATCH] Cache credentials on Pkg up --- stdlib/Pkg/src/Operations.jl | 53 +++++++++++++++++++----------------- stdlib/Pkg/src/Types.jl | 8 ++++-- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/stdlib/Pkg/src/Operations.jl b/stdlib/Pkg/src/Operations.jl index 547cebdc75842..63cf3ad6f273a 100644 --- a/stdlib/Pkg/src/Operations.jl +++ b/stdlib/Pkg/src/Operations.jl @@ -1162,33 +1162,36 @@ end function up(ctx::Context, pkgs::Vector{PackageSpec}) # resolve upgrade levels to version specs new_git = UUID[] - for pkg in pkgs - if pkg.uuid in keys(ctx.stdlibs) - pkg.version = VersionSpec() - continue - end - pkg.version isa UpgradeLevel || continue - level = pkg.version - info = manifest_info(ctx.env, pkg.uuid) - if info !== nothing && haskey(info, "repo-url") - pkg.repo = Types.GitRepo(info["repo-url"], info["repo-rev"]) - new = handle_repos_add!(ctx, [pkg]; upgrade_or_add = (level == UPLEVEL_MAJOR)) - append!(new_git, new) - else - if info !== nothing - pkg.uuid in keys(ctx.stdlibs) && continue - ver = VersionNumber(info["version"]) - if level == UPLEVEL_FIXED - pkg.version = VersionNumber(info["version"]) + Base.shred!(LibGit2.CachedCredentials()) do creds + for pkg in pkgs + if pkg.uuid in keys(ctx.stdlibs) + pkg.version = VersionSpec() + continue + end + pkg.version isa UpgradeLevel || continue + level = pkg.version + info = manifest_info(ctx.env, pkg.uuid) + if info !== nothing && haskey(info, "repo-url") + pkg.repo = Types.GitRepo(info["repo-url"], info["repo-rev"]) + new = handle_repos_add!(ctx, [pkg]; credentials=creds, + upgrade_or_add = (level == UPLEVEL_MAJOR)) + append!(new_git, new) + else + if info !== nothing + pkg.uuid in keys(ctx.stdlibs) && continue + ver = VersionNumber(info["version"]) + if level == UPLEVEL_FIXED + pkg.version = VersionNumber(info["version"]) + else + r = level == UPLEVEL_PATCH ? VersionRange(ver.major, ver.minor) : + level == UPLEVEL_MINOR ? VersionRange(ver.major) : + level == UPLEVEL_MAJOR ? VersionRange() : + error("unexpected upgrade level: $level") + pkg.version = VersionSpec(r) + end else - r = level == UPLEVEL_PATCH ? VersionRange(ver.major, ver.minor) : - level == UPLEVEL_MINOR ? VersionRange(ver.major) : - level == UPLEVEL_MAJOR ? VersionRange() : - error("unexpected upgrade level: $level") - pkg.version = VersionSpec(r) + pkg.version = VersionSpec() end - else - pkg.version = VersionSpec() end end end diff --git a/stdlib/Pkg/src/Types.jl b/stdlib/Pkg/src/Types.jl index 0a247849650d7..d1e6f5b025269 100644 --- a/stdlib/Pkg/src/Types.jl +++ b/stdlib/Pkg/src/Types.jl @@ -577,10 +577,12 @@ function handle_repos_develop!(ctx::Context, pkgs::AbstractVector{PackageSpec}, end end -function handle_repos_add!(ctx::Context, pkgs::AbstractVector{PackageSpec}; upgrade_or_add::Bool=true) +function handle_repos_add!(ctx::Context, pkgs::AbstractVector{PackageSpec}; + upgrade_or_add::Bool=true, credentials=nothing) # Always update the registry when adding UPDATED_REGISTRY_THIS_SESSION[] || Pkg.API.update_registry(ctx) - Base.shred!(LibGit2.CachedCredentials()) do creds + creds = credentials !== nothing ? credentials : LibGit2.CachedCredentials() + try env = ctx.env new_uuids = UUID[] for pkg in pkgs @@ -670,6 +672,8 @@ function handle_repos_add!(ctx::Context, pkgs::AbstractVector{PackageSpec}; upgr @assert pkg.version isa VersionNumber end return new_uuids + finally + creds !== credentials && Base.shred!(creds) end end