10 Commits
lazy ... dev

Author SHA1 Message Date
5a395de735 add arbitrary tag selection with *s 2024-12-23 21:46:44 -05:00
6d6568ecfd Merge branch 'master' into dev 2024-12-23 21:42:38 -05:00
443a091e3e fix: accidentally jumps to FETCH_HEAD 2024-11-19 12:53:06 -06:00
6259250120 fix: --unshallow errors if the repo is already unshallow
instead we use --depth=2147483647 because as noted by the docs...

  The special depth 2147483647 (or 0x7fffffff, the largest positive number a
  signed 32-bit integer can contain) means infinite depth.

  https://git-scm.com/docs/shallow
2024-11-19 12:41:54 -06:00
25372aea36 add ability to specifiy commit ref 2024-11-19 12:36:55 -06:00
30e7e05771 make sure the load function is called on dep reloading 2024-07-25 20:01:23 -04:00
d7a08ca820 actually fix it this time 2024-07-25 10:36:27 -04:00
d141c762c1 whoops 2024-07-25 10:27:12 -04:00
3d20ae8d2a pin the correct repo to the top of the plugin list 2024-07-25 10:25:36 -04:00
d6460d53ed notify user that this is a development version 2023-04-29 12:18:06 -04:00
5 changed files with 186 additions and 177 deletions

View File

@ -1,6 +1,7 @@
MIT License MIT License
Copyright (c) 2021 chiya.dev (c) 2021 chiya.dev
(c) 2024 squibid
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

107
README.md
View File

@ -95,6 +95,10 @@ A package must be declared in the following format.
-- Defaults to whatever the remote configured as their HEAD, which is usually "master". -- Defaults to whatever the remote configured as their HEAD, which is usually "master".
branch = "develop", branch = "develop",
-- [string] Overrides the commit ref to target
-- Defaults to the latest commit on the current branch
commit = "e76cb03",
-- [boolean] Prevents the package from being loaded. -- [boolean] Prevents the package from being loaded.
disable = true, disable = true,
@ -287,97 +291,6 @@ require "dep" {
} }
``` ```
## Separating code into modules
Suppose you split your `init.lua` into two files `packages/search.lua` and
`packages/vcs.lua`, which declare the packages [telescope.nvim][6] and [vim-fugitive][7] respectively.
```lua
-- ~/.config/nvim/lua/packages/search.lua:
return {
{
"nvim-telescope/telescope.nvim",
requires = "nvim-lua/plenary.nvim"
}
}
```
```lua
-- ~/.config/nvim/lua/packages/vcs.lua:
return {
"tpope/vim-fugitive"
}
```
Package specifications from other modules can be loaded using the `modules` option.
```lua
require "dep" {
modules = {
prefix = "packages.",
"search",
"vcs"
}
}
-- the above is equivalent to
require "dep" {
modules = {
"packages.search",
"packages.vcs"
}
}
-- which is equivalent to
local packages = {}
for _, package in ipairs(require "packages.search") do
table.insert(packages, package)
end
for _, package in ipairs(require "packages.vcs") do
table.insert(packages, package)
end
require("dep")(packages)
-- which is ultimately equivalent to
require "dep" {
{
"nvim-telescope/telescope.nvim",
requires = "nvim-lua/plenary.nvim"
},
"tpope/vim-fugitive"
}
-- all of the above are guaranteed to load plenary.nvim before telescope.nvim.
-- order of telescope.nvim and vim-fugitive is consistent but unspecified.
```
Entire modules can be marked as disabled, which disables all top-level packages declared in that module.
```lua
return {
disable = true,
{
"user/package",
disabled = true, -- implied by module
requires = {
{
"user/dependency",
-- disabled = true -- not implied
}
},
deps = {
{
"user/dependent",
disabled = true -- implied by dependency
}
}
}
}
```
## Miscellaneous configuration ## Miscellaneous configuration
dep accepts configuration parameters as named fields in the package list. dep accepts configuration parameters as named fields in the package list.
@ -390,14 +303,10 @@ require "dep" {
-- "always": synchronize all packages on startup -- "always": synchronize all packages on startup
sync = "new", sync = "new",
-- [array] Specifies the modules to load package specifications from. -- [function] Callback when dep is (re)loaded
-- Defaults to an empty table. -- if a table is returned it will be read as a table of config specs
-- Items can be either an array of package specifications, load = function()
-- or a string that indicates the name of the module from which the array of package specifications is loaded. end
modules = {
-- [string] Prefix string to prepend to all module names.
prefix = "",
},
-- list of package specs... -- list of package specs...
} }

View File

@ -11,7 +11,7 @@ local logger = require("dep.log").global
local proc = require("dep.proc") local proc = require("dep.proc")
local initialized, perf, config_path, base_dir local initialized, perf, config_path, base_dir
local packages, root local packages, root, load
local function bench(name, code, ...) local function bench(name, code, ...)
local start = os.clock() 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.url = spec.url or package.url or ("https://github.com/" .. id .. ".git")
package.branch = spec.branch or package.branch package.branch = spec.branch or package.branch
package.dir = base_dir .. package.name package.dir = base_dir .. package.name
package.commit = spec.commit
package.pin = overrides.pin or spec.pin or package.pin package.pin = overrides.pin or spec.pin or package.pin
package.enabled = not overrides.disable and not spec.disable and package.enabled 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]))) error(string.format("%s (spec=%s)", err, vim.inspect(list[i])))
end end
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 end
local function sort_dependencies() local function sort_dependencies()
@ -417,6 +397,16 @@ local function reload()
end end
local function reload_all() 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 for i = 1, #packages do
local package = packages[i] local package = packages[i]
package.loaded, package.subtree_loaded = false, false package.loaded, package.subtree_loaded = false, false
@ -489,63 +479,105 @@ local function sync(package, cb)
return return
end end
if package.exists then local function log_err(err)
if package.pin then logger:log("error", string.format("failed to update %s; reason: %s", package.id, err))
cb() end
return
end
local function log_err(err) proc.git_resolve_branch(package.url, package.branch, function(err, branch)
logger:log("error", string.format("failed to update %s; reason: %s", package.id, err)) if err then
log_err(err)
cb(err)
end end
package.branch = branch
proc.git_rev_parse(package.dir, "HEAD", function(err, before) if package.exists then
if err then if package.pin then
log_err(before) cb()
cb(err) return
else end
proc.git_fetch(package.dir, "origin", package.branch or "HEAD", function(err, message)
if err then proc.git_rev_parse(package.dir, "HEAD", function(err, before)
log_err(message) if err then
cb(err) log_err(before)
else cb(err)
proc.git_rev_parse(package.dir, "FETCH_HEAD", function(err, after) else
if package.commit then
proc.git_checkout(package.dir, package.branch, package.commit, function(err, message)
if err then if err then
log_err(after) log_err(message)
cb(err)
elseif before == after then
logger:log("skip", string.format("skipped %s", package.id))
cb(err) cb(err)
else else
proc.git_reset(package.dir, after, function(err, message) proc.git_rev_parse(package.dir, package.commit, function(err, after)
if err then if err then
log_err(message) log_err(after)
cb(err)
elseif before == after then
logger:log("skip", string.format("skipped %s", package.id))
cb(err)
else else
mark_reconfigure(package) mark_reconfigure(package)
logger:log("update", string.format("updated %s; %s -> %s", package.id, before, after)) logger:log("update", string.format("updated %s; %s -> %s", package.id, before, after))
end 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) cb(err)
end)
end
end) end)
end end
end) end)
end end
end) end
end end)
end) else
else proc.git_clone(package.dir, package.url, package.branch, function(err, message)
proc.git_clone(package.dir, package.url, package.branch, function(err, message) if err then
if err then logger:log("error", string.format("failed to install %s; reason: %s", package.id, message))
logger:log("error", string.format("failed to install %s; reason: %s", package.id, message)) else
else if package.commit then
package.exists = true proc.git_checkout(package.dir, package.branch, package.commit, function(err, message)
mark_reconfigure(package) if err then
logger:log("install", string.format("installed %s", package.id)) logger:log("error", string.format("failed to checkout %s; reason: %s", package.id, message))
end 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) cb(err)
end) end)
end end
end)
end end
local function sync_list(list, on_complete) local function sync_list(list, on_complete)
@ -638,6 +670,7 @@ local function print_list(cb)
line = line + 1 line = line + 1
end end
print("!! Warning you are using the dev branch of dep, expect bugs")
print(string.format("Installed packages (%s):", #packages)) print(string.format("Installed packages (%s):", #packages))
indent = 1 indent = 1
@ -850,6 +883,15 @@ return setmetatable({
bench("load", function() bench("load", function()
root = register("squibid/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) register_recursive(config)
sort_dependencies() sort_dependencies()
ensure_acyclic() ensure_acyclic()

View File

@ -168,7 +168,6 @@ local PackageStore = setmetatable({
assert(type(specs) == "table", "package list must be a table") 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.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.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 = scope or {}
scope = { scope = {
@ -181,20 +180,6 @@ local PackageStore = setmetatable({
for i = 1, #specs do for i = 1, #specs do
self:add_spec(specs[i], scope) self:add_spec(specs[i], scope)
end 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, end,
--- Ensures there are no circular dependencies in this package store. --- Ensures there are no circular dependencies in this package store.

View File

@ -61,4 +61,76 @@ function proc.git_reset(dir, treeish, cb)
proc.exec("git", args, dir, git_env, cb) proc.exec("git", args, dir, git_env, cb)
end 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
function proc.git_resolve_branch(url, branch, cb)
if string.match(branch or "", "*") ~= "*" then
cb(false, branch)
return
end
local buffer = {}
local function cb_output(_, data, _)
if data[1] ~= "" then
buffer = data
end
end
vim.fn.jobstart({
"git",
"ls-remote",
"--tags",
"--sort",
"v:refname",
url
}, {
cwd = nil,
env = { GIT_TERMINAL_PROMPT = 0 },
stdin = nil,
on_stdout = cb_output,
on_stderr = cb_output,
on_exit = function(_, exit_code, _)
if exit_code == 0 then
-- get a list of all versions
local versions = {}
for _, v in pairs(buffer) do
local s, e = string.find(v, "refs/tags/.+")
if not s or not e then
goto continue
end
local tag = string.sub(v, s, e)
tag = string.gsub(tag, "refs/tags/", "")
tag = string.gsub(tag, "%^{}", "")
table.insert(versions, tag)
::continue::
end
-- match the chosen version against all versions
for i = #versions, 1, -1 do
if branch == "*" then
cb(false, versions[i])
return
else
local r = string.match(versions[i], branch)
if r then
cb(false, r)
return
end
end
end
end
end
})
end
return proc return proc