aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Melnichenko <mpeterval@gmail.com>2016-10-28 17:24:01 +0300
committerPeter Melnichenko <mpeterval@gmail.com>2016-10-28 22:38:19 +0300
commit0574fb3c6d015b80c1f0330e2bf5a630c5ec306a (patch)
treeaba6b57415049d9187e84ffd449013c3826b2215 /src
parent650755f9b82b678ebb1f14242e5249c5f9e6c36f (diff)
downloadluarocks-0574fb3c6d015b80c1f0330e2bf5a630c5ec306a.tar.gz
luarocks-0574fb3c6d015b80c1f0330e2bf5a630c5ec306a.tar.bz2
luarocks-0574fb3c6d015b80c1f0330e2bf5a630c5ec306a.zip
Refactor store_results in luarocks.manif
Instead of passing a function and its arguments to a helper function for it to call it, make a copy of result, and return it, call the function on the outer level and pass the result to helper.
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/manif.lua44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua
index 2d983a85..15a27c48 100644
--- a/src/luarocks/manif.lua
+++ b/src/luarocks/manif.lua
@@ -161,31 +161,28 @@ function manif.load_manifest(repo_url, lua_version)
161 return manif_core.manifest_loader(pathname, repo_url, lua_version) 161 return manif_core.manifest_loader(pathname, repo_url, lua_version)
162end 162end
163 163
164--- Output a table listing items of a package. 164--- Update storage table to account for items provided by a package.
165-- @param itemsfn function: a function for obtaining items of a package. 165-- @param storage table: a table storing items in the following format:
166-- pkg and version will be passed to it; it should return a table with 166-- keys are item names and values are arrays of packages providing each item,
167-- items as keys. 167-- where a package is specified as string `name/version`.
168-- @param pkg string: package name 168-- @param items table: a table mapping item names to paths.
169-- @param version string: package version 169-- @param name string: package name.
170-- @param tbl table: the package matching table: keys should be item names 170-- @param version string: package version.
171-- and values arrays of strings with packages names in "name/version" format. 171local function store_package_items(storage, name, version, items)
172local function store_package_items(itemsfn, pkg, version, tbl) 172 assert(type(storage) == "table")
173 assert(type(itemsfn) == "function") 173 assert(type(items) == "table")
174 assert(type(pkg) == "string") 174 assert(type(name) == "string")
175 assert(type(version) == "string") 175 assert(type(version) == "string")
176 assert(type(tbl) == "table")
177 176
178 local pkg_version = pkg.."/"..version 177 local package_identifier = name.."/"..version
179 local result = {}
180 178
181 for item, path in pairs(itemsfn(pkg, version)) do 179 for item_name, path in pairs(items) do
182 result[item] = path 180 if not storage[item_name] then
183 if not tbl[item] then 181 storage[item_name] = {}
184 tbl[item] = {}
185 end 182 end
186 table.insert(tbl[item], pkg_version) 183
184 table.insert(storage[item_name], package_identifier)
187 end 185 end
188 return result
189end 186end
190 187
191--- Sort function for ordering rock identifiers in a manifest's 188--- Sort function for ordering rock identifiers in a manifest's
@@ -340,8 +337,11 @@ local function store_results(results, manifest, dep_handler)
340 if not rock_manifest then 337 if not rock_manifest then
341 return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks 2 tree?" 338 return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks 2 tree?"
342 end 339 end
343 entrytable.modules = store_package_items(repos.package_modules, name, version, manifest.modules) 340
344 entrytable.commands = store_package_items(repos.package_commands, name, version, manifest.commands) 341 entrytable.modules = repos.package_modules(name, version)
342 store_package_items(manifest.modules, name, version, entrytable.modules)
343 entrytable.commands = repos.package_commands(name, version)
344 store_package_items(manifest.commands, name, version, entrytable.commands)
345 end 345 end
346 table.insert(versiontable, entrytable) 346 table.insert(versiontable, entrytable)
347 end 347 end