From 3f6df3b29d5e7b4e4bf7d8b9dbe51bd5e2febd7f Mon Sep 17 00:00:00 2001 From: sylvanaar Date: Sat, 20 Aug 2011 13:43:45 -0400 Subject: added an hg scc provider --- src/luarocks/fetch.lua | 8 ++++--- src/luarocks/fetch/hg.lua | 52 +++++++++++++++++++++++++++++++++++++++++++++ src/luarocks/type_check.lua | 1 + 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 src/luarocks/fetch/hg.lua (limited to 'src') diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 2ea2c906..98e10609 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -156,7 +156,8 @@ function load_local_rockspec(filename) end local protocol, pathname = dir.split_url(rockspec.source.url) - if protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" then + local vccs = rockspec.source.vccs + if vccs ~= nil and ( protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" ) then rockspec.source.file = rockspec.source.file or dir.base_name(rockspec.source.url) end rockspec.source.protocol, rockspec.source.pathname = protocol, pathname @@ -293,11 +294,12 @@ function fetch_sources(rockspec, extract, dest_dir) assert(type(dest_dir) == "string" or not dest_dir) local protocol = rockspec.source.protocol + local vccs = rockspec.source.protocol local ok, proto - if protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" then + if vccs == nil or ( protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" ) then proto = require("luarocks.fetch") else - ok, proto = pcall(require, "luarocks.fetch."..protocol) + ok, proto = pcall(require, "luarocks.fetch."..vccs or protocol) if not ok then return nil, "Unknown protocol "..protocol end diff --git a/src/luarocks/fetch/hg.lua b/src/luarocks/fetch/hg.lua new file mode 100644 index 00000000..885060a2 --- /dev/null +++ b/src/luarocks/fetch/hg.lua @@ -0,0 +1,52 @@ + +--- Fetch back-end for retrieving sources from HG. +module("luarocks.fetch.hg", package.seeall) + +local fs = require("luarocks.fs") +local dir = require("luarocks.dir") +local util = require("luarocks.util") + +--- Download sources for building a rock, using hg. +-- @param rockspec table: The rockspec table +-- @param extract boolean: Unused in this module (required for API purposes.) +-- @param dest_dir string or nil: If set, will extract to the given directory. +-- @return (string, string) or (nil, string): The absolute pathname of +-- the fetched source tarball and the temporary directory created to +-- store it; or nil and an error message. +function get_sources(rockspec, extract, dest_dir) + assert(type(rockspec) == "table") + assert(type(dest_dir) == "string" or not dest_dir) + + local hg_cmd = rockspec.variables.HG + local name_version = rockspec.name .. "-" .. rockspec.version + local module = dir.base_name(rockspec.source.url) + -- Strip off .hg from base name if present + module = module:gsub("%.hg$", "") + local command = {hg_cmd, "clone", "--startrev HEAD", rockspec.source.url, module} + local tag_or_branch = rockspec.source.tag or rockspec.source.branch + if tag_or_branch then + command = {hg_cmd, "clone", "--startrev HEAD", "--rev", rockspec.source.url, module} + end + local store_dir + if not dest_dir then + store_dir = fs.make_temp_dir(name_version) + if not store_dir then + return nil, "Failed creating temporary directory." + end + util.schedule_function(fs.delete, store_dir) + else + store_dir = dest_dir + end + fs.change_dir(store_dir) + if not fs.execute(unpack(command)) then + return nil, "Failed cloning hg repository." + end + fs.change_dir(module) + + fs.delete(dir.path(store_dir, module, ".hg")) + fs.delete(dir.path(store_dir, module, ".hgignore")) + fs.pop_dir() + fs.pop_dir() + return module, store_dir +end + diff --git a/src/luarocks/type_check.lua b/src/luarocks/type_check.lua index 0e4a73af..87617bcd 100644 --- a/src/luarocks/type_check.lua +++ b/src/luarocks/type_check.lua @@ -38,6 +38,7 @@ rockspec_types = { md5 = "string", file = "string", dir = "string", + vccs = "string", tag = "string", branch = "string", module = "string", -- cgit v1.2.3-55-g6feb From c1809b0c62bb118157880de56b01174f18c1c18e Mon Sep 17 00:00:00 2001 From: sylvanaar Date: Sat, 20 Aug 2011 20:09:01 -0400 Subject: some additional fixes --- src/luarocks/fetch.lua | 7 ++++--- src/luarocks/fetch/hg.lua | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 98e10609..9b946684 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -294,14 +294,15 @@ function fetch_sources(rockspec, extract, dest_dir) assert(type(dest_dir) == "string" or not dest_dir) local protocol = rockspec.source.protocol - local vccs = rockspec.source.protocol + local vccs = rockspec.source.vccs + local ok, proto - if vccs == nil or ( protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" ) then + if vccs == nil and ( protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" ) then proto = require("luarocks.fetch") else ok, proto = pcall(require, "luarocks.fetch."..vccs or protocol) if not ok then - return nil, "Unknown protocol "..protocol + return nil, "Unknown protocol "..proto end end diff --git a/src/luarocks/fetch/hg.lua b/src/luarocks/fetch/hg.lua index 885060a2..5c1575ba 100644 --- a/src/luarocks/fetch/hg.lua +++ b/src/luarocks/fetch/hg.lua @@ -20,8 +20,7 @@ function get_sources(rockspec, extract, dest_dir) local hg_cmd = rockspec.variables.HG local name_version = rockspec.name .. "-" .. rockspec.version local module = dir.base_name(rockspec.source.url) - -- Strip off .hg from base name if present - module = module:gsub("%.hg$", "") + local command = {hg_cmd, "clone", "--startrev HEAD", rockspec.source.url, module} local tag_or_branch = rockspec.source.tag or rockspec.source.branch if tag_or_branch then -- cgit v1.2.3-55-g6feb From 6a4d1f42228a47b74f5542e09d132515d6ef19ba Mon Sep 17 00:00:00 2001 From: sylvanaar Date: Sat, 3 Sep 2011 02:01:33 -0400 Subject: change the hg provider to use the hg:// protocol for backwards compatibility. add HG to the default vars --- src/luarocks/cfg.lua | 1 + src/luarocks/fetch.lua | 11 ++++------- src/luarocks/fetch/hg.lua | 9 ++++++--- src/luarocks/type_check.lua | 1 - 4 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 1abe39cb..43f10e6b 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -154,6 +154,7 @@ local defaults = { GIT = "git", SSCM = "sscm", SVN = "svn", + HG = "hg", RSYNC = "rsync", WGET = "wget", diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 9b946684..2ea2c906 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -156,8 +156,7 @@ function load_local_rockspec(filename) end local protocol, pathname = dir.split_url(rockspec.source.url) - local vccs = rockspec.source.vccs - if vccs ~= nil and ( protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" ) then + if protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" then rockspec.source.file = rockspec.source.file or dir.base_name(rockspec.source.url) end rockspec.source.protocol, rockspec.source.pathname = protocol, pathname @@ -294,15 +293,13 @@ function fetch_sources(rockspec, extract, dest_dir) assert(type(dest_dir) == "string" or not dest_dir) local protocol = rockspec.source.protocol - local vccs = rockspec.source.vccs - local ok, proto - if vccs == nil and ( protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" ) then + if protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" then proto = require("luarocks.fetch") else - ok, proto = pcall(require, "luarocks.fetch."..vccs or protocol) + ok, proto = pcall(require, "luarocks.fetch."..protocol) if not ok then - return nil, "Unknown protocol "..proto + return nil, "Unknown protocol "..protocol end end diff --git a/src/luarocks/fetch/hg.lua b/src/luarocks/fetch/hg.lua index 5c1575ba..a08520a5 100644 --- a/src/luarocks/fetch/hg.lua +++ b/src/luarocks/fetch/hg.lua @@ -19,12 +19,15 @@ function get_sources(rockspec, extract, dest_dir) local hg_cmd = rockspec.variables.HG local name_version = rockspec.name .. "-" .. rockspec.version - local module = dir.base_name(rockspec.source.url) + -- Strip off special hg:// protocol type + local url = rockspec.source.url:gsub("^hg://", "") - local command = {hg_cmd, "clone", "--startrev HEAD", rockspec.source.url, module} + local module = dir.base_name(url) + + local command = {hg_cmd, "clone", url, module} local tag_or_branch = rockspec.source.tag or rockspec.source.branch if tag_or_branch then - command = {hg_cmd, "clone", "--startrev HEAD", "--rev", rockspec.source.url, module} + command = {hg_cmd, "clone", "--rev", url, module} end local store_dir if not dest_dir then diff --git a/src/luarocks/type_check.lua b/src/luarocks/type_check.lua index 87617bcd..0e4a73af 100644 --- a/src/luarocks/type_check.lua +++ b/src/luarocks/type_check.lua @@ -38,7 +38,6 @@ rockspec_types = { md5 = "string", file = "string", dir = "string", - vccs = "string", tag = "string", branch = "string", module = "string", -- cgit v1.2.3-55-g6feb