Skip to content

Commit

Permalink
Cache credentials on Pkg up (#28437)
Browse files Browse the repository at this point in the history
  • Loading branch information
omus authored and KristofferC committed Feb 11, 2019
1 parent 4381605 commit c929924
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
53 changes: 28 additions & 25 deletions stdlib/Pkg/src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions stdlib/Pkg/src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit c929924

Please sign in to comment.