Skip to content

Commit 7373f53

Browse files
Refactor version range spacing normalization.
1 parent 5b4b9ff commit 7373f53

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/Compress.jl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,28 @@ function compress(path::AbstractString, uncompressed::Dict,
7676
inverted = Dict{Pair{String,Any},Vector{VersionNumber}}()
7777
for (ver, data) in uncompressed, (key, val) in data
7878
val isa Base.UUID && (val = string(val))
79-
# Existing version ranges in `Compat.toml` files are stored without spaces.
80-
# New version ranges are added with spaces in their string representation.
81-
# Remove all spaces, so that equal version ranges compare equal as strings.
82-
# This is a temporary work-around that will become unnecessary when
83-
# "all this is rewritten to use VersionNumbers", as suggested above.
84-
#
85-
# The source of the spaces is https://github.com/JuliaLang/Pkg.jl/pull/3580.
86-
val = replace(string(val), " " => "")
87-
push!(get!(inverted, key => val, VersionNumber[]), ver)
79+
push!(get!(inverted, key => unspace_hyphen(val), VersionNumber[]), ver)
8880
end
8981
compressed = Dict{String,Dict{String,Any}}()
9082
for ((k, v), vers) in inverted
9183
for r in compress_versions(versions, sort!(vers)).ranges
92-
# Remove the version range spaces also in the keys.
93-
get!(compressed, replace(string(r), " " => ""), Dict{String,Any}())[k] = v
84+
get!(compressed, unspace_hyphen(string(r)), Dict{String, Any}())[k] = v
9485
end
9586
end
9687
return compressed
9788
end
9889

90+
# Existing version ranges in `Compat.toml` files are stored without spaces
91+
# around hyphens. New version ranges are added with spaces in their string
92+
# representation. Remove all spaces, so that equal version ranges compare
93+
# equal as strings. This is a temporary work-around that will become
94+
# unnecessary when "all this is rewritten to use VersionNumbers", as
95+
# suggested above.
96+
#
97+
# The source of the spaces is https://github.com/JuliaLang/Pkg.jl/pull/3580.
98+
unspace_hyphen(x::AbstractString) = replace(x, " - " => "-")
99+
unspace_hyphen(x::AbstractVector) = unspace_hyphen.(x)
100+
99101
function save(path::AbstractString, uncompressed::Dict,
100102
versions::Vector{VersionNumber} = load_versions(path))
101103
compressed = compress(path, uncompressed)

0 commit comments

Comments
 (0)