diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-09-05 14:57:11 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-09-05 14:57:11 +0100 |
commit | 9b8833619780eb1c8c2fffc0f95cf93c6adb1d83 (patch) | |
tree | 8c0d72eaa3f397673374da30db0bbf7acba29b76 | |
parent | f0ec685980cf6161e74649522f3ca40e83d30071 (diff) | |
download | gitano-9b8833619780eb1c8c2fffc0f95cf93c6adb1d83.tar.gz |
GITANO: Rationalise splittable stuff and split groups on dashes and repos on slashes
-rw-r--r-- | lib/gitano/admincommand.lua | 6 | ||||
-rw-r--r-- | lib/gitano/lace.lua | 3 | ||||
-rw-r--r-- | lib/gitano/repository.lua | 13 | ||||
-rw-r--r-- | lib/gitano/util.lua | 28 |
4 files changed, 37 insertions, 13 deletions
diff --git a/lib/gitano/admincommand.lua b/lib/gitano/admincommand.lua index 8637093..5d67eba 100644 --- a/lib/gitano/admincommand.lua +++ b/lib/gitano/admincommand.lua @@ -332,9 +332,11 @@ end local function builtin_group_prep(conf, _, cmdline, context) context.operation = "group" .. cmdline[2] - context.targetgroup = cmdline[3] + util.add_splitable(context, "targetgroup", cmdline[3], + "-", "prefix", "suffix") if cmdline[2]:match("user") or cmdline[2]:match("group") then - context.member = cmdline[4] + util.add_splitable(context, "member", cmdline[4], + "-", "prefix", "suffix") end return conf.repo:run_lace(context) end diff --git a/lib/gitano/lace.lua b/lib/gitano/lace.lua index 5d125df..c98e42b 100644 --- a/lib/gitano/lace.lua +++ b/lib/gitano/lace.lua @@ -107,6 +107,7 @@ end local simples = { -- Trivial strings/lists "operation", "owner", "ref", "group", "user", "repository", + "repository/basename", "repository/dirname", -- Trees for update operations (flat lists) "start_tree", "target_tree", -- Tree diffs for update operations (flat lists) @@ -117,6 +118,8 @@ local simples = { "as_user", "as_group", -- Stuff for site admin commands "targetuser", "targetgroup", "member", + "targetgroup/prefix", "targetgroup/suffix", + "member/prefix", "member/suffix", } for _, s in ipairs(simples) do diff --git a/lib/gitano/repository.lua b/lib/gitano/repository.lua index a9a0e2f..cf4fd09 100644 --- a/lib/gitano/repository.lua +++ b/lib/gitano/repository.lua @@ -374,17 +374,8 @@ function repo_method:validate_admin_sha(sha) end function repo_method:populate_context(context) - context["repository"] = self.name - local i = 1 - for section in self.name:gmatch("([^/]+)") do - context[("repository/%d"):format(i)] = section - i = i + 1 - end - local dirname, basename = self.name:match("^(.*/)([^/]+)$") - if dirname then - context["repository/dirname"] = dirname:sub(1,-2) - end - context["repository/basename"] = basename + util.add_splitable(context, "repository", self.name, + "/", "dirname", "basename") if self.is_nascent then context["owner"] = "gitano/nobody" else diff --git a/lib/gitano/util.lua b/lib/gitano/util.lua index b0ca710..1d497c0 100644 --- a/lib/gitano/util.lua +++ b/lib/gitano/util.lua @@ -258,6 +258,32 @@ local function set(t) return ret end +local function add_splitable(context, key, value, splitter, + prefix_name, suffix_name) + if not value or value == "" then + return + end + local function _(k, v) + context[k] = v + end + _(key, value) + local prefix, suffix = value:match("^(.*%" .. splitter .. ")" .. + "([^%" .. splitter .. "]+)$") + + if prefix then + _(key .. "/" .. prefix_name, prefix:sub(1, -2)) + _(key .. "/" .. suffix_name, suffix) + else + _(key .. "/" .. suffix_name, value) + end + + local i = 1 + for section in value:gmatch("([^%" .. splitter .. "]+)") do + _(key .. "/" .. tostring(i), section) + i = i + 1 + end +end + return { parse_cmdline = _parse_cmdline, @@ -274,6 +300,8 @@ return { deep_copy = _deep_copy, prep_expansion = prep_expansion, + + add_splitable = add_splitable, process_expansion = process_expansion, set = set, |