diff options
author | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2014-03-12 14:31:25 +0000 |
---|---|---|
committer | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2014-03-12 14:31:25 +0000 |
commit | 77266b3ec2efec51f0a3246cbad70a4f15835958 (patch) | |
tree | 141ed6836821bd96cdb6248735367d0883e2ce1d /lib/gitano | |
parent | 0434ed0c1f14bb856e11925dbf45605f10734449 (diff) | |
parent | 98d9af920fb8052b47fdf7cbf2affa5617b6f089 (diff) | |
download | gitano-77266b3ec2efec51f0a3246cbad70a4f15835958.tar.gz |
Merge in rsync support from upstream.
Signed-off-by: Daniel Silverstone <daniel.silverstone@codethink.co.uk>
Diffstat (limited to 'lib/gitano')
-rw-r--r-- | lib/gitano/admincommand.lua | 16 | ||||
-rw-r--r-- | lib/gitano/auth.lua | 11 | ||||
-rw-r--r-- | lib/gitano/command.lua | 24 | ||||
-rw-r--r-- | lib/gitano/plugins.lua | 63 |
4 files changed, 93 insertions, 21 deletions
diff --git a/lib/gitano/admincommand.lua b/lib/gitano/admincommand.lua index f565e96..d0d13ce 100644 --- a/lib/gitano/admincommand.lua +++ b/lib/gitano/admincommand.lua @@ -47,18 +47,12 @@ local function builtin_as_validate(config, _, cmdline) cmdline.cmd = cmd -- If the returned command needs a repo, find it (and save it for later) local repo - if cmd.takes_repo and #cmdline > 3 then + if cmd.takes_repo then -- Acquire the repository object for the target repo - local msg - repo, msg = repository.find(config, cmdline[4]) - if not repo then - log.critical("Unable to locate repository.") - log.critical(" * " .. (tostring(msg))) - log.fatal("Cannot continue") - end - - if repo.is_nascent then - log.info("Repository " .. repo.name .. " is nascent") + repo, cmdline.copy = cmd.detect_repo(config, cmdline.copy) + if not repo and not cmdline.copy then + log.error("Unable to continue") + return false end cmdline.repo = repo end diff --git a/lib/gitano/auth.lua b/lib/gitano/auth.lua index 8cdd8ec..8f288e6 100644 --- a/lib/gitano/auth.lua +++ b/lib/gitano/auth.lua @@ -97,14 +97,9 @@ local function is_authorized(user, source, cmdline) local repo if cmd.takes_repo and #parsed_cmdline > 1 then - -- Acquire the repository object for the target repo - local msg - repo, msg = repository.find(admin_conf, parsed_cmdline[2]) - - if not repo then - log.critical("Unable to locate repository.") - log.critical(" * " .. (tostring(msg) or "No error")) - return nil + repo, parsed_cmdline = cmd.detect_repo(admin_conf, parsed_cmdline) + if not repo and not parsed_cmdline then + return nil end end diff --git a/lib/gitano/command.lua b/lib/gitano/command.lua index e55fe33..468b34b 100644 --- a/lib/gitano/command.lua +++ b/lib/gitano/command.lua @@ -13,9 +13,27 @@ local sio = require "luxio.simple" local cmds = {} +local function default_detect_repo(config, parsed_cmdline) + local repo, msg + if #parsed_cmdline > 1 then + -- Acquire the repository object for the target repo from arg 2 + repo, msg = repository.find(config, parsed_cmdline[2]) + if not repo then + log.critical("Unable to locate repository.") + log.critical(" * " .. (tostring(msg))) + return nil, nil + end + + if repo.is_nascent then + log.info("Repository " .. repo.name .. " is nascent") + end + end + return repo, parsed_cmdline +end + local function register_cmd(cmdname, short, helptext, validate_fn, prep_fn, run_fn, - takes_repo, hidden, is_admin) + takes_repo, hidden, is_admin, detect_repo) --[[ log.ddebug("Register command", cmdname) if takes_repo then @@ -35,7 +53,8 @@ local function register_cmd(cmdname, short, helptext, hidden = hidden, admin = is_admin, short = short, - helptext = helptext + helptext = helptext, + detect_repo = detect_repo or default_detect_repo } cmds[#cmds+1] = cmdname table.sort(cmds) @@ -52,6 +71,7 @@ local function get_cmd(cmdname) prep = cmd.prep, run = cmd.run, takes_repo = cmd.takes_repo, + detect_repo = cmd.detect_repo } end diff --git a/lib/gitano/plugins.lua b/lib/gitano/plugins.lua new file mode 100644 index 0000000..bdc6d1e --- /dev/null +++ b/lib/gitano/plugins.lua @@ -0,0 +1,63 @@ +-- gitano.plugins +-- +-- Plugin loading support for Gitano +-- +-- Copyright 2014 Daniel Silverstone <daniel.silverstone@codethink.co.uk> + +local util = require "gitano.util" +local log = require "gitano.log" + +local luxio = require "luxio" +local sio = require "luxio.simple" + +local gfind = string.gfind + +local plugin_name_pattern = "^(.+)%.lua$" + +local function find_plugins(path) + local ret = {} + for _, entry in ipairs(path) do + local dirp, err = sio.opendir(entry) + if not dirp then + log.warning(("Unable to scan plugin directory '%s': %s") + :format(entry, err)) + else + for filename, fileinfo in dirp:iterate() do + local plugin_name = filename:match(plugin_name_pattern) + if plugin_name and fileinfo.d_type == luxio.DT_REG then + if not ret[plugin_name] then + ret[plugin_name] = entry + ret[#ret + 1] = plugin_name + end + end + end + end + end + table.sort(ret) + return ret +end + +local function load_plugins(path) + local to_load = find_plugins(path) + for _, plugin_name in ipairs(to_load) do + local filepath = util.path_join(to_load[plugin_name], + plugin_name .. ".lua") + local chunk, err = loadfile(filepath) + if not chunk then + log.warning(("Failure loading plugin '%s' from '%s': %s") + :format(plugin_name, to_load[plugin_name], + err)) + else + local ok, err = pcall(chunk) + if not ok then + log.warning(("Failure running plugin '%s' from '%s': %s") + :format(plugin_name, to_load[plugin_name], + err)) + end + end + end +end + +return { + load_plugins = load_plugins, +} |