Skip to content

Commit b1ec6de

Browse files
authored
Fix invalidations from Pair(obj) methods (#2695)
xref sbromberger/LightGraphs.jl#1581
1 parent 002fa4e commit b1ec6de

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

src/API.jl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,19 +1491,21 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
14911491
pkgerror("Did not find path `$(repo_source)` for $(err_rep(pkg))")
14921492
end
14931493
repo_path = Types.add_repo_cache_path(repo_source)
1494-
LibGit2.with(GitTools.ensure_clone(ctx.io, repo_path, repo_source; isbare=true)) do repo
1495-
# We only update the clone if the tree hash can't be found
1496-
tree_hash_object = tree_hash(repo, string(pkg.tree_hash))
1497-
if tree_hash_object === nothing
1498-
GitTools.fetch(ctx.io, repo, repo_source; refspecs=Types.refspecs)
1494+
let repo_source=repo_source
1495+
LibGit2.with(GitTools.ensure_clone(ctx.io, repo_path, repo_source; isbare=true)) do repo
1496+
# We only update the clone if the tree hash can't be found
14991497
tree_hash_object = tree_hash(repo, string(pkg.tree_hash))
1498+
if tree_hash_object === nothing
1499+
GitTools.fetch(ctx.io, repo, repo_source; refspecs=Types.refspecs)
1500+
tree_hash_object = tree_hash(repo, string(pkg.tree_hash))
1501+
end
1502+
if tree_hash_object === nothing
1503+
pkgerror("Did not find tree_hash $(pkg.tree_hash) for $(err_rep(pkg))")
1504+
end
1505+
mkpath(sourcepath)
1506+
GitTools.checkout_tree_to_path(repo, tree_hash_object, sourcepath)
1507+
push!(new_git, pkg.uuid)
15001508
end
1501-
if tree_hash_object === nothing
1502-
pkgerror("Did not find tree_hash $(pkg.tree_hash) for $(err_rep(pkg))")
1503-
end
1504-
mkpath(sourcepath)
1505-
GitTools.checkout_tree_to_path(repo, tree_hash_object, sourcepath)
1506-
push!(new_git, pkg.uuid)
15071509
end
15081510
end
15091511

src/GitTools.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,10 @@ function fetch(io::IO, repo::LibGit2.GitRepo, remoteurl=nothing; header=nothing,
158158
end
159159
try
160160
if use_cli_git()
161-
cd(LibGit2.path(repo)) do
162-
run(`git fetch -q $remoteurl $(only(refspecs))`)
161+
let remoteurl=remoteurl
162+
cd(LibGit2.path(repo)) do
163+
run(`git fetch -q $remoteurl $(only(refspecs))`)
164+
end
163165
end
164166
else
165167
return LibGit2.fetch(repo; remoteurl=remoteurl, callbacks=callbacks, refspecs=refspecs, kwargs...)

src/Types.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,9 @@ function handle_repo_add!(ctx::Context, pkg::PackageSpec)
705705
end
706706

707707
let repo_source = repo_source
708-
LibGit2.with(GitTools.ensure_clone(ctx.io, add_repo_cache_path(repo_source), repo_source; isbare=true)) do repo
708+
# The type-assertions below are necessary presumably due to julia#36454
709+
LibGit2.with(GitTools.ensure_clone(ctx.io, add_repo_cache_path(repo_source::Union{Nothing,String}), repo_source::Union{Nothing,String}; isbare=true)) do repo
710+
repo_source_typed = repo_source::Union{Nothing,String}
709711
GitTools.check_valid_HEAD(repo)
710712

711713
# If the user didn't specify rev, assume they want the default (master) branch if on a branch, otherwise the current commit
@@ -717,7 +719,7 @@ function handle_repo_add!(ctx::Context, pkg::PackageSpec)
717719
fetched = false
718720
if obj_branch === nothing
719721
fetched = true
720-
GitTools.fetch(ctx.io, repo, repo_source; refspecs=refspecs)
722+
GitTools.fetch(ctx.io, repo, repo_source_typed; refspecs=refspecs)
721723
obj_branch = get_object_or_branch(repo, pkg.repo.rev)
722724
if obj_branch === nothing
723725
pkgerror("Did not find rev $(pkg.repo.rev) in repository")
@@ -729,7 +731,7 @@ function handle_repo_add!(ctx::Context, pkg::PackageSpec)
729731
innerentry = manifest_info(ctx.env.manifest, pkg.uuid)
730732
ispinned = innerentry !== nothing && innerentry.pinned
731733
if isbranch && !fetched && !ispinned
732-
GitTools.fetch(ctx.io, repo, repo_source; refspecs=refspecs)
734+
GitTools.fetch(ctx.io, repo, repo_source_typed; refspecs=refspecs)
733735
gitobject, isbranch = get_object_or_branch(repo, pkg.repo.rev)
734736
end
735737

0 commit comments

Comments
 (0)