Skip to content

Commit fc9fc33

Browse files
KristofferCIanButterworth
authored andcommitted
add some missing hash definitions (#4228)
(cherry picked from commit cb88750)
1 parent de7f1cf commit fc9fc33

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Types.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ end
8585

8686
Base.:(==)(r1::GitRepo, r2::GitRepo) =
8787
r1.source == r2.source && r1.rev == r2.rev && r1.subdir == r2.subdir
88-
88+
Base.hash(r::GitRepo, h::UInt) =
89+
foldr(hash, [r.source, r.rev, r.subdir], init=h)
8990

9091
mutable struct PackageSpec
9192
name::Union{Nothing,String}
@@ -119,11 +120,15 @@ PackageSpec(name::AbstractString, uuid::UUID) = PackageSpec(;name=name, uuid=uui
119120
PackageSpec(name::AbstractString, version::VersionTypes) = PackageSpec(;name=name, version=version)::PackageSpec
120121
PackageSpec(n::AbstractString, u::UUID, v::VersionTypes) = PackageSpec(;name=n, uuid=u, version=v)::PackageSpec
121122

123+
# XXX: These definitions are a bit fishy. It seems to be used in an `==` call in status printing
122124
function Base.:(==)(a::PackageSpec, b::PackageSpec)
123125
return a.name == b.name && a.uuid == b.uuid && a.version == b.version &&
124126
a.tree_hash == b.tree_hash && a.repo == b.repo && a.path == b.path &&
125127
a.pinned == b.pinned
126128
end
129+
function Base.hash(a::PackageSpec, h::UInt)
130+
return foldr(hash, [a.name, a.uuid, a.version, a.tree_hash, a.repo, a.path, a.pinned], init=h)
131+
end
127132

128133
function err_rep(pkg::PackageSpec)
129134
x = pkg.name !== nothing && pkg.uuid !== nothing ? x = "$(pkg.name) [$(string(pkg.uuid)[1:8])]" :

test/new.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3184,4 +3184,6 @@ end
31843184
@test occursin("[loaded: v0.5.4]", out)
31853185
end
31863186

3187+
@test allunique(unique([Pkg.PackageSpec(path="foo"), Pkg.PackageSpec(path="foo")]))
3188+
31873189
end #module

0 commit comments

Comments
 (0)