aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam Harrison <adamdharrison@gmail.com>2023-01-02 13:39:52 -0500
committerAdam Harrison <adamdharrison@gmail.com>2023-01-02 13:39:52 -0500
commit9a5c459f3fdf6affb73039a0cabad66486aff9c4 (patch)
tree6af393009e4352e25bc57b3e17aacb80512d05b2 /src
parent928dffdd842553af625ee698bf95b640417e68b4 (diff)
downloadlite-xl-plugin-manager-9a5c459f3fdf6affb73039a0cabad66486aff9c4.tar.gz
lite-xl-plugin-manager-9a5c459f3fdf6affb73039a0cabad66486aff9c4.zip
Added in ability to grab plugins from remote repos that are stubs that aren't in the repository list.
Diffstat (limited to 'src')
-rw-r--r--src/lpm.c50
-rw-r--r--src/lpm.lua41
2 files changed, 58 insertions, 33 deletions
diff --git a/src/lpm.c b/src/lpm.c
index 14d75b8..f2e9799 100644
--- a/src/lpm.c
+++ b/src/lpm.c
@@ -79,7 +79,6 @@ static int lpm_hash(lua_State* L) {
hex_buffer[i*2+1] = hex_digits[buffer[i] & 0xF];
}
lua_pushlstring(L, hex_buffer, digest_length * 2);
- hex_buffer[digest_length*2]=0;
return 1;
}
@@ -335,6 +334,22 @@ static int lpm_reset(lua_State* L) {
return 0;
}
+static int lpm_revparse(lua_State* L) {
+ git_repository* repository = luaL_checkgitrepo(L, 1);
+ git_oid commit_id;
+ int got_commit = git_get_id(&commit_id, repository, "HEAD");
+ git_repository_free(repository);
+ if (got_commit)
+ return luaL_error(L, "git retrieve commit error: %s", git_error_last_string());
+ int digest_length = sizeof(commit_id.id);
+ char hex_buffer[digest_length * 2];
+ for (size_t i = 0; i < digest_length; ++i) {
+ hex_buffer[i*2+0] = hex_digits[commit_id.id[i] >> 4];
+ hex_buffer[i*2+1] = hex_digits[commit_id.id[i] & 0xF];
+ }
+ lua_pushlstring(L, hex_buffer, digest_length * 2);
+ return 1;
+}
static int lpm_init(lua_State* L) {
const char* path = luaL_checkstring(L, 1);
@@ -937,22 +952,23 @@ static int lpm_pwd(lua_State* L) {
}
static const luaL_Reg system_lib[] = {
- { "ls", lpm_ls }, // Returns an array of files.
- { "stat", lpm_stat }, // Returns info about a single file.
- { "mkdir", lpm_mkdir }, // Makes a directory.
- { "rmdir", lpm_rmdir }, // Removes a directory.
- { "hash", lpm_hash }, // Returns a hex sha256 hash.
- { "symlink", lpm_symlink }, // Creates a symlink.
- { "chmod", lpm_chmod }, // Chmod's a file.
- { "init", lpm_init }, // Initializes a git repository with the specified remote.
- { "fetch", lpm_fetch }, // Updates a git repository with the specified remote.
- { "reset", lpm_reset }, // Updates a git repository to the specified commit/hash/branch.
- { "get", lpm_get }, // HTTP(s) GET request.
- { "extract", lpm_extract }, // Extracts .tar.gz, and .zip files.
- { "trace", lpm_trace }, // Sets trace bit.
- { "certs", lpm_certs }, // Sets the SSL certificate chain folder/file.
- { "chdir", lpm_chdir }, // Changes directory. Only use for --post actions.
- { "pwd", lpm_pwd }, // Gets existing directory. Only use for --post actions.
+ { "ls", lpm_ls }, // Returns an array of files.
+ { "stat", lpm_stat }, // Returns info about a single file.
+ { "mkdir", lpm_mkdir }, // Makes a directory.
+ { "rmdir", lpm_rmdir }, // Removes a directory.
+ { "hash", lpm_hash }, // Returns a hex sha256 hash.
+ { "symlink", lpm_symlink }, // Creates a symlink.
+ { "chmod", lpm_chmod }, // Chmod's a file.
+ { "init", lpm_init }, // Initializes a git repository with the specified remote.
+ { "fetch", lpm_fetch }, // Updates a git repository with the specified remote.
+ { "reset", lpm_reset }, // Updates a git repository to the specified commit/hash/branch.
+ { "revparse", lpm_revparse }, // Gets a commit id.
+ { "get", lpm_get }, // HTTP(s) GET request.
+ { "extract", lpm_extract }, // Extracts .tar.gz, and .zip files.
+ { "trace", lpm_trace }, // Sets trace bit.
+ { "certs", lpm_certs }, // Sets the SSL certificate chain folder/file.
+ { "chdir", lpm_chdir }, // Changes directory. Only use for --post actions.
+ { "pwd", lpm_pwd }, // Gets existing directory. Only use for --post actions.
{ NULL, NULL }
};
diff --git a/src/lpm.lua b/src/lpm.lua
index 6f1db28..5058743 100644
--- a/src/lpm.lua
+++ b/src/lpm.lua
@@ -685,11 +685,12 @@ function Plugin:install(bottle, installing)
log_action("Downloaded file " .. self.url .. " to " .. path)
if system.hash(path, "file") ~= self.checksum then fatal_warning("checksum doesn't match for " .. path) end
elseif self.remote then
- log_action("Cloning repository " .. self.remote .. " into " .. install_path)
+ log_progress_action("Fetching repository " .. self.remote .. " into " .. install_path)
common.mkdirp(temporary_install_path)
local _, _, url, branch = self.remote:find("^(.*):(.*)$")
system.init(temporary_install_path, url)
- common.reset(temporary_install_path, branch)
+ system.fetch(temporary_install_path, write_progress_bar)
+ common.reset(temporary_install_path, branch, "hard")
elseif self.path then
local path = install_path .. (self.organization == 'complex' and self.path and system.stat(self.local_path).type ~= "dir" and (PATHSEP .. "init.lua") or "")
local temporary_path = temporary_install_path .. (self.organization == 'complex' and self.path and system.stat(self.local_path).type ~= "dir" and (PATHSEP .. "init.lua") or "")
@@ -800,7 +801,10 @@ function Repository:parse_manifest(already_pulling)
if self.manifest then return self.manifest, self.remotes end
if system.stat(self.local_path) and system.stat(self.local_path .. PATHSEP .. (self.commit or self.branch)) then
self.manifest_path = self.local_path .. PATHSEP .. (self.commit or self.branch) .. PATHSEP .. "manifest.json"
- if not system.stat(self.manifest_path) then self:generate_manifest() end
+ if not system.stat(self.manifest_path) then
+ log_action("Can't find manifest.json for " .. self:url() .. "; automatically generating manifest.")
+ self:generate_manifest()
+ end
local status, manifest = pcall(json.decode, common.read(self.manifest_path))
if not status then error("error parsing manifest for " .. self:url() .. ": " .. manifest) end
self.manifest = manifest
@@ -808,10 +812,8 @@ function Repository:parse_manifest(already_pulling)
self.remotes = {}
for i, metadata in ipairs(self.manifest["plugins"] or {}) do
if metadata.remote then
- local _, _, url, branch_or_commit = metadata.remote:find("^(.-):?(.*)?$")
+ local _, _, url, branch_or_commit = metadata.remote:find("^(.-):?(%w*)$")
if branch_or_commit and is_commit_hash(branch_or_commit) then
- repo = Repository.new({ remote = url, commit = branch_or_commit })
- table.insert(remotes, repo)
table.insert(self.plugins, Plugin.new(self, metadata))
else
-- log_warning("plugin " .. metadata.name .. " specifies remote as source, but isn't a commit")
@@ -822,10 +824,8 @@ function Repository:parse_manifest(already_pulling)
end
for i, metadata in ipairs(self.manifest["lite-xls"] or {}) do
if metadata.remote then
- local _, _, url, branch_or_commit = metadata.remote:find("^(.-):?(.*)?$")
+ local _, _, url, branch_or_commit = metadata.remote:find("^(.-):?(%w*)$")
if branch_or_commit and is_commit_hash(branch_or_commit) then
- repo = Repository.new({ remote = url, commit = branch_or_commit })
- table.insert(remotes, repo)
table.insert(self.lite_xls, LiteXL.new(self, metadata))
else
-- log_warning("plugin " .. metadata.name .. " specifies remote as source, but isn't a commit")
@@ -858,7 +858,12 @@ function Repository:generate_manifest()
local file = common.get(path, nil, nil, write_progress_bar)
plugin_map[name].checksum = system.hash(file)
else
+ path = path:gsub("\\", "")
plugin_map[name].remote = path
+ pcall(function()
+ local repo = Repository.url(path):add()
+ plugin_map[name].remote = path .. ":" .. system.revparse(repo.local_path .. PATHSEP .. (repo.branch))
+ end)
end
else
plugin_map[name].path = path:gsub("%?.*$", "")
@@ -868,7 +873,7 @@ function Repository:generate_manifest()
end
for i, file in ipairs(system.ls(path .. plugin_dir)) do
if file:find("%.lua$") then
- local plugin = { description = nil, name = common.basename(file):gsub("%.lua$", ""), mod_version = 3, version = "1.0", path = plugin_dir .. file }
+ local plugin = { description = nil, name = common.basename(file):gsub("%.lua$", ""), mod_version = 3, version = "0.1", path = plugin_dir .. file }
for line in io.lines(path .. plugin_dir .. file) do
local _, _, mod_version = line:find("%-%-.*mod%-version:%s*(%w+)")
if mod_version then plugin.mod_version = mod_version end
@@ -884,9 +889,10 @@ function Repository:generate_manifest()
end
for k, v in pairs(plugin_map) do
if not v.plugin then
- table.insert(plugins, common.merge({ mod_version = self.branch == "master" and 2 or 3, version = "1.0" }, v))
+ table.insert(plugins, common.merge({ mod_version = 3, version = "0.1" }, v))
end
end
+ table.sort(plugins, function(a,b) return a.name:lower() < b.name:lower() end)
common.write(path .. PATHSEP .. "manifest.json", json.encode({ plugins = plugins }))
end
@@ -1319,15 +1325,19 @@ local function lpm_lite_xl_run(version, ...)
if not version then error("requires a version") end
local lite_xl = get_lite_xl(version) or error("can't find lite-xl version " .. version)
local plugins = {}
- for i, str in ipairs({ ... }) do
+ local arguments = { ... }
+ local i = 1
+ while i < #arguments and arguments[i] ~= "--" do
+ local str = arguments[i]
local name, version = common.split(":", str)
local plugin = system_bottle:get_plugin(name, version, { mod_version = lite_xl.mod_version })
if not plugin then error("can't find plugin " .. str) end
table.insert(plugins, plugin)
+ i = i + 1
end
local bottle = Bottle.new(lite_xl, plugins)
if not bottle:is_constructed() then bottle:construct() end
- bottle:run()
+ bottle:run(common.splice(arguments, i + 1))
end
@@ -1764,8 +1774,8 @@ in any circumstance unless explicitly supplied.
table.sort(plugins, function(a,b) return string.lower(a.name) < string.lower(b.name) end)
local names = common.map(plugins, function(plugin)
if plugin.path then return string.format("[`%s`](%s?raw=1)", plugin.name, plugin.path) end
- if plugin.url then return string.format("[`%s`](%s)", plugin.name, plugin.url) end
- if plugin.remote then return string.format("[`%s`](%s)\\*", plugin.name, plugin.remote) end
+ if plugin.url then return string.format("[`%s`](%s)", plugin.name, plugin.url) end
+ if plugin.remote then return string.format("[`%s`](%s)\\*", plugin.name, plugin.remote:gsub(":%w+$")) end
return plugin.name
end)
local descriptions = common.map(plugins, function(e) return e.description or "" end)
@@ -1779,7 +1789,6 @@ in any circumstance unless explicitly supplied.
os.exit(0)
end
-
-- Base setup; initialize default repos if applicable, read them in. Determine Lite XL system binary if not specified, and pull in a list of all local lite-xl's.
lpm_repo_init()
repositories, lite_xls = {}, {}