From 344223afd55a93cea65501d223886c648ee9c054 Mon Sep 17 00:00:00 2001 From: Squibid Date: Sat, 29 Apr 2023 12:19:13 -0400 Subject: notifiy was in the wrong place --- lua/dep.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lua/dep.lua b/lua/dep.lua index 386e739..b4bce62 100644 --- a/lua/dep.lua +++ b/lua/dep.lua @@ -638,9 +638,7 @@ local function print_list(cb) line = line + 1 end - vim.notify(string.format("Installed packages (%s):", #packages), 'info', { - title = 'Dep', - }) + print(string.format("Installed packages (%s):", #packages)) indent = 1 local loaded = {} -- cgit v1.2.1 From 5b7b7f610f515e55c72a86bc8f49855652c0f339 Mon Sep 17 00:00:00 2001 From: Squibid Date: Sun, 30 Apr 2023 19:49:01 -0400 Subject: pin the correct repo to the top of the plugin list --- lua/dep.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/dep.lua b/lua/dep.lua index b4bce62..dccd17b 100644 --- a/lua/dep.lua +++ b/lua/dep.lua @@ -849,7 +849,7 @@ return setmetatable({ packages = {} bench("load", function() - root = register("chiyadev/dep") + root = register("squibid/dep") register_recursive(config) sort_dependencies() ensure_acyclic() -- cgit v1.2.1 From 3d20ae8d2ac131aa2e2d2064c91ae31c800d8ea9 Mon Sep 17 00:00:00 2001 From: Squibid Date: Sun, 30 Apr 2023 19:49:01 -0400 Subject: pin the correct repo to the top of the plugin list --- LICENSE | 3 +- README.md | 103 ++-------------------------------------------------- lua/dep.lua | 27 +++----------- lua/dep/package.lua | 15 -------- 4 files changed, 12 insertions(+), 136 deletions(-) diff --git a/LICENSE b/LICENSE index 3a42b2f..3cfd7b3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ 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 of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 808821e..a77c576 100644 --- a/README.md +++ b/README.md @@ -287,97 +287,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 dep accepts configuration parameters as named fields in the package list. @@ -390,14 +299,10 @@ require "dep" { -- "always": synchronize all packages on startup sync = "new", - -- [array] Specifies the modules to load package specifications from. - -- Defaults to an empty table. - -- Items can be either an array of package specifications, - -- or a string that indicates the name of the module from which the array of package specifications is loaded. - modules = { - -- [string] Prefix string to prepend to all module names. - prefix = "", - }, + -- [function] Callback when dep is (re)loaded + -- if a table is returned it will be read as a table of config specs + load = function() + end -- list of package specs... } diff --git a/lua/dep.lua b/lua/dep.lua index dccd17b..20be24f 100644 --- a/lua/dep.lua +++ b/lua/dep.lua @@ -127,27 +127,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 = "", 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() @@ -851,6 +830,12 @@ return setmetatable({ bench("load", function() root = register("squibid/dep") register_recursive(config) + if config["load"] and type(config["load"]) == "function" then + local ok, ret = pcall(config["load"]()) + if ok and type(ret) == "table" then + register_recursive(ok) + end + end sort_dependencies() ensure_acyclic() end) 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. -- cgit v1.2.1 From d141c762c19d7e216b8e9953874f957b6b70775e Mon Sep 17 00:00:00 2001 From: Squibid Date: Thu, 25 Jul 2024 10:27:12 -0400 Subject: whoops --- lua/dep.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/dep.lua b/lua/dep.lua index 20be24f..0e25819 100644 --- a/lua/dep.lua +++ b/lua/dep.lua @@ -833,7 +833,7 @@ return setmetatable({ if config["load"] and type(config["load"]) == "function" then local ok, ret = pcall(config["load"]()) if ok and type(ret) == "table" then - register_recursive(ok) + register_recursive(ret) end end sort_dependencies() -- cgit v1.2.1 From d7a08ca8205817589e90050ec20ea06591035526 Mon Sep 17 00:00:00 2001 From: Squibid Date: Thu, 25 Jul 2024 10:36:27 -0400 Subject: actually fix it this time --- lua/dep.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lua/dep.lua b/lua/dep.lua index 0e25819..c6deb9f 100644 --- a/lua/dep.lua +++ b/lua/dep.lua @@ -829,13 +829,15 @@ return setmetatable({ bench("load", function() root = register("squibid/dep") - register_recursive(config) if config["load"] and type(config["load"]) == "function" then - local ok, ret = pcall(config["load"]()) + local ok, ret = pcall(config["load"]) if ok and type(ret) == "table" then register_recursive(ret) + else + logger:log("error", ret) end end + register_recursive(config) sort_dependencies() ensure_acyclic() end) -- cgit v1.2.1 From 30e7e057718973c86e3dc811c21000ce9a5c2050 Mon Sep 17 00:00:00 2001 From: Squibid Date: Thu, 25 Jul 2024 20:01:23 -0400 Subject: make sure the load function is called on dep reloading --- lua/dep.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lua/dep.lua b/lua/dep.lua index c6deb9f..378ef82 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() @@ -396,6 +396,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 @@ -832,6 +842,7 @@ return setmetatable({ 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) -- cgit v1.2.1 From 25372aea36cef2a094b1a0d8f83e0199734944f6 Mon Sep 17 00:00:00 2001 From: Squibid Date: Tue, 19 Nov 2024 12:36:55 -0600 Subject: add ability to specifiy commit ref --- README.md | 4 ++++ lua/dep.lua | 28 +++++++++++++++++++++++----- lua/dep/proc.lua | 10 ++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a77c576..d3991af 100644 --- a/README.md +++ b/README.md @@ -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". 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. disable = true, diff --git a/lua/dep.lua b/lua/dep.lua index 378ef82..911ceca 100644 --- a/lua/dep.lua +++ b/lua/dep.lua @@ -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 @@ -493,7 +494,7 @@ local function sync(package, cb) log_err(before) cb(err) else - proc.git_fetch(package.dir, "origin", package.branch or "HEAD", function(err, message) + local function continue(err, message) if err then log_err(message) cb(err) @@ -519,7 +520,12 @@ local function sync(package, cb) end end) end - end) + end + if package.commit then + proc.git_checkout(package.dir, package.branch, package.commit, continue) + else + proc.git_fetch(package.dir, "origin", package.branch or "HEAD", continue) + end end end) else @@ -527,9 +533,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) diff --git a/lua/dep/proc.lua b/lua/dep/proc.lua index 4b95baa..3355228 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", "--unshallow", "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 -- cgit v1.2.1 From 6259250120315534d31f28ffd03d36f1cdb30f7b Mon Sep 17 00:00:00 2001 From: Squibid Date: Tue, 19 Nov 2024 12:41:54 -0600 Subject: 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 --- lua/dep/proc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/dep/proc.lua b/lua/dep/proc.lua index 3355228..cf3aa9c 100644 --- a/lua/dep/proc.lua +++ b/lua/dep/proc.lua @@ -62,7 +62,7 @@ function proc.git_reset(dir, treeish, cb) end function proc.git_checkout(dir, branch, commit, cb) - local args = { "fetch", "--unshallow", "origin", branch } + local args = { "fetch", "--depth=2147483647", "origin", branch } proc.exec("git", args, dir, git_env, function(err, message) cb(err, message) -- cgit v1.2.1 From 443a091e3e2b0c4fc0fdcaf00d878b1edc86ce91 Mon Sep 17 00:00:00 2001 From: Squibid Date: Tue, 19 Nov 2024 12:53:06 -0600 Subject: fix: accidentally jumps to FETCH_HEAD --- lua/dep.lua | 75 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 29 deletions(-) diff --git a/lua/dep.lua b/lua/dep.lua index 911ceca..dbf6516 100644 --- a/lua/dep.lua +++ b/lua/dep.lua @@ -494,37 +494,54 @@ local function sync(package, cb) log_err(before) cb(err) else - local function continue(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 if package.commit then - proc.git_checkout(package.dir, package.branch, package.commit, continue) + 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) + 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", continue) + 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) -- cgit v1.2.1