From 447e8aa089fc189fef8434facfea2b0d84047749 Mon Sep 17 00:00:00 2001
From: Hisham Muhammad <hisham@gobolinux.org>
Date: Tue, 19 Jun 2018 00:08:33 -0300
Subject: core.util: move type_check.merge_under to core.util.deep_merge_under

---
 src/luarocks/core/util.lua  | 22 ++++++++++++++++++++--
 src/luarocks/type_check.lua | 15 +--------------
 src/luarocks/util.lua       | 10 ++++++----
 3 files changed, 27 insertions(+), 20 deletions(-)

(limited to 'src')

diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua
index 3582cb54..daec9d05 100644
--- a/src/luarocks/core/util.lua
+++ b/src/luarocks/core/util.lua
@@ -54,7 +54,7 @@ function util.show_table(t, tname, top_indent)
 
    local function is_empty_table(tbl) return next(tbl) == nil end
    
-   local function basic_serialize (o)
+   local function basic_serialize(o)
       local so = tostring(o)
       if type(o) == "function" then
          local info = debug.getinfo(o, "S")
@@ -72,7 +72,7 @@ function util.show_table(t, tname, top_indent)
       end
    end
    
-   local function add_to_cart (value, name, indent, saved, field)
+   local function add_to_cart(value, name, indent, saved, field)
       indent = indent or ""
       saved = saved or {}
       field = field or name
@@ -133,6 +133,24 @@ function util.deep_merge(dst, src)
    end
 end
 
+--- Merges contents of src below those of dst's contents.
+-- @param dst Destination table, which will receive src's contents.
+-- @param src Table which provides new contents to dst.
+function util.deep_merge_under(dst, src)
+   for k, v in pairs(src) do
+      if type(v) == "table" then
+         if not dst[k] then
+            dst[k] = {}
+         end
+         if type(dst[k]) == "table" then
+            util.deep_merge_under(dst[k], v)
+         end
+      elseif dst[k] == nil then
+         dst[k] = v
+      end
+   end
+end
+
 --- Clean up a path-style string ($PATH, $LUA_PATH/package.path, etc.),
 -- removing repeated entries and making sure only the relevant
 -- Lua version is used.
diff --git a/src/luarocks/type_check.lua b/src/luarocks/type_check.lua
index 827c64b6..b204f5ee 100644
--- a/src/luarocks/type_check.lua
+++ b/src/luarocks/type_check.lua
@@ -4,7 +4,6 @@ local type_check = {}
 local cfg = require("luarocks.core.cfg")
 local vers = require("luarocks.core.vers")
 local util = require("luarocks.util")
-local require = nil
 --------------------------------------------------------------------------------
 
 type_check.MAGIC_PLATFORMS = {}
@@ -34,18 +33,6 @@ do
       end
    end
    
-   local function merge_under(dst, src)
-      for k, v in pairs(src) do
-         if dst[k] == nil then
-            if type(dst[k]) == "table" then
-               util.deep_merge(dst[k], v)
-            else
-               dst[k] = v
-            end
-         end
-      end
-   end
-   
    -- Build a table of schemas.
    -- @param versions a table where each key is a version number as a string,
    -- and the value is a schema specification. Schema versions are considered
@@ -75,7 +62,7 @@ do
       -- so that error messages can inform users when they try
       -- to use new features without bumping rockspec_format in their rockspecs.
       for i = #version_list, 2, -1 do
-         merge_under(schemas[version_list[i - 1]], schemas[version_list[i]])
+         util.deep_merge_under(schemas[version_list[i - 1]], schemas[version_list[i]])
       end
 
       return schemas
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua
index f5506f53..ee4a803a 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -8,14 +8,16 @@ local util = {}
 
 local core = require("luarocks.core.util")
 
-util.popen_read = core.popen_read
 util.cleanup_path = core.cleanup_path
 util.split_string = core.split_string
-util.keys = core.keys
-util.printerr = core.printerr
 util.sortedpairs = core.sortedpairs
-util.warning = core.warning
 util.deep_merge = core.deep_merge
+util.deep_merge_under = core.deep_merge_under
+util.popen_read = core.popen_read
+util.show_table = core.show_table
+util.printerr = core.printerr
+util.warning = core.warning
+util.keys = core.keys
 
 local unpack = unpack or table.unpack
 
-- 
cgit v1.2.3-55-g6feb