Skip to content

Commit 21c3ad4

Browse files
fix: remove lua module
1 parent 1e09f6b commit 21c3ad4

File tree

1 file changed

+57
-57
lines changed

1 file changed

+57
-57
lines changed
Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
1-
local log = require("hg.log")
2-
3-
local M = {}
4-
5-
local COMMIT_INFO_PATH = "/gitCommit/commitinfo"
6-
local REVISION_LENGTH = 10
7-
8-
local function read_commit_hash()
9-
local file, open_error = io.open(COMMIT_INFO_PATH, "r")
10-
11-
if not file then
12-
log.debug(
13-
string.format(
14-
"WARNING: Failed to open commit information file: %s (%s)",
15-
COMMIT_INFO_PATH,
16-
open_error or "unknown error"
17-
)
18-
)
19-
return nil
20-
end
21-
22-
local revision = file:read("*l")
23-
file:close()
24-
25-
if not revision or revision == "" then
26-
log.debug("WARNING: Commit information file is empty or unreadable: " .. COMMIT_INFO_PATH)
27-
return nil
28-
end
29-
30-
return revision:sub(1, REVISION_LENGTH)
31-
end
32-
33-
function M.apply_revision_override()
34-
local revision = read_commit_hash()
35-
36-
if not revision then
37-
log.debug("INFO: project.revision override will not be applied.")
38-
return
39-
end
40-
41-
log.debug("INFO: Detected commit hash: " .. revision .. ". Overriding sys.get_config.")
42-
43-
local original_get_config = sys.get_config
44-
45-
sys.get_config = function(key, default_value)
46-
if key == "project.revision" then
47-
return revision
48-
end
49-
return original_get_config(key, default_value)
50-
end
51-
52-
log.debug(
53-
"INFO: sys.get_config successfully overridden. project.revision is now: " .. sys.get_config("project.revision")
54-
)
55-
end
56-
57-
return M
1+
local log = require("hg.log")
2+
3+
local M = {}
4+
5+
local COMMIT_INFO_PATH = "gitcommit/commitinfo"
6+
local REVISION_LENGTH = 10
7+
8+
local function read_commit_hash()
9+
local file, open_error = io.open(COMMIT_INFO_PATH, "r")
10+
11+
if not file then
12+
log.debug(
13+
string.format(
14+
"WARNING: Failed to open commit information file: %s (%s)",
15+
COMMIT_INFO_PATH,
16+
open_error or "unknown error"
17+
)
18+
)
19+
return nil
20+
end
21+
22+
local revision = file:read("*l")
23+
file:close()
24+
25+
if not revision or revision == "" then
26+
log.debug("WARNING: Commit information file is empty or unreadable: " .. COMMIT_INFO_PATH)
27+
return nil
28+
end
29+
30+
return revision:sub(1, REVISION_LENGTH)
31+
end
32+
33+
function M.apply_revision_override()
34+
local revision = read_commit_hash()
35+
36+
if not revision then
37+
log.debug("INFO: project.revision override will not be applied.")
38+
return
39+
end
40+
41+
log.debug("INFO: Detected commit hash: " .. revision .. ". Overriding sys.get_config.")
42+
43+
local original_get_config = sys.get_config
44+
45+
sys.get_config = function(key, default_value)
46+
if key == "project.revision" then
47+
return revision
48+
end
49+
return original_get_config(key, default_value)
50+
end
51+
52+
log.debug(
53+
"INFO: sys.get_config successfully overridden. project.revision is now: " .. sys.get_config("project.revision")
54+
)
55+
end
56+
57+
return M

0 commit comments

Comments
 (0)