Skip to content

Commit

Permalink
Use Compat.uuid5
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Feb 7, 2020
1 parent 8c135cd commit 0805fff
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 25 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ uuid = "33c8b6b6-d38a-422a-b730-caa89a2f386c"
version = "0.1.0"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
Compat = "3.2"
julia = "0.7, 1"

[extras]
Expand Down
25 changes: 1 addition & 24 deletions src/ProgressLogging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,10 @@ module ProgressLogging
export @progress, @progressid, @withprogress, @logprogress

using Base.Meta: isexpr
using Compat: uuid5 # for Julia 1.0
using UUIDs: UUID, uuid4
using Logging: Logging, @logmsg, LogLevel

if VERSION >= v"1.1-"
using UUIDs: uuid5
else
import SHA
function uuid5(ns::UUID, name::String)
nsbytes = zeros(UInt8, 16)
nsv = ns.value
for idx in Base.OneTo(16)
nsbytes[idx] = nsv >> 120
nsv = nsv << 8
end
hash_result = SHA.sha1(append!(nsbytes, convert(Vector{UInt8}, codeunits(unescape_string(name)))))
# set version number to 5
hash_result[7] = (hash_result[7] & 0x0F) | (0x50)
hash_result[9] = (hash_result[9] & 0x3F) | (0x80)
v = zero(UInt128)
#use only the first 16 bytes of the SHA1 hash
for idx in Base.OneTo(16)
v = (v << 0x08) | hash_result[idx]
end
return UUID(v)
end
end

const ProgressLevel = LogLevel(-1)

"""
Expand Down

0 comments on commit 0805fff

Please sign in to comment.