Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache credentials on Pkg up #28437

Merged
merged 1 commit into from
Aug 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using git diff --ignore-space-change this is more comprehensible:

diff --git a/stdlib/Pkg/src/Operations.jl b/stdlib/Pkg/src/Operations.jl
index 547cebdc75..63cf3ad6f2 100644
--- a/stdlib/Pkg/src/Operations.jl
+++ b/stdlib/Pkg/src/Operations.jl
@@ -1162,6 +1162,7 @@ end
 function up(ctx::Context, pkgs::Vector{PackageSpec})
     # resolve upgrade levels to version specs
     new_git = UUID[]
+    Base.shred!(LibGit2.CachedCredentials()) do creds
         for pkg in pkgs
             if pkg.uuid in keys(ctx.stdlibs)
                 pkg.version = VersionSpec()
@@ -1172,7 +1173,8 @@ function up(ctx::Context, pkgs::Vector{PackageSpec})
             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))
+                new = handle_repos_add!(ctx, [pkg]; credentials=creds,
+                                        upgrade_or_add = (level == UPLEVEL_MAJOR))
                 append!(new_git, new)
             else
                 if info !== nothing
@@ -1192,6 +1194,7 @@ function up(ctx::Context, pkgs::Vector{PackageSpec})
                 end
             end
         end
+    end
     # resolve & apply package versions
     resolve_versions!(ctx, pkgs)
     new_apply = apply_versions(ctx, pkgs)

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