aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsylvanaar <sylvanaar@mindspring.com>2011-08-20 13:43:45 -0400
committersylvanaar <sylvanaar@mindspring.com>2011-08-20 15:06:19 -0400
commit3f6df3b29d5e7b4e4bf7d8b9dbe51bd5e2febd7f (patch)
tree3eb18dfa1d8ba9f5a954a75db389867039eb894a /src
parent4724492df402089b0529c3ef7cb4fd240cbb5ed0 (diff)
downloadluarocks-3f6df3b29d5e7b4e4bf7d8b9dbe51bd5e2febd7f.tar.gz
luarocks-3f6df3b29d5e7b4e4bf7d8b9dbe51bd5e2febd7f.tar.bz2
luarocks-3f6df3b29d5e7b4e4bf7d8b9dbe51bd5e2febd7f.zip
added an hg scc provider
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/fetch.lua8
-rw-r--r--src/luarocks/fetch/hg.lua52
-rw-r--r--src/luarocks/type_check.lua1
3 files changed, 58 insertions, 3 deletions
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)
156 end 156 end
157 157
158 local protocol, pathname = dir.split_url(rockspec.source.url) 158 local protocol, pathname = dir.split_url(rockspec.source.url)
159 if protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" then 159 local vccs = rockspec.source.vccs
160 if vccs ~= nil and ( protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" ) then
160 rockspec.source.file = rockspec.source.file or dir.base_name(rockspec.source.url) 161 rockspec.source.file = rockspec.source.file or dir.base_name(rockspec.source.url)
161 end 162 end
162 rockspec.source.protocol, rockspec.source.pathname = protocol, pathname 163 rockspec.source.protocol, rockspec.source.pathname = protocol, pathname
@@ -293,11 +294,12 @@ function fetch_sources(rockspec, extract, dest_dir)
293 assert(type(dest_dir) == "string" or not dest_dir) 294 assert(type(dest_dir) == "string" or not dest_dir)
294 295
295 local protocol = rockspec.source.protocol 296 local protocol = rockspec.source.protocol
297 local vccs = rockspec.source.protocol
296 local ok, proto 298 local ok, proto
297 if protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" then 299 if vccs == nil or ( protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" ) then
298 proto = require("luarocks.fetch") 300 proto = require("luarocks.fetch")
299 else 301 else
300 ok, proto = pcall(require, "luarocks.fetch."..protocol) 302 ok, proto = pcall(require, "luarocks.fetch."..vccs or protocol)
301 if not ok then 303 if not ok then
302 return nil, "Unknown protocol "..protocol 304 return nil, "Unknown protocol "..protocol
303 end 305 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 @@
1
2--- Fetch back-end for retrieving sources from HG.
3module("luarocks.fetch.hg", package.seeall)
4
5local fs = require("luarocks.fs")
6local dir = require("luarocks.dir")
7local util = require("luarocks.util")
8
9--- Download sources for building a rock, using hg.
10-- @param rockspec table: The rockspec table
11-- @param extract boolean: Unused in this module (required for API purposes.)
12-- @param dest_dir string or nil: If set, will extract to the given directory.
13-- @return (string, string) or (nil, string): The absolute pathname of
14-- the fetched source tarball and the temporary directory created to
15-- store it; or nil and an error message.
16function get_sources(rockspec, extract, dest_dir)
17 assert(type(rockspec) == "table")
18 assert(type(dest_dir) == "string" or not dest_dir)
19
20 local hg_cmd = rockspec.variables.HG
21 local name_version = rockspec.name .. "-" .. rockspec.version
22 local module = dir.base_name(rockspec.source.url)
23 -- Strip off .hg from base name if present
24 module = module:gsub("%.hg$", "")
25 local command = {hg_cmd, "clone", "--startrev HEAD", rockspec.source.url, module}
26 local tag_or_branch = rockspec.source.tag or rockspec.source.branch
27 if tag_or_branch then
28 command = {hg_cmd, "clone", "--startrev HEAD", "--rev", rockspec.source.url, module}
29 end
30 local store_dir
31 if not dest_dir then
32 store_dir = fs.make_temp_dir(name_version)
33 if not store_dir then
34 return nil, "Failed creating temporary directory."
35 end
36 util.schedule_function(fs.delete, store_dir)
37 else
38 store_dir = dest_dir
39 end
40 fs.change_dir(store_dir)
41 if not fs.execute(unpack(command)) then
42 return nil, "Failed cloning hg repository."
43 end
44 fs.change_dir(module)
45
46 fs.delete(dir.path(store_dir, module, ".hg"))
47 fs.delete(dir.path(store_dir, module, ".hgignore"))
48 fs.pop_dir()
49 fs.pop_dir()
50 return module, store_dir
51end
52
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 = {
38 md5 = "string", 38 md5 = "string",
39 file = "string", 39 file = "string",
40 dir = "string", 40 dir = "string",
41 vccs = "string",
41 tag = "string", 42 tag = "string",
42 branch = "string", 43 branch = "string",
43 module = "string", 44 module = "string",