Skip to content

Commit c929924

Browse files
omusKristofferC
authored andcommitted
Cache credentials on Pkg up (#28437)
1 parent 4381605 commit c929924

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

stdlib/Pkg/src/Operations.jl

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,33 +1162,36 @@ end
11621162
function up(ctx::Context, pkgs::Vector{PackageSpec})
11631163
# resolve upgrade levels to version specs
11641164
new_git = UUID[]
1165-
for pkg in pkgs
1166-
if pkg.uuid in keys(ctx.stdlibs)
1167-
pkg.version = VersionSpec()
1168-
continue
1169-
end
1170-
pkg.version isa UpgradeLevel || continue
1171-
level = pkg.version
1172-
info = manifest_info(ctx.env, pkg.uuid)
1173-
if info !== nothing && haskey(info, "repo-url")
1174-
pkg.repo = Types.GitRepo(info["repo-url"], info["repo-rev"])
1175-
new = handle_repos_add!(ctx, [pkg]; upgrade_or_add = (level == UPLEVEL_MAJOR))
1176-
append!(new_git, new)
1177-
else
1178-
if info !== nothing
1179-
pkg.uuid in keys(ctx.stdlibs) && continue
1180-
ver = VersionNumber(info["version"])
1181-
if level == UPLEVEL_FIXED
1182-
pkg.version = VersionNumber(info["version"])
1165+
Base.shred!(LibGit2.CachedCredentials()) do creds
1166+
for pkg in pkgs
1167+
if pkg.uuid in keys(ctx.stdlibs)
1168+
pkg.version = VersionSpec()
1169+
continue
1170+
end
1171+
pkg.version isa UpgradeLevel || continue
1172+
level = pkg.version
1173+
info = manifest_info(ctx.env, pkg.uuid)
1174+
if info !== nothing && haskey(info, "repo-url")
1175+
pkg.repo = Types.GitRepo(info["repo-url"], info["repo-rev"])
1176+
new = handle_repos_add!(ctx, [pkg]; credentials=creds,
1177+
upgrade_or_add = (level == UPLEVEL_MAJOR))
1178+
append!(new_git, new)
1179+
else
1180+
if info !== nothing
1181+
pkg.uuid in keys(ctx.stdlibs) && continue
1182+
ver = VersionNumber(info["version"])
1183+
if level == UPLEVEL_FIXED
1184+
pkg.version = VersionNumber(info["version"])
1185+
else
1186+
r = level == UPLEVEL_PATCH ? VersionRange(ver.major, ver.minor) :
1187+
level == UPLEVEL_MINOR ? VersionRange(ver.major) :
1188+
level == UPLEVEL_MAJOR ? VersionRange() :
1189+
error("unexpected upgrade level: $level")
1190+
pkg.version = VersionSpec(r)
1191+
end
11831192
else
1184-
r = level == UPLEVEL_PATCH ? VersionRange(ver.major, ver.minor) :
1185-
level == UPLEVEL_MINOR ? VersionRange(ver.major) :
1186-
level == UPLEVEL_MAJOR ? VersionRange() :
1187-
error("unexpected upgrade level: $level")
1188-
pkg.version = VersionSpec(r)
1193+
pkg.version = VersionSpec()
11891194
end
1190-
else
1191-
pkg.version = VersionSpec()
11921195
end
11931196
end
11941197
end

stdlib/Pkg/src/Types.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,12 @@ function handle_repos_develop!(ctx::Context, pkgs::AbstractVector{PackageSpec},
577577
end
578578
end
579579

580-
function handle_repos_add!(ctx::Context, pkgs::AbstractVector{PackageSpec}; upgrade_or_add::Bool=true)
580+
function handle_repos_add!(ctx::Context, pkgs::AbstractVector{PackageSpec};
581+
upgrade_or_add::Bool=true, credentials=nothing)
581582
# Always update the registry when adding
582583
UPDATED_REGISTRY_THIS_SESSION[] || Pkg.API.update_registry(ctx)
583-
Base.shred!(LibGit2.CachedCredentials()) do creds
584+
creds = credentials !== nothing ? credentials : LibGit2.CachedCredentials()
585+
try
584586
env = ctx.env
585587
new_uuids = UUID[]
586588
for pkg in pkgs
@@ -670,6 +672,8 @@ function handle_repos_add!(ctx::Context, pkgs::AbstractVector{PackageSpec}; upgr
670672
@assert pkg.version isa VersionNumber
671673
end
672674
return new_uuids
675+
finally
676+
creds !== credentials && Base.shred!(creds)
673677
end
674678
end
675679

0 commit comments

Comments
 (0)