aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-03-29 19:11:26 -0300
committerHisham Muhammad <hisham@gobolinux.org>2018-04-11 14:38:06 -0300
commit4941a48407f08544c5517542ffc11b0c26fd4236 (patch)
tree4201643b3ee4fdb3fc3f2c610a9e0bcd964cb365 /src
parentbfc77ef7989d8a07f53681bde17c0c33b1734404 (diff)
downloadluarocks-4941a48407f08544c5517542ffc11b0c26fd4236.tar.gz
luarocks-4941a48407f08544c5517542ffc11b0c26fd4236.tar.bz2
luarocks-4941a48407f08544c5517542ffc11b0c26fd4236.zip
Beginning support for namespaced queries
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/cmd/install.lua3
-rw-r--r--src/luarocks/cmd/list.lua7
-rw-r--r--src/luarocks/cmd/purge.lua5
-rw-r--r--src/luarocks/cmd/remove.lua3
-rw-r--r--src/luarocks/cmd/search.lua4
-rw-r--r--src/luarocks/deps.lua6
-rw-r--r--src/luarocks/download.lua6
-rw-r--r--src/luarocks/manif/writer.lua5
-rw-r--r--src/luarocks/queries.lua96
-rw-r--r--src/luarocks/remove.lua7
-rw-r--r--src/luarocks/search.lua66
11 files changed, 132 insertions, 76 deletions
diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.lua
index 018e9246..6901a680 100644
--- a/src/luarocks/cmd/install.lua
+++ b/src/luarocks/cmd/install.lua
@@ -11,6 +11,7 @@ local deps = require("luarocks.deps")
11local writer = require("luarocks.manif.writer") 11local writer = require("luarocks.manif.writer")
12local remove = require("luarocks.remove") 12local remove = require("luarocks.remove")
13local search = require("luarocks.search") 13local search = require("luarocks.search")
14local queries = require("luarocks.queries")
14local cfg = require("luarocks.core.cfg") 15local cfg = require("luarocks.core.cfg")
15 16
16install.help_summary = "Install a rock." 17install.help_summary = "Install a rock."
@@ -174,7 +175,7 @@ function install.command(flags, name, version)
174 writer.check_dependencies(nil, deps.get_deps_mode(flags)) 175 writer.check_dependencies(nil, deps.get_deps_mode(flags))
175 return name, version 176 return name, version
176 else 177 else
177 local url, err = search.find_suitable_rock(search.make_query(name:lower(), version)) 178 local url, err = search.find_suitable_rock(queries.new(name:lower(), version))
178 if not url then 179 if not url then
179 return nil, err 180 return nil, err
180 end 181 end
diff --git a/src/luarocks/cmd/list.lua b/src/luarocks/cmd/list.lua
index ed94bc68..e07c4ff3 100644
--- a/src/luarocks/cmd/list.lua
+++ b/src/luarocks/cmd/list.lua
@@ -4,6 +4,7 @@
4local list = {} 4local list = {}
5 5
6local search = require("luarocks.search") 6local search = require("luarocks.search")
7local queries = require("luarocks.queries")
7local vers = require("luarocks.vers") 8local vers = require("luarocks.vers")
8local cfg = require("luarocks.core.cfg") 9local cfg = require("luarocks.core.cfg")
9local util = require("luarocks.util") 10local util = require("luarocks.util")
@@ -31,8 +32,7 @@ local function check_outdated(trees, query)
31 table.sort(versions, vers.compare_versions) 32 table.sort(versions, vers.compare_versions)
32 local latest_installed = versions[1] 33 local latest_installed = versions[1]
33 34
34 local query_available = search.make_query(name:lower()) 35 local query_available = queries.new(name:lower(), nil, false)
35 query.exact_name = true
36 local results_available, err = search.search_repos(query_available) 36 local results_available, err = search.search_repos(query_available)
37 37
38 if results_available[name] then 38 if results_available[name] then
@@ -69,8 +69,7 @@ end
69-- @param version string or nil: a version may also be passed. 69-- @param version string or nil: a version may also be passed.
70-- @return boolean: True if succeeded, nil on errors. 70-- @return boolean: True if succeeded, nil on errors.
71function list.command(flags, filter, version) 71function list.command(flags, filter, version)
72 local query = search.make_query(filter and filter:lower() or "", version) 72 local query = queries.new(filter and filter:lower() or "", version, true)
73 query.exact_name = false
74 local trees = cfg.rocks_trees 73 local trees = cfg.rocks_trees
75 if flags["tree"] then 74 if flags["tree"] then
76 trees = { flags["tree"] } 75 trees = { flags["tree"] }
diff --git a/src/luarocks/cmd/purge.lua b/src/luarocks/cmd/purge.lua
index bbce9f8c..15efb0ef 100644
--- a/src/luarocks/cmd/purge.lua
+++ b/src/luarocks/cmd/purge.lua
@@ -12,6 +12,7 @@ local repos = require("luarocks.repos")
12local writer = require("luarocks.manif.writer") 12local writer = require("luarocks.manif.writer")
13local cfg = require("luarocks.core.cfg") 13local cfg = require("luarocks.core.cfg")
14local remove = require("luarocks.remove") 14local remove = require("luarocks.remove")
15local queries = require("luarocks.queries")
15 16
16purge.help_summary = "Remove all installed rocks from a tree." 17purge.help_summary = "Remove all installed rocks from a tree."
17purge.help_arguments = "--tree=<tree> [--old-versions]" 18purge.help_arguments = "--tree=<tree> [--old-versions]"
@@ -37,8 +38,6 @@ function purge.command(flags)
37 end 38 end
38 39
39 local results = {} 40 local results = {}
40 local query = search.make_query("")
41 query.exact_name = false
42 if not fs.is_dir(tree) then 41 if not fs.is_dir(tree) then
43 return nil, "Directory not found: "..tree 42 return nil, "Directory not found: "..tree
44 end 43 end
@@ -46,7 +45,7 @@ function purge.command(flags)
46 local ok, err = fs.check_command_permissions(flags) 45 local ok, err = fs.check_command_permissions(flags)
47 if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end 46 if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end
48 47
49 search.manifest_search(results, path.rocks_dir(tree), query) 48 search.manifest_search(results, path.rocks_dir(tree), queries.all())
50 49
51 local sort = function(a,b) return vers.compare_versions(b,a) end 50 local sort = function(a,b) return vers.compare_versions(b,a) end
52 if flags["old-versions"] then 51 if flags["old-versions"] then
diff --git a/src/luarocks/cmd/remove.lua b/src/luarocks/cmd/remove.lua
index b8148ba7..2624854d 100644
--- a/src/luarocks/cmd/remove.lua
+++ b/src/luarocks/cmd/remove.lua
@@ -11,6 +11,7 @@ local search = require("luarocks.search")
11local path = require("luarocks.path") 11local path = require("luarocks.path")
12local deps = require("luarocks.deps") 12local deps = require("luarocks.deps")
13local writer = require("luarocks.manif.writer") 13local writer = require("luarocks.manif.writer")
14local queries = require("luarocks.queries")
14 15
15cmd_remove.help_summary = "Uninstall a rock." 16cmd_remove.help_summary = "Uninstall a rock."
16cmd_remove.help_arguments = "[--force|--force-fast] <name> [<version>]" 17cmd_remove.help_arguments = "[--force|--force-fast] <name> [<version>]"
@@ -50,7 +51,7 @@ function cmd_remove.command(flags, name, version)
50 51
51 local results = {} 52 local results = {}
52 name = name:lower() 53 name = name:lower()
53 search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version)) 54 search.manifest_search(results, cfg.rocks_dir, queries.new(name, version))
54 if not results[name] then 55 if not results[name] then
55 return nil, "Could not find rock '"..name..(version and " "..version or "").."' in "..path.rocks_tree_to_string(cfg.root_dir) 56 return nil, "Could not find rock '"..name..(version and " "..version or "").."' in "..path.rocks_tree_to_string(cfg.root_dir)
56 end 57 end
diff --git a/src/luarocks/cmd/search.lua b/src/luarocks/cmd/search.lua
index d12f5314..ccdbda7b 100644
--- a/src/luarocks/cmd/search.lua
+++ b/src/luarocks/cmd/search.lua
@@ -6,6 +6,7 @@ local cmd_search = {}
6local cfg = require("luarocks.core.cfg") 6local cfg = require("luarocks.core.cfg")
7local util = require("luarocks.util") 7local util = require("luarocks.util")
8local search = require("luarocks.search") 8local search = require("luarocks.search")
9local queries = require("luarocks.queries")
9 10
10cmd_search.help_summary = "Query the LuaRocks servers." 11cmd_search.help_summary = "Query the LuaRocks servers."
11cmd_search.help_arguments = "[--source] [--binary] { <name> [<version>] | --all }" 12cmd_search.help_arguments = "[--source] [--binary] { <name> [<version>] | --all }"
@@ -55,8 +56,7 @@ function cmd_search.command(flags, name, version)
55 return nil, "Enter name and version or use --all. "..util.see_help("search") 56 return nil, "Enter name and version or use --all. "..util.see_help("search")
56 end 57 end
57 58
58 local query = search.make_query(name:lower(), version) 59 local query = queries.new(name:lower(), version, true)
59 query.exact_name = false
60 local results, err = search.search_repos(query) 60 local results, err = search.search_repos(query)
61 local porcelain = flags["porcelain"] 61 local porcelain = flags["porcelain"]
62 local full_name = name .. (version and " " .. version or "") 62 local full_name = name .. (version and " " .. version or "")
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua
index 015e2527..229c3843 100644
--- a/src/luarocks/deps.lua
+++ b/src/luarocks/deps.lua
@@ -8,6 +8,7 @@ local path = require("luarocks.path")
8local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
9local util = require("luarocks.util") 9local util = require("luarocks.util")
10local vers = require("luarocks.vers") 10local vers = require("luarocks.vers")
11local queries = require("luarocks.queries")
11 12
12--- Attempt to match a dependency to an installed rock. 13--- Attempt to match a dependency to an installed rock.
13-- @param dep table: A dependency parsed in table format. 14-- @param dep table: A dependency parsed in table format.
@@ -90,8 +91,7 @@ local function values_set(tbl)
90end 91end
91 92
92local function rock_status(name, deps_mode, rocks_provided) 93local function rock_status(name, deps_mode, rocks_provided)
93 local search = require("luarocks.search") 94 local installed = match_dep(queries.new(name), nil, deps_mode, rocks_provided)
94 local installed = match_dep(search.make_query(name), nil, deps_mode, rocks_provided)
95 local installation_type = rocks_provided[name] and "provided by VM" or "installed" 95 local installation_type = rocks_provided[name] and "provided by VM" or "installed"
96 return installed and installed.." "..installation_type or "not installed" 96 return installed and installed.." "..installation_type or "not installed"
97end 97end
@@ -184,7 +184,7 @@ function deps.fulfill_dependencies(rockspec, deps_mode)
184 return nil, "Failed matching dependencies" 184 return nil, "Failed matching dependencies"
185 end 185 end
186 186
187 local url, search_err = search.find_suitable_rock(dep) 187 local url, search_err = search.find_suitable_rock(queries.from_constraints(dep.name, dep.constraints))
188 if not url then 188 if not url then
189 return nil, "Could not satisfy dependency "..vers.show_dep(dep)..": "..search_err 189 return nil, "Could not satisfy dependency "..vers.show_dep(dep)..": "..search_err
190 end 190 end
diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua
index ec9996b2..77564b52 100644
--- a/src/luarocks/download.lua
+++ b/src/luarocks/download.lua
@@ -3,6 +3,7 @@ local download = {}
3local path = require("luarocks.path") 3local path = require("luarocks.path")
4local fetch = require("luarocks.fetch") 4local fetch = require("luarocks.fetch")
5local search = require("luarocks.search") 5local search = require("luarocks.search")
6local queries = require("luarocks.queries")
6local fs = require("luarocks.fs") 7local fs = require("luarocks.fs")
7local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
8local cfg = require("luarocks.core.cfg") 9local cfg = require("luarocks.core.cfg")
@@ -22,12 +23,11 @@ local function get_file(filename)
22end 23end
23 24
24function download.download(arch, name, version, all) 25function download.download(arch, name, version, all)
25 local query = search.make_query(name, version) 26 local substring = (all and name == "")
26 if arch then query.arch = arch end 27 local query = queries.new(name, version, substring, arch)
27 local search_err 28 local search_err
28 29
29 if all then 30 if all then
30 if name == "" then query.exact_name = false end
31 local results = search.search_repos(query) 31 local results = search.search_repos(query)
32 local has_result = false 32 local has_result = false
33 local all_ok = true 33 local all_ok = true
diff --git a/src/luarocks/manif/writer.lua b/src/luarocks/manif/writer.lua
index 2d17d328..e6edd27d 100644
--- a/src/luarocks/manif/writer.lua
+++ b/src/luarocks/manif/writer.lua
@@ -13,6 +13,7 @@ local fetch = require("luarocks.fetch")
13local path = require("luarocks.path") 13local path = require("luarocks.path")
14local persist = require("luarocks.persist") 14local persist = require("luarocks.persist")
15local manif = require("luarocks.manif") 15local manif = require("luarocks.manif")
16local queries = require("luarocks.queries")
16 17
17--- Update storage table to account for items provided by a package. 18--- Update storage table to account for items provided by a package.
18-- @param storage table: a table storing items in the following format: 19-- @param storage table: a table storing items in the following format:
@@ -296,9 +297,7 @@ function writer.make_manifest(repo, deps_mode, remote)
296 return nil, "Cannot access repository at "..repo 297 return nil, "Cannot access repository at "..repo
297 end 298 end
298 299
299 local query = search.make_query("") 300 local query = queries.all("any")
300 query.exact_name = false
301 query.arch = "any"
302 local results = search.disk_search(repo, query) 301 local results = search.disk_search(repo, query)
303 local manifest = { repository = {}, modules = {}, commands = {} } 302 local manifest = { repository = {}, modules = {}, commands = {} }
304 303
diff --git a/src/luarocks/queries.lua b/src/luarocks/queries.lua
new file mode 100644
index 00000000..5bd7462e
--- /dev/null
+++ b/src/luarocks/queries.lua
@@ -0,0 +1,96 @@
1
2local queries = {}
3
4local vers = require("luarocks.vers")
5local cfg = require("luarocks.core.cfg")
6
7local safer = require("safer")
8
9--- Convert the arch field of a query table to table format.
10-- @param input string, table or nil
11local function arch_to_table(input)
12 if type(input) == "table" then
13 return input
14 elseif type(input) == "string" then
15 local arch = {}
16 for a in input:gmatch("[%w_-]+") do
17 arch[a] = true
18 end
19 return arch
20 else
21 local arch = {}
22 arch["src"] = true
23 arch["all"] = true
24 arch["rockspec"] = true
25 arch["installed"] = true
26 arch[cfg.arch] = true
27 return arch
28 end
29end
30
31-- Split name and namespace of a package name.
32-- @param name a name that may be in "namespace/name" format
33-- @return string, string? - name and optionally a namespace
34local function split_namespace(name)
35 local p1, p2 = name:match("^([^/]+)/([^/]+)$")
36 if p1 then
37 return p2, p1
38 end
39 return name
40end
41
42--- Prepare a query in dependency table format.
43-- @param name string: The query name.
44-- @param version string or nil:
45-- @param substring boolean: match substrings of the name
46-- (default is false, match full name)
47-- @param arch string: a string with pipe-separated accepted arch values
48-- @param operator string: operator for version matching (default is "==")
49-- @return table: A query in table format
50function queries.new(name, version, substring, arch, operator)
51 assert(type(name) == "string")
52 assert(type(version) == "string" or not version)
53 assert(type(substring) == "boolean" or not substring)
54 assert(type(arch) == "string" or not arch)
55 assert(type(operator) == "string" or not operator)
56
57 operator = operator or "=="
58
59 local namespace
60 name, namespace = split_namespace(name)
61
62 local query = {
63 name = name,
64 namespace = namespace,
65 constraints = {},
66 substring = substring,
67 arch = arch_to_table(arch),
68 }
69 if version then
70 table.insert(query.constraints, { op = operator, version = vers.parse_version(version)})
71 end
72 return safer.readonly(query)
73end
74
75-- Query for all packages
76-- @param arch string (optional)
77function queries.all(arch)
78 assert(type(arch) == "string" or not arch)
79
80 return queries.new("", nil, true, arch)
81end
82
83function queries.from_constraints(name, constraints)
84 local namespace
85 name, namespace = split_namespace(name)
86 local query = {
87 name = name,
88 namespace = namespace,
89 constraints = constraints,
90 substring = false,
91 arch = arch_to_table(nil),
92 }
93 return safer.readonly(query)
94end
95
96return queries
diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua
index 6cc8334f..a469d149 100644
--- a/src/luarocks/remove.lua
+++ b/src/luarocks/remove.lua
@@ -7,6 +7,7 @@ local repos = require("luarocks.repos")
7local path = require("luarocks.path") 7local path = require("luarocks.path")
8local util = require("luarocks.util") 8local util = require("luarocks.util")
9local cfg = require("luarocks.core.cfg") 9local cfg = require("luarocks.core.cfg")
10local queries = require("luarocks.queries")
10 11
11--- Obtain a list of packages that depend on the given set of packages 12--- Obtain a list of packages that depend on the given set of packages
12-- (where all packages of the set are versions of one program). 13-- (where all packages of the set are versions of one program).
@@ -22,8 +23,7 @@ local function check_dependents(name, versions, deps_mode)
22 blacklist[name][version] = true 23 blacklist[name][version] = true
23 end 24 end
24 local local_rocks = {} 25 local local_rocks = {}
25 local query_all = search.make_query("") 26 local query_all = queries.all()
26 query_all.exact_name = false
27 search.manifest_search(local_rocks, cfg.rocks_dir, query_all) 27 search.manifest_search(local_rocks, cfg.rocks_dir, query_all)
28 local_rocks[name] = nil 28 local_rocks[name] = nil
29 for rock_name, rock_versions in pairs(local_rocks) do 29 for rock_name, rock_versions in pairs(local_rocks) do
@@ -105,7 +105,8 @@ end
105 105
106function remove.remove_other_versions(name, version, force, fast) 106function remove.remove_other_versions(name, version, force, fast)
107 local results = {} 107 local results = {}
108 search.manifest_search(results, cfg.rocks_dir, { name = name, exact_name = true, constraints = {{ op = "~=", version = version}} }) 108 local query = queries.new(name, version, false, nil, "~=")
109 search.manifest_search(results, cfg.rocks_dir, query)
109 if results[name] then 110 if results[name] then
110 return remove.remove_search_results(results, name, cfg.deps_mode, force, fast) 111 return remove.remove_search_results(results, name, cfg.deps_mode, force, fast)
111 end 112 end
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua
index 35010c2b..4e0cb847 100644
--- a/src/luarocks/search.lua
+++ b/src/luarocks/search.lua
@@ -6,29 +6,7 @@ local manif = require("luarocks.manif")
6local vers = require("luarocks.vers") 6local vers = require("luarocks.vers")
7local cfg = require("luarocks.core.cfg") 7local cfg = require("luarocks.core.cfg")
8local util = require("luarocks.util") 8local util = require("luarocks.util")
9 9local queries = require("luarocks.queries")
10--- Convert the arch field of a query table to table format.
11-- @param query table: A query table.
12local function query_arch_as_table(query)
13 local format = type(query.arch)
14 if format == "table" then
15 return
16 elseif format == "nil" then
17 local accept = {}
18 accept["src"] = true
19 accept["all"] = true
20 accept["rockspec"] = true
21 accept["installed"] = true
22 accept[cfg.arch] = true
23 query.arch = accept
24 elseif format == "string" then
25 local accept = {}
26 for a in query.arch:gmatch("[%w_-]+") do
27 accept[a] = true
28 end
29 query.arch = accept
30 end
31end
32 10
33--- Store a search result (a rock or rockspec) in the results table. 11--- Store a search result (a rock or rockspec) in the results table.
34-- @param results table: The results table, where keys are package names and 12-- @param results table: The results table, where keys are package names and
@@ -56,7 +34,7 @@ function search.store_result(results, name, version, arch, repo)
56end 34end
57 35
58--- Test the name field of a query. 36--- Test the name field of a query.
59-- If query has a boolean field exact_name set to false, 37-- If query has a boolean field substring set to true,
60-- then substring match is performed; otherwise, exact string 38-- then substring match is performed; otherwise, exact string
61-- comparison is done. 39-- comparison is done.
62-- @param query table: A query in dependency table format. 40-- @param query table: A query in dependency table format.
@@ -65,7 +43,7 @@ end
65local function match_name(query, name) 43local function match_name(query, name)
66 assert(type(query) == "table") 44 assert(type(query) == "table")
67 assert(type(name) == "string") 45 assert(type(name) == "string")
68 if query.exact_name == false then 46 if query.substring then
69 return name:find(query.name, 0, true) and true or false 47 return name:find(query.name, 0, true) and true or false
70 else 48 else
71 return name == query.name 49 return name == query.name
@@ -84,7 +62,7 @@ end
84-- @param version string: The version of the package being tested. 62-- @param version string: The version of the package being tested.
85-- @param arch string: The arch of the package being tested. 63-- @param arch string: The arch of the package being tested.
86-- @param query table: A table describing the query in dependency 64-- @param query table: A table describing the query in dependency
87-- format (for example, {name = "filesystem", exact_name = false, 65-- format (for example, {name = "filesystem", substring = true,
88-- constraints = {op = "~>", version = {1,0}}}, arch = "rockspec"). 66-- constraints = {op = "~>", version = {1,0}}}, arch = "rockspec").
89-- If the arch field is omitted, the local architecture (cfg.arch) 67-- If the arch field is omitted, the local architecture (cfg.arch)
90-- is used. The special value "any" is also recognized, returning all 68-- is used. The special value "any" is also recognized, returning all
@@ -102,7 +80,7 @@ end
102--- Perform search on a local repository. 80--- Perform search on a local repository.
103-- @param repo string: The pathname of the local repository. 81-- @param repo string: The pathname of the local repository.
104-- @param query table: A table describing the query in dependency 82-- @param query table: A table describing the query in dependency
105-- format (for example, {name = "filesystem", exact_name = false, 83-- format (for example, {name = "filesystem", substring = true,
106-- constraints = {op = "~>", version = {1,0}}}, arch = "rockspec"). 84-- constraints = {op = "~>", version = {1,0}}}, arch = "rockspec").
107-- If the arch field is omitted, the local architecture (cfg.arch) 85-- If the arch field is omitted, the local architecture (cfg.arch)
108-- is used. The special value "any" is also recognized, returning all 86-- is used. The special value "any" is also recognized, returning all
@@ -123,7 +101,6 @@ function search.disk_search(repo, query, results)
123 if not results then 101 if not results then
124 results = {} 102 results = {}
125 end 103 end
126 query_arch_as_table(query)
127 104
128 for name in fs.dir(repo) do 105 for name in fs.dir(repo) do
129 local pathname = dir.path(repo, name) 106 local pathname = dir.path(repo, name)
@@ -149,7 +126,7 @@ end
149-- @param repo string: The URL of a rocks server or 126-- @param repo string: The URL of a rocks server or
150-- the pathname of a rocks tree (as returned by path.rocks_dir()). 127-- the pathname of a rocks tree (as returned by path.rocks_dir()).
151-- @param query table: A table describing the query in dependency 128-- @param query table: A table describing the query in dependency
152-- format (for example, {name = "filesystem", exact_name = false, 129-- format (for example, {name = "filesystem", substring = true,
153-- constraints = {op = "~>", version = {1,0}}}, arch = "rockspec"). 130-- constraints = {op = "~>", version = {1,0}}}, arch = "rockspec").
154-- If the arch field is omitted, the local architecture (cfg.arch) 131-- If the arch field is omitted, the local architecture (cfg.arch)
155-- is used. The special value "any" is also recognized, returning all 132-- is used. The special value "any" is also recognized, returning all
@@ -160,8 +137,11 @@ function search.manifest_search(results, repo, query, lua_version)
160 assert(type(results) == "table") 137 assert(type(results) == "table")
161 assert(type(repo) == "string") 138 assert(type(repo) == "string")
162 assert(type(query) == "table") 139 assert(type(query) == "table")
163 140
164 query_arch_as_table(query) 141 if query.namespace then
142 repo = repo .. "/manifests/" .. query.namespace
143 end
144
165 local manifest, err, errcode = manif.load_manifest(repo, lua_version) 145 local manifest, err, errcode = manif.load_manifest(repo, lua_version)
166 if not manifest then 146 if not manifest then
167 return nil, err, errcode 147 return nil, err, errcode
@@ -216,24 +196,6 @@ function search.search_repos(query, lua_version)
216 return results 196 return results
217end 197end
218 198
219--- Prepare a query in dependency table format.
220-- @param name string: The query name.
221-- @param version string or nil:
222-- @return table: A query in table format
223function search.make_query(name, version)
224 assert(type(name) == "string")
225 assert(type(version) == "string" or not version)
226
227 local query = {
228 name = name,
229 constraints = {}
230 }
231 if version then
232 table.insert(query.constraints, { op = "==", version = vers.parse_version(version)})
233 end
234 return query
235end
236
237--- Get the URL for the latest in a set of versions. 199--- Get the URL for the latest in a set of versions.
238-- @param name string: The package name to be used in the URL. 200-- @param name string: The package name to be used in the URL.
239-- @param versions table: An array of version informations, as stored 201-- @param versions table: An array of version informations, as stored
@@ -369,8 +331,7 @@ function search.act_on_src_or_rockspec(action, name, version, ...)
369 assert(type(name) == "string") 331 assert(type(name) == "string")
370 assert(type(version) == "string" or not version) 332 assert(type(version) == "string" or not version)
371 333
372 local query = search.make_query(name, version) 334 local query = queries.new(name, version, nil, "src|rockspec")
373 query.arch = "src|rockspec"
374 local url, err = search.find_suitable_rock(query) 335 local url, err = search.find_suitable_rock(query)
375 if not url then 336 if not url then
376 return nil, "Could not find a result named "..name..(version and " "..version or "")..": "..err 337 return nil, "Could not find a result named "..name..(version and " "..version or "")..": "..err
@@ -380,8 +341,7 @@ end
380 341
381function search.pick_installed_rock(name, version, given_tree) 342function search.pick_installed_rock(name, version, given_tree)
382 local results = {} 343 local results = {}
383 local query = search.make_query(name, version) 344 local query = queries.new(name, version, true)
384 query.exact_name = true
385 local tree_map = {} 345 local tree_map = {}
386 local trees = cfg.rocks_trees 346 local trees = cfg.rocks_trees
387 if given_tree then 347 if given_tree then