Skip to content

Commit

Permalink
rename to strhash
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Oct 10, 2024
1 parent c189bb5 commit d023f35
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions xmake/core/base/hash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ function hash.uuid(str)
return hash.uuid4(str)
end

-- generate hash32, e.g. "91e8ecf1"
function hash.hash32(str)
-- generate hash32 from string, e.g. "91e8ecf1"
function hash.strhash32(str)
return hash.uuid4(str):split("-", {plain = true})[1]:lower()
end

-- generate hash128, e.g. "91e8ecf1417f4edfa574e22d7d8d204a"
function hash.hash128(str)
-- generate hash128 from string, e.g. "91e8ecf1417f4edfa574e22d7d8d204a"
function hash.strhash128(str)
return hash.uuid4(str):replace("-", "", {plain = true}):lower()
end

Expand Down
8 changes: 4 additions & 4 deletions xmake/core/sandbox/modules/hash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ function sandbox_hash.xxhash128(file_or_data)
end

-- generate hash32 from string
function sandbox_hash.hash32(str)
local hash32, errors = hash.hash32(str)
function sandbox_hash.strhash32(str)
local hash32, errors = hash.strhash32(str)
if not hash32 then
raise("cannot generate hash32 for %s, %s", str, errors or "unknown errors")
end
return hash32
end

-- generate hash128 from string
function sandbox_hash.hash128(str)
local hash128, errors = hash.hash128(str)
function sandbox_hash.strhash128(str)
local hash128, errors = hash.strhash128(str)
if not hash128 then
raise("cannot generate hash128 for %s, %s", str, errors or "unknown errors")
end
Expand Down
4 changes: 2 additions & 2 deletions xmake/includes/xrepo/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
-- @endcode
--
function xrepo_addenvs(envs)
local packagename = "__xrepo_addenvs_" .. hash.hash32(tostring(envs))
local packagename = "__xrepo_addenvs_" .. hash.strhash32(tostring(envs))
package(packagename)
on_load(function (package)
if type(envs) == "function" then
Expand Down Expand Up @@ -61,7 +61,7 @@ end
--
function xrepo_addenv(name, ...)
local args = table.pack(...)
local packagename = "__xrepo_addenv_" .. name .. hash.hash32(table.concat(args))
local packagename = "__xrepo_addenv_" .. name .. hash.strhash32(table.concat(args))
package(packagename)
on_load(function (package)
package:addenv(name, table.unpack(args))
Expand Down
2 changes: 1 addition & 1 deletion xmake/modules/private/action/require/impl/repository.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function _get_packagedir_from_locked_repo(packagename, locked_repo)
break
end
end
local reponame = hash.hash128(locked_repo.url .. (locked_repo.commit or "")) .. ".lock"
local reponame = hash.strhash128(locked_repo.url .. (locked_repo.commit or "")) .. ".lock"

-- get local repodir
local repodir_local
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function main(requireinfo, opt)
if key == "" then
key = "_" -- we need to generate a fixed hash value
end
return hash.hash32(key)
return hash.strhash32(key)
else
return key
end
Expand Down
2 changes: 1 addition & 1 deletion xmake/plugins/pack/nsis/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ end

-- get unique tag
function _get_unique_tag(content)
return hash.hash32(content)
return hash.strhash32(content)
end

-- translate the file path
Expand Down

0 comments on commit d023f35

Please sign in to comment.