mirror of
https://github.com/Ed94/pikuma_ps1.git
synced 2026-08-07 16:18:51 +00:00
some saved by cahcing git path resolution.
This commit is contained in:
+7
-2
@@ -98,10 +98,14 @@ local BYTE_DIGIT_9 = 57 -- '9'
|
|||||||
-- `C:\\projects\\Pikuma\\ps1\\...` breaks portability. Git gives us
|
-- `C:\\projects\\Pikuma\\ps1\\...` breaks portability. Git gives us
|
||||||
-- the canonical repo root regardless of where it lives.
|
-- the canonical repo root regardless of where it lives.
|
||||||
|
|
||||||
--- Resolve the repo root via `git rev-parse --show-toplevel`. Returns a
|
--- Resolve the repo root via `git rev-parse --show-toplevel` (cached).
|
||||||
--- path with a trailing separator, or nil if not in a git repo.
|
--- Returns a path with a trailing separator, or nil if not in a git repo.
|
||||||
--- @return string|nil
|
--- @return string|nil
|
||||||
local function find_repo_root()
|
local function find_repo_root()
|
||||||
|
-- Cached in `package.loaded` (process-global) so all 8 entry scripts
|
||||||
|
-- + passes scripts share one git call. Without this, git rev-parse
|
||||||
|
-- runs once per script load = 8 × ~150ms = 1.2s wasted per build.
|
||||||
|
if package.loaded.__duffle_repo_root__ then return package.loaded.__duffle_repo_root__ end
|
||||||
local p = io.popen("git rev-parse --show-toplevel 2>nul")
|
local p = io.popen("git rev-parse --show-toplevel 2>nul")
|
||||||
local root
|
local root
|
||||||
if p then
|
if p then
|
||||||
@@ -110,6 +114,7 @@ local function find_repo_root()
|
|||||||
end
|
end
|
||||||
if not root or root == "" then return nil end
|
if not root or root == "" then return nil end
|
||||||
if not root:match("[/\\]$") then root = root .. "/" end
|
if not root:match("[/\\]$") then root = root .. "/" end
|
||||||
|
package.loaded.__duffle_repo_root__ = root
|
||||||
return root
|
return root
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -28,10 +28,18 @@
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
--- Resolve the repo root via git. Returns a normalized path with a
|
-- Cache key for the repo root. Stored in `package.loaded` (process-
|
||||||
--- trailing forward-slash, or nil if not in a git repo.
|
-- global) so all 8 entry scripts + passes scripts share one git call.
|
||||||
|
-- Without this cache, `git rev-parse --show-toplevel` runs once per
|
||||||
|
-- script load = 8 × ~150ms = 1.2s wasted per build on Windows.
|
||||||
|
local CACHE_KEY = "__duffle_repo_root__"
|
||||||
|
|
||||||
|
--- Resolve the repo root via git (cached after first call).
|
||||||
|
--- Returns a normalized path with a trailing forward-slash, or nil
|
||||||
|
--- if not in a git repo.
|
||||||
--- @return string|nil
|
--- @return string|nil
|
||||||
local function find_repo_root()
|
local function find_repo_root()
|
||||||
|
if package.loaded[CACHE_KEY] then return package.loaded[CACHE_KEY] end
|
||||||
local p = io.popen("git rev-parse --show-toplevel 2>nul")
|
local p = io.popen("git rev-parse --show-toplevel 2>nul")
|
||||||
local root
|
local root
|
||||||
if p then
|
if p then
|
||||||
@@ -43,11 +51,13 @@ local function find_repo_root()
|
|||||||
-- `\` + `/` confuses LuaJIT's file APIs).
|
-- `\` + `/` confuses LuaJIT's file APIs).
|
||||||
root = root:gsub("\\", "/")
|
root = root:gsub("\\", "/")
|
||||||
if not root:match("/$") then root = root .. "/" end
|
if not root:match("/$") then root = root .. "/" end
|
||||||
|
package.loaded[CACHE_KEY] = root
|
||||||
return root
|
return root
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set `package.path` (for `require("duffle")` + `require("passes.X")`)
|
--- Set `package.path` (for `require("duffle")` + `require("passes.X")`)
|
||||||
--- and `package.cpath` (for `lpeg.dll` on Windows).
|
--- and `package.cpath` (for `lpeg.dll` on Windows).
|
||||||
|
--- Idempotent: safe to call multiple times (just re-sets the same paths).
|
||||||
function M.setup()
|
function M.setup()
|
||||||
local repo_root = find_repo_root()
|
local repo_root = find_repo_root()
|
||||||
if not repo_root then
|
if not repo_root then
|
||||||
|
|||||||
@@ -28,10 +28,18 @@
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
--- Resolve the repo root via git. Returns a normalized path with a
|
-- Cache key for the repo root. Stored in `package.loaded` (process-
|
||||||
--- trailing forward-slash, or nil if not in a git repo.
|
-- global) so all 8 entry scripts + passes scripts share one git call.
|
||||||
|
-- Without this cache, `git rev-parse --show-toplevel` runs once per
|
||||||
|
-- script load = 8 × ~150ms = 1.2s wasted per build on Windows.
|
||||||
|
local CACHE_KEY = "__duffle_repo_root__"
|
||||||
|
|
||||||
|
--- Resolve the repo root via git (cached after first call).
|
||||||
|
--- Returns a normalized path with a trailing forward-slash, or nil
|
||||||
|
--- if not in a git repo.
|
||||||
--- @return string|nil
|
--- @return string|nil
|
||||||
local function find_repo_root()
|
local function find_repo_root()
|
||||||
|
if package.loaded[CACHE_KEY] then return package.loaded[CACHE_KEY] end
|
||||||
local p = io.popen("git rev-parse --show-toplevel 2>nul")
|
local p = io.popen("git rev-parse --show-toplevel 2>nul")
|
||||||
local root
|
local root
|
||||||
if p then
|
if p then
|
||||||
@@ -43,11 +51,13 @@ local function find_repo_root()
|
|||||||
-- `\` + `/` confuses LuaJIT's file APIs).
|
-- `\` + `/` confuses LuaJIT's file APIs).
|
||||||
root = root:gsub("\\", "/")
|
root = root:gsub("\\", "/")
|
||||||
if not root:match("/$") then root = root .. "/" end
|
if not root:match("/$") then root = root .. "/" end
|
||||||
|
package.loaded[CACHE_KEY] = root
|
||||||
return root
|
return root
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set `package.path` (for `require("duffle")` + `require("passes.X")`)
|
--- Set `package.path` (for `require("duffle")` + `require("passes.X")`)
|
||||||
--- and `package.cpath` (for `lpeg.dll` on Windows).
|
--- and `package.cpath` (for `lpeg.dll` on Windows).
|
||||||
|
--- Idempotent: safe to call multiple times (just re-sets the same paths).
|
||||||
function M.setup()
|
function M.setup()
|
||||||
local repo_root = find_repo_root()
|
local repo_root = find_repo_root()
|
||||||
if not repo_root then
|
if not repo_root then
|
||||||
|
|||||||
Reference in New Issue
Block a user