diff options
author | Richard Maw <richard.maw@gmail.com> | 2017-06-17 17:50:15 +0100 |
---|---|---|
committer | Richard Maw <richard.maw@gmail.com> | 2017-06-17 17:50:15 +0100 |
commit | 317740cc2b35d0cf9c716a64d2984a5f14c624c0 (patch) | |
tree | fb42c924a7b582e9cc178a238ebbb1ec23a36cd6 /lib | |
parent | 7c992daade9445584d2f233c722500d426546361 (diff) | |
download | gitano-317740cc2b35d0cf9c716a64d2984a5f14c624c0.tar.gz |
Centralise patterns into a single module
This has moved every pattern that wasn't obviously just for string manipulation
and has in the process of doing so reworked some logic
so that fewer distinct patterns are used,
and the repository path normalisation has been unified.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitano/actions.lua | 5 | ||||
-rw-r--r-- | lib/gitano/admincommand.lua | 17 | ||||
-rw-r--r-- | lib/gitano/command.lua | 15 | ||||
-rw-r--r-- | lib/gitano/config.lua | 17 | ||||
-rw-r--r-- | lib/gitano/lace.lua | 3 | ||||
-rw-r--r-- | lib/gitano/patterns.lua | 115 | ||||
-rw-r--r-- | lib/gitano/plugins.lua | 5 | ||||
-rw-r--r-- | lib/gitano/repository.lua | 54 | ||||
-rw-r--r-- | lib/gitano/supple.lua | 3 | ||||
-rw-r--r-- | lib/gitano/usercommand.lua | 5 |
10 files changed, 180 insertions, 59 deletions
diff --git a/lib/gitano/actions.lua b/lib/gitano/actions.lua index 8568d72..dbb5fe1 100644 --- a/lib/gitano/actions.lua +++ b/lib/gitano/actions.lua @@ -34,6 +34,7 @@ local util = require "gitano.util" local log = require "gitano.log" local gall = require "gall" local config = require "gitano.config" +local pat = require "gitano.patterns" local i18n = require 'gitano.i18n' local sio = require 'luxio.simple' local supple = require 'gitano.supple' @@ -106,9 +107,9 @@ local function _curl_txn(url, headers, body, content_type) if (how ~= "exit" or why ~= 0) then return "500", err, {}, "" end - local code, msg, _headers, content = response:match("^HTTP/1.[01] (...) ?([^\r\n]+)\r?\n(.-)\r?\n\r?\n(.*)$") + local code, msg, _headers, content = response:match(pat.HTTP_RESPONSE) local headers = {} - for k, v in _headers:gmatch("([^:\r\n]+): *([^\r\n]+)") do + for k, v in _headers:gmatch(pat.HTTP_HEADER) do local r = headers[k] or {} r[#r+1] = v headers[k] = r diff --git a/lib/gitano/admincommand.lua b/lib/gitano/admincommand.lua index cb60851..3dd3258 100644 --- a/lib/gitano/admincommand.lua +++ b/lib/gitano/admincommand.lua @@ -34,6 +34,7 @@ local log = require 'gitano.log' local util = require 'gitano.util' local repository = require 'gitano.repository' local config = require 'gitano.config' +local pat = require 'gitano.patterns' local clod = require 'clod' local luxio = require 'luxio' local sio = require 'luxio.simple' @@ -176,7 +177,7 @@ local function builtin_user_validate(conf, _, cmdline) log.error("user add takes a username, email address and real name") return false end - if cmdline[2] == "add" and not cmdline[3]:match("^[a-z][a-z0-9_.-]+$") then + if cmdline[2] == "add" and not cmdline[3]:match(pat.VALID_USERNAME) then log.error("user name '" .. cmdline[3] .. "' not valid.") return false end @@ -406,7 +407,7 @@ local function builtin_group_validate(conf, _, cmdline) log.error("Add takes a group name and a description") return false end - if cmdline[2] == "add" and not cmdline[3]:match("^[a-z][a-z0-9_.-]+$") then + if cmdline[2] == "add" and not cmdline[3]:match(pat.VALID_GROUPNAME) then log.error("group name '" .. cmdline[3] .. "' not valid.") return false end @@ -739,7 +740,7 @@ local function builtin_keyring_validate(conf, _, cmdline) if #cmdline > 3 then local ok = true for i = 4, #cmdline do - if not cmdline[i]:match("^" .. string.rep("[0-9A-Fa-f]", 40) .. "$") then + if not cmdline[i]:match(pat.VALID_KEY_FINGERPINRT) then log.error("error: '" .. cmdline[i] .. "' is not a valid fingerprint") ok = false end @@ -750,7 +751,7 @@ local function builtin_keyring_validate(conf, _, cmdline) end if cmdline[2] == "delkey" then if #cmdline == 4 or #cmdline == 5 then - if not cmdline[4]:match("^" .. string.rep("[0-9A-Fa-f]", 40) .. "$") then + if not cmdline[4]:match(pat.VALID_KEY_FINGERPRINT) then log.error("error: '" .. cmdline[i] .. "' is not a valid fingerprint") return false end @@ -795,7 +796,7 @@ local function builtin_keyring_run(conf, _, cmdline, env) log.error("Keyring " .. keyringname .. " already exists") return "exit", 1 end - if not keyringname:match("^[a-z][a-z0-9_.-]+$") then + if not keyringname:match(pat.VALID_KEYRING_NAME) then log.error("Keyring " .. keyringname .. " is not lower-alphanumeric") return "exit", 1 end @@ -867,7 +868,7 @@ local function builtin_keyring_run(conf, _, cmdline, env) if code ~= 0 then log.fatal("Unable to list keyring: GPG returned " .. tostring(code)) end - for fingerprint in alloutput:gmatch("fpr:::::::::([0-9A-F]+):") do + for fingerprint in alloutput:gmatch(pat.GPG_OUTPUT_FINGERPRINT_MATCH) do log.stdout(fingerprint) end end @@ -1149,7 +1150,7 @@ local function builtin_graveyard_run(conf, _, cmdline, env) repeat e, i = luxio.readdir(dirp) if e == 0 then - if not i.d_name:find("^%.") then + if not i.d_name:find(pat.DOTFILE) then log.stdout(i.d_name) end end @@ -1200,7 +1201,7 @@ local function builtin_graveyard_run(conf, _, cmdline, env) repeat e, i = luxio.readdir(dirp) if e == 0 then - if not i.d_name:find("^%.") then + if not i.d_name:find(pat.DOTFILE) then if not match or (match == i.d_name) then to_remove[#to_remove+1] = i.d_name end diff --git a/lib/gitano/command.lua b/lib/gitano/command.lua index f581dc1..3f433ca 100644 --- a/lib/gitano/command.lua +++ b/lib/gitano/command.lua @@ -33,6 +33,7 @@ local log = require 'gitano.log' local util = require 'gitano.util' local repository = require 'gitano.repository' +local pattern = require 'gitano.patterns' local sio = require "luxio.simple" @@ -241,7 +242,7 @@ local function builtin_help_run(config, repo, cmdline, env) log.state(cmd.name, do_sep(cmd), desc) if cmd.helptext then log.state("") - for line in (cmd.helptext):gmatch("([^\n]*)\n") do + for line in (cmd.helptext):gmatch(pattern.TEXT_LINE) do log.state("=>", line) end end @@ -453,9 +454,9 @@ local function builtin_config_validate(conf, repo, cmdline) return false end cmdline.orig_key = cmdline[4] - if cmdline[4]:match("%.%*$") then + if cmdline[4]:match(pattern.CONF_ENDS_WILDCARD) then -- Doing a wild removal, expand it now - local prefix = cmdline[4]:match("^(.+)%.%*$") + local prefix = cmdline[4]:match(pattern.CONF_WILDCARD) cmdline[4] = nil for k in repo.project_config:each(prefix) do cmdline[#cmdline+1] = k @@ -525,7 +526,7 @@ local function builtin_config_run(conf, repo, cmdline, env) for i = 1, #slist do local key = slist[i] local value = repo.project_config.settings[key] - local prefix = key:match("^(.+)%.i_[0-9]+$") + local prefix = key:match(pattern.CONF_ARRAY_INDEX) if prefix then local neatkey = prefix .. ".*" for i = 4, #cmdline do @@ -539,7 +540,7 @@ local function builtin_config_run(conf, repo, cmdline, env) end elseif cmdline[3] == "set" then local key, value = cmdline[4], cmdline[5] - local vtype, rest = value:match("^([sbi]):(.*)$") + local vtype, rest = value:match(pattern.CONF_SET_TYPE_PREFIX) if vtype then if vtype == "s" then value = rest @@ -839,9 +840,9 @@ local function builtin_ls_run(config, _, cmdline, env) pat = pat .. ".*" end if used_evil then - pat = "^/" .. pat .. "%.git$" + pat = "^/" .. pat .. pattern.GIT_REPO_SUFFIX else - pat = "/" .. pat .. "%.git$" + pat = "/" .. pat .. pattern.GIT_REPO_SUFFIX end log.debug("PAT:", pat) pats[#pats+1] = pat diff --git a/lib/gitano/config.lua b/lib/gitano/config.lua index a582db1..7227866 100644 --- a/lib/gitano/config.lua +++ b/lib/gitano/config.lua @@ -38,6 +38,7 @@ local gall = require 'gall' local log = require 'gitano.log' local lace = require 'gitano.lace' local i18n = require 'gitano.i18n' +local pat = require 'gitano.patterns' local luxio = require 'luxio' local sio = require 'luxio.simple' local clod = require 'clod' @@ -109,7 +110,7 @@ local function parse_admin_config(commit) -- Gather the users local users = {} for filename, obj in pairs(flat_tree) do - local prefix, username = filename:match("^(users/.-)([a-z][a-z0-9_.-]+)/user%.conf$") + local prefix, username = filename:match(pat.USER_CONF_MATCH) if prefix and username then if not is_blob(obj) then return nil, prefix .. username .. "/user.conf is not a blob?" @@ -144,7 +145,7 @@ local function parse_admin_config(commit) -- Now gather the users' keys local all_keys = {} for filename, obj in pairs(flat_tree) do - local prefix, username, keyname = filename:match("^(users/.-)([a-z][a-z0-9_.-]+)/([a-z][a-z0-9_.-]+)%.key$") + local prefix, username, keyname = filename:match(pat.USER_KEY_MATCH) if prefix and username and keyname then if not users[username] then return nil, i18n.expand("ERROR_ORPHAN_KEY", @@ -158,7 +159,7 @@ local function parse_admin_config(commit) return nil, i18n.expand("ERROR_BAD_KEY_NEWLINES", {filename=filename}) end - local keytype, keydata, keytag = this_key:match("^([^ ]+) ([^ ]+) ([^ ].*)$") + local keytype, keydata, keytag = this_key:match(pat.SSH_KEY_CONTENTS) if not (keytype and keydata and keytag) then return nil, i18n.expand("ERROR_BAD_KEY_SMELL", {filename=filename}) end @@ -190,7 +191,7 @@ local function parse_admin_config(commit) -- Now gather the groups local groups = {} for filename, obj in pairs(flat_tree) do - local prefix, groupname = filename:match("^(groups/.-)([a-z][a-z0-9_.-]+)%.conf$") + local prefix, groupname = filename:match(pat.GROUP_CONF_MATCH) if prefix and groupname then if groups[groupname] then return nil, i18n.expand("ERROR_DUPLICATE_GROUP", {name=groupname}) @@ -269,7 +270,7 @@ local function parse_admin_config(commit) -- Now gather the keyrings local keyrings = {} for filename, obj in pairs(flat_tree) do - local prefix, keyringname = filename:match("^(keyrings/.-)([a-z][a-z0-9_.-]+)%.gpg$") + local prefix, keyringname = filename:match(pat.KEYRING_MATCH) if prefix and keyringname then if keyrings[keyringname] then return nil, i18n.expand("ERROR_DUPLICATE_KEYRING", {name=keyringname}) @@ -440,9 +441,9 @@ local function commit_config_changes(conf, desc, author, committer) -- Shallow copy the tree ready for mods, skipping keyrings, users and groups for k,v in pairs(conf.content) do - if not (k:match("^users/") or - k:match("^groups/") or - k:match("^keyrings/")) then + if not (k:match(pat.USER_INFO_PREFIX) or + k:match(pat.GROUP_INFO_PREFIX) or + k:match(pat.KEYRING_INFO_PREFIX)) then newtree[k] = v end end diff --git a/lib/gitano/lace.lua b/lib/gitano/lace.lua index 2ba0634..685d625 100644 --- a/lib/gitano/lace.lua +++ b/lib/gitano/lace.lua @@ -35,6 +35,7 @@ local util = require 'gitano.util' local gall = require 'gall' local log = require 'gitano.log' local i18n = require 'gitano.i18n' +local pat = require 'gitano.patterns' local pcre = require "rex_pcre" @@ -45,7 +46,7 @@ include global:core } local function _loader(ctx, _name) - local global_name = _name:match("^global:(.+)$") + local global_name = _name:match(pat.LACE_GLOBAL_DEFINITION) local name, tree, sha = global_name or _name if not global_name then -- Project load diff --git a/lib/gitano/patterns.lua b/lib/gitano/patterns.lua new file mode 100644 index 0000000..ede4541 --- /dev/null +++ b/lib/gitano/patterns.lua @@ -0,0 +1,115 @@ +-- gitano.patterns +-- +-- Internal centralised pattern definitions. Not stable ABI. +-- +-- Copyright 2017 Richard Maw <richard.maw@gmail.com> +-- All rights reserved. +-- +-- Redistribution and use in source and binary forms, with or without +-- modification, are permitted provided that the following conditions +-- are met: +-- 1. Redistributions of source code must retain the above copyright +-- notice, this list of conditions and the following disclaimer. +-- 2. Redistributions in binary form must reproduce the above copyright +-- notice, this list of conditions and the following disclaimer in the +-- documentation and/or other materials provided with the distribution. +-- 3. Neither the name of the author nor the names of their contributors +-- may be used to endorse or promote products derived from this software +-- without specific prior written permission. +-- +-- THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +-- ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +-- SUCH DAMAGE. +-- + +local _NICE_NAME = "[a-z][a-z0-9_.-]+" +local _STARTS_DOT = "^%." +local _ENDS_DOTSTAR = "%.%*$" +local _HEX40 = string.rep("[0-9A-Fa-f]", 40) + +local TEXT_LINE = "([^\n]*)\n" + +local DOTFILE = _STARTS_DOT + +local VALID_USERNAME = "^" .. _NICE_NAME .. "$" +local VALID_SSHKEYNAME = "^" .. _NICE_NAME .. "$" +local USER_INFO_PREFIX = "^(users/.-)(".. _NICE_NAME .. ")/" +local USER_CONF_MATCH = USER_INFO_PREFIX .. "user%.conf$" +local USER_KEY_MATCH = USER_INFO_PREFIX .. "(" .. _NICE_NAME .. ")%.key$" + +local SSH_KEY_CONTENTS = "^([^ ]+) ([^ ]+) ([^ ].*)$" + +local VALID_GROUPNAME = "^" .. _NICE_NAME .. "$" +local GROUP_INFO_PREFIX = "^(groups/.-)(".. _NICE_NAME .. ")" +local GROUP_CONF_MATCH = GROUP_INFO_PREFIX .. "%.conf$" + +local VALID_KEY_FINGERPRINT = "^" .. _HEX40 .. "$" +local VALID_KEYRING_NAME = "^" .. _NICE_NAME .. "$" +local KEYRING_INFO_PREFIX = "^(keyrings/.-)(".. _NICE_NAME .. ")" +local KEYRING_MATCH = KEYRING_INFO_PREFIX .. "%.gpg$" + +local GPG_OUTPUT_FINGERPRINT_MATCH = "fpr:::::::::([0-9A-F]+):" + +local HTTP_RESPONSE = "^HTTP/1.[01] (...) ?([^\r\n]+)\r?\n(.-)\r?\n\r?\n(.*)$" +local HTTP_HEADER = "([^:\r\n]+): *([^\r\n]+)" + +local CONF_ENDS_WILDCARD = _ENDS_DOTSTAR +local CONF_WILDCARD = "^(.+)" .. CONF_ENDS_WILDCARD +local CONF_ARRAY_INDEX = "^(.+)%.i_[0-9]+$" +local CONF_SET_TYPE_PREFIX = "^([sbi]):(.*)$" + +local GIT_REPO_SUFFIX = "%.git$" +local GIT_REPO_NAME_MATCH = "^(.+)" .. GIT_REPO_SUFFIX + +local LACE_GLOBAL_DEFINITION = "^global:(.+)$" + +local PLUGIN_NAME = "^([^_]+)%.lua$" + +local REF_IS_NORMALISED = "^refs/" + +local PARSE_TIME_AND_TZOFFSET = "^([0-9]+) ([+-][0-9]+)$" + +local SUPPLE_MODULE_LOAD_MATCH = "^([^%.]+)%.(.+)$" + +local GITHOOK_PARSE_CHANGESET = "([^ ]+) ([^ ]+) ([^\n]+)\n?" + +return { + TEXT_LINE = TEXT_LINE, + DOTFILE = DOTFILE, + VALID_USERNAME = VALID_USERNAME, + VALID_SSHKEYNAME = VALID_SSHKEYNAME, + USER_INFO_PREFIX = USER_INFO_PREFIX, + USER_CONF_MATCH = USER_CONF_MATCH, + USER_KEY_MATCH = USER_KEY_MATCH, + SSH_KEY_CONTENTS = SSH_KEY_CONTENTS, + VALID_GROUPNAME = VALID_GROUPNAME, + GROUP_INFO_PREFIX = GROUP_INFO_PREFIX, + GROUP_CONF_MATCH = GROUP_CONF_MATCH, + VALID_KEY_FINGERPRINT = VALID_KEY_FINGERPRINT, + VALID_KEYRING_NAME = VALID_KEYRING_NAME, + KEYRING_INFO_PREFIX = KEYRING_INFO_PREFIX, + KEYRING_MATCH = KEYRING_MATCH, + GPG_OUTPUT_FINGERPRINT_MATCH = GPG_OUTPUT_FINGERPRINT_MATCH, + HTTP_RESPONSE = HTTP_RESPONSE, + HTTP_HEADER = HTTP_HEADER, + CONF_ENDS_WILDCARD = CONF_ENDS_WILDCARD, + CONF_WILDCARD = CONF_WILDCARD, + CONF_ARRAY_INDEX = CONF_ARRAY_INDEX, + CONF_SET_TYPE_PREFIX = CONF_SET_TYPE_PREFIX, + GIT_REPO_SUFFIX = GIT_REPO_SUFFIX, + GIT_REPO_NAME_MATCH = GIT_REPO_NAME_MATCH, + LACE_GLOBAL_DEFINITION = LACE_GLOBAL_DEFINITION, + PLUGIN_NAME = PLUGIN_NAME, + REF_IS_NORMALISED = REF_IS_NORMALISED, + PARSE_TIME_AND_TZOFFSET = PARSE_TIME_AND_TZOFFSET, + SUPPLE_MODULE_LOAD_MATCH = SUPPLE_MODULE_LOAD_MATCH, + GITHOOK_PARSE_CHANGESET = GITHOOK_PARSE_CHANGESET, +} diff --git a/lib/gitano/plugins.lua b/lib/gitano/plugins.lua index fd393ef..81546e6 100644 --- a/lib/gitano/plugins.lua +++ b/lib/gitano/plugins.lua @@ -33,14 +33,13 @@ local util = require "gitano.util" local log = require "gitano.log" local i18n = require "gitano.i18n" +local pat = require "gitano.patterns" 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 @@ -50,7 +49,7 @@ local function find_plugins(path) {dir=entry, reason=err})) else for filename, fileinfo in dirp:iterate() do - local plugin_name = filename:match(plugin_name_pattern) + local plugin_name = filename:match(pat.PLUGIN_NAME) if plugin_name then if not ret[plugin_name] then ret[plugin_name] = entry diff --git a/lib/gitano/repository.lua b/lib/gitano/repository.lua index b7e2ccc..be6a689 100644 --- a/lib/gitano/repository.lua +++ b/lib/gitano/repository.lua @@ -40,6 +40,7 @@ local config = require 'gitano.config' local util = require 'gitano.util' local lace = require 'gitano.lace' local i18n = require 'gitano.i18n' +local pat = require 'gitano.patterns' local clod = require 'clod' local base_rules = [[ @@ -455,8 +456,8 @@ function repo_method:populate_context(context) if not self.is_nascent then local lists_to_add = {} for k, v in self.project_config:each() do - if k:match("%.i_[0-9]+$") then - lists_to_add[k:gsub("%.i_[0-9]+$", "")] = true + if k:match(pat.CONF_ARRAY_INDEX) then + lists_to_add[k:match(pat.CONF_ARRAY_INDEX)] = true else local confkey = "config/" .. k:gsub("%.", "/") context[confkey] = v @@ -512,7 +513,7 @@ function repo_method:conf_set_and_save(conf, newvalue, author, committer) end function repo_method:set_head(newhead, author, committer) - if not newhead:match("^refs/") then + if not newhead:match(pat.REF_IS_NORMALISED) then newhead = "refs/heads/" .. newhead end local oldhead = self:conf_get "project.head" @@ -568,15 +569,27 @@ function repo_method:destroy_self(call_me) return true end +local function normalise_repo_path(reponame) + -- Inject a leading '/' + reponame = "/" .. reponame + -- Remove any spaces, tabs, newlines or nulls + reponame = reponame:gsub("[%s%z]+", "") + -- Remove any '.' which follows a '/' + reponame = reponame:gsub("/%.+", "/") + -- simplify any sequence of '/' to a single '/' + reponame = reponame:gsub("/+", "/") + -- Remove any leading or trailing / + reponame = reponame:match("^/*(.-)/*$") + -- Remove trailing .git if present. + if reponame:match("."..pat.GIT_REPO_SUFFIX) then + reponame = reponame:match(pat.GIT_REPO_NAME_MATCH) + end + return reponame +end + function repo_method:rename_to(somename) -- Same cleanup as in find... - if somename:match(".%.git$") then - somename = somename:match("^(.+)%.git$") - end - -- Remove any '.' - somename = somename:gsub("%.", "") - -- Remove any leading or trailing / - somename = somename:match("^/*(.-)/*$") + somename = normalise_repo_path(somename) local newpath = self.fs_path({name=somename,config=self.config}) @@ -679,7 +692,7 @@ function repo_method:update_modified_date(shas) if f then local s = f:read("*l") if s then - local cur_mod_time, cur_mod_offset = s:find("^([0-9]+) ([+-][0-9]+)$") + local cur_mod_time, cur_mod_offset = s:find(pat.PARSE_TIME_AND_TZOFFSET) if cur_mod_time then update_based_on(cur_mod_time, cur_mod_offset) end @@ -830,20 +843,7 @@ local function find_repository(config, reponame) -- -- If the repository exists, then it is examined and brought up-to-date -- with any global config changes before being returned. - -- Inject a leading '/' - reponame = "/" .. reponame - -- Remove any spaces, tabs, newlines or nulls - reponame = reponame:gsub("[%s%z]+", "") - -- Remove any '.' which follows a '/' - reponame = reponame:gsub("/%.+", "/") - -- simplify any sequence of '/' to a single '/' - reponame = reponame:gsub("/+", "/") - -- Remove any leading or trailing / - reponame = reponame:match("^/*(.-)/*$") - -- Remove trailing .git if present. - if reponame:match(".%.git$") then - reponame = reponame:match("^(.+)%.git$") - end + reponame = normalise_repo_path(reponame) -- Construct the repo local repo = setmetatable({config = config, name = reponame}, repo_meta) @@ -904,12 +904,12 @@ local function foreach_repository(conf, callback, filterfn) repeat e, i = luxio.readdir(dirp) if e == 0 then - if i.d_name:find("%.git$") then + if i.d_name:match(pat.GIT_REPO_SUFFIX) then -- Might be a repo, save for later all_repos[#all_repos+1] = (util.path_join(prefix, i.d_name) ):gsub("^/", "") else - if i.d_name:find("^[^%.]") then + if not i.d_name:match(pat.DOTFILE) then recurse[#recurse+1] = i.d_name end end diff --git a/lib/gitano/supple.lua b/lib/gitano/supple.lua index 79ca3b4..49d62b1 100644 --- a/lib/gitano/supple.lua +++ b/lib/gitano/supple.lua @@ -36,6 +36,7 @@ local supple = require 'supple' local log = require 'gitano.log' local config = require 'gitano.config' local i18n = require 'gitano.i18n' +local pat = require 'gitano.patterns' local repo_proxies = {} local proxied_repo = {} @@ -112,7 +113,7 @@ local function load_repo_module(fromrepo, prefix, module) end local function load_module_src(modname) - local pfx, mod = modname:match("^([^%.]+)%.(.+)$") + local pfx, mod = modname:match(pat.SUPPLE_MODULE_LOAD_MATCH) if not (pfx and mod) then error(i18n.expand("ERROR_NOT_RIGHT_NAME_FORMAT", {modname=modname})) end diff --git a/lib/gitano/usercommand.lua b/lib/gitano/usercommand.lua index 49f4694..5d3d7ac 100644 --- a/lib/gitano/usercommand.lua +++ b/lib/gitano/usercommand.lua @@ -34,6 +34,7 @@ local log = require 'gitano.log' local util = require 'gitano.util' local repository = require 'gitano.repository' local config = require 'gitano.config' +local pat = require 'gitano.patterns' local sio = require 'luxio.simple' local subprocess = require 'luxio.subprocess' @@ -155,7 +156,7 @@ local function builtin_sshkey_validate(config, _, cmdline) log.error("sshkey", cmdline[2] .. ": Expected tag and no more") return false end - if not cmdline[3]:match("^[a-z][a-z0-9_-]+$") then + if not cmdline[3]:match(pat.VALID_SSHKEYNAME) then log.error("sshkey:", cmdline[3], "is not a valid tag name.") log.state("Tag names start with a letter and may contain only letters") log.state("and numbers, underscores and dashes. Tag names must be at") @@ -211,7 +212,7 @@ local function builtin_sshkey_run(conf, _, cmdline, env) end elseif cmdline[2] == "add" then local sshkey = sio.stdin:read("*l") - local keytype, keydata, keytag = sshkey:match("^([^ ]+) ([^ ]+) ([^ ].*)$") + local keytype, keydata, keytag = sshkey:match(pat.SSH_KEY_CONTENTS) if not (keytype and keydata and keytag) then log.error("Unable to parse key,", filename, "did not smell like an OpenSSH v2 key") |