aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lua/dep.lua137
-rw-r--r--lua/dep/package.lua15
-rw-r--r--lua/dep/proc.lua10
3 files changed, 95 insertions, 67 deletions
diff --git a/lua/dep.lua b/lua/dep.lua
index 11802c8..1c143c8 100644
--- a/lua/dep.lua
+++ b/lua/dep.lua
@@ -11,7 +11,7 @@ local logger = require("dep.log").global
local proc = require("dep.proc")
local initialized, perf, config_path, base_dir
-local packages, root
+local packages, root, load
local function bench(name, code, ...)
local start = os.clock()
@@ -78,6 +78,7 @@ local function register(spec, overrides)
package.url = spec.url or package.url or ("https://github.com/" .. id .. ".git")
package.branch = spec.branch or package.branch
package.dir = base_dir .. package.name
+ package.commit = spec.commit
package.pin = overrides.pin or spec.pin or package.pin
package.enabled = not overrides.disable and not spec.disable and package.enabled
@@ -127,27 +128,6 @@ local function register_recursive(list, overrides)
error(string.format("%s (spec=%s)", err, vim.inspect(list[i])))
end
end
-
- if list.modules then
- for i = 1, #list.modules do
- local name, module = "<unnamed module>", list.modules[i]
-
- if type(module) == "string" then
- if list.modules.prefix then
- module = list.modules.prefix .. module
- end
-
- name, module = module, require(module)
- end
-
- name = module.name or name
-
- local ok, err = pcall(register_recursive, module, overrides)
- if not ok then
- error(string.format("%s <- %s", err, name))
- end
- end
- end
end
local function sort_dependencies()
@@ -417,6 +397,16 @@ local function reload()
end
local function reload_all()
+ -- recall the load function
+ if load and type(load) == "function" then
+ local ok, ret = pcall(load)
+ if ok and type(ret) == "table" then
+ register_recursive(ret)
+ else
+ logger:log("error", ret)
+ end
+ end
+
for i = 1, #packages do
local package = packages[i]
package.loaded, package.subtree_loaded = false, false
@@ -504,33 +494,55 @@ local function sync(package, cb)
log_err(before)
cb(err)
else
- proc.git_fetch(package.dir, "origin", package.branch or "HEAD", function(err, message)
- if err then
- log_err(message)
- cb(err)
- else
- proc.git_rev_parse(package.dir, "FETCH_HEAD", function(err, after)
- if err then
- log_err(after)
- cb(err)
- elseif before == after then
- logger:log("skip", string.format("skipped %s", package.id))
- cb(err)
- else
- proc.git_reset(package.dir, after, function(err, message)
- if err then
- log_err(message)
- else
- mark_reconfigure(package)
- logger:log("update", string.format("updated %s; %s -> %s", package.id, before, after))
- end
-
+ if package.commit then
+ proc.git_checkout(package.dir, package.branch, package.commit, function(err, message)
+ if err then
+ log_err(message)
+ cb(err)
+ else
+ proc.git_rev_parse(package.dir, package.commit, function(err, after)
+ if err then
+ log_err(after)
cb(err)
- end)
- end
- end)
- end
- end)
+ elseif before == after then
+ logger:log("skip", string.format("skipped %s", package.id))
+ cb(err)
+ else
+ mark_reconfigure(package)
+ logger:log("update", string.format("updated %s; %s -> %s", package.id, before, after))
+ end
+ end)
+ end
+ end)
+ else
+ proc.git_fetch(package.dir, "origin", package.branch or "HEAD", function(err, message)
+ if err then
+ log_err(message)
+ cb(err)
+ else
+ proc.git_rev_parse(package.dir, "FETCH_HEAD", function(err, after)
+ if err then
+ log_err(after)
+ cb(err)
+ elseif before == after then
+ logger:log("skip", string.format("skipped %s", package.id))
+ cb(err)
+ else
+ proc.git_reset(package.dir, after, function(err, message)
+ if err then
+ log_err(message)
+ else
+ mark_reconfigure(package)
+ logger:log("update", string.format("updated %s; %s -> %s", package.id, before, after))
+ end
+
+ cb(err)
+ end)
+ end
+ end)
+ end
+ end)
+ end
end
end)
else
@@ -538,9 +550,21 @@ local function sync(package, cb)
if err then
logger:log("error", string.format("failed to install %s; reason: %s", package.id, message))
else
- package.exists = true
- mark_reconfigure(package)
- logger:log("install", string.format("installed %s", package.id))
+ if package.commit then
+ proc.git_checkout(package.dir, package.branch, package.commit, function(err, message)
+ if err then
+ logger:log("error", string.format("failed to checkout %s; reason: %s", package.id, message))
+ else
+ package.exists = true
+ mark_reconfigure(package)
+ logger:log("install", string.format("installed %s", package.id))
+ end
+ end)
+ else
+ package.exists = true
+ mark_reconfigure(package)
+ logger:log("install", string.format("installed %s", package.id))
+ end
end
cb(err)
@@ -850,7 +874,16 @@ return setmetatable({
packages = {}
bench("load", function()
- root = register("chiyadev/dep")
+ root = register("squibid/dep")
+ if config["load"] and type(config["load"]) == "function" then
+ local ok, ret = pcall(config["load"])
+ if ok and type(ret) == "table" then
+ load = config["load"]
+ register_recursive(ret)
+ else
+ logger:log("error", ret)
+ end
+ end
register_recursive(config)
sort_dependencies()
ensure_acyclic()
diff --git a/lua/dep/package.lua b/lua/dep/package.lua
index 513df8d..e76238d 100644
--- a/lua/dep/package.lua
+++ b/lua/dep/package.lua
@@ -168,7 +168,6 @@ local PackageStore = setmetatable({
assert(type(specs) == "table", "package list must be a table")
assert(specs.pin == nil or type(specs.pin) == "boolean", "package list pin must be a boolean")
assert(specs.disable == nil or type(specs.disable) == "boolean", "package list disable must be a boolean")
- assert(specs.modules == nil or type(specs.modules) == "table", "package list module list must be a table")
scope = scope or {}
scope = {
@@ -181,20 +180,6 @@ local PackageStore = setmetatable({
for i = 1, #specs do
self:add_spec(specs[i], scope)
end
-
- -- recursively add referenced spec list modules
- if specs.modules then
- local prefix = specs.modules.prefix or ""
- for i = 1, #specs.modules do
- local name = specs.modules[i]
- assert(type(name) == "string", "package list inner module name must be a string")
- name = prefix .. name
-
- local module = require(name)
- assert(type(module) == "table", "package list inner module did not return a spec list table")
- self:add_specs(module, scope)
- end
- end
end,
--- Ensures there are no circular dependencies in this package store.
diff --git a/lua/dep/proc.lua b/lua/dep/proc.lua
index 4b95baa..cf3aa9c 100644
--- a/lua/dep/proc.lua
+++ b/lua/dep/proc.lua
@@ -61,4 +61,14 @@ function proc.git_reset(dir, treeish, cb)
proc.exec("git", args, dir, git_env, cb)
end
+function proc.git_checkout(dir, branch, commit, cb)
+ local args = { "fetch", "--depth=2147483647", "origin", branch }
+ proc.exec("git", args, dir, git_env, function(err, message)
+ cb(err, message)
+
+ args = { "checkout", commit }
+ proc.exec("git", args, dir, git_env, cb)
+ end)
+end
+
return proc