aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/luarocks/cfg.lua1
-rw-r--r--src/luarocks/fetch/hg.lua54
2 files changed, 55 insertions, 0 deletions
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index 77eb051e..2b48d576 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -154,6 +154,7 @@ local defaults = {
154 GIT = "git", 154 GIT = "git",
155 SSCM = "sscm", 155 SSCM = "sscm",
156 SVN = "svn", 156 SVN = "svn",
157 HG = "hg",
157 158
158 RSYNC = "rsync", 159 RSYNC = "rsync",
159 WGET = "wget", 160 WGET = "wget",
diff --git a/src/luarocks/fetch/hg.lua b/src/luarocks/fetch/hg.lua
new file mode 100644
index 00000000..a08520a5
--- /dev/null
+++ b/src/luarocks/fetch/hg.lua
@@ -0,0 +1,54 @@
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 -- Strip off special hg:// protocol type
23 local url = rockspec.source.url:gsub("^hg://", "")
24
25 local module = dir.base_name(url)
26
27 local command = {hg_cmd, "clone", url, module}
28 local tag_or_branch = rockspec.source.tag or rockspec.source.branch
29 if tag_or_branch then
30 command = {hg_cmd, "clone", "--rev", url, module}
31 end
32 local store_dir
33 if not dest_dir then
34 store_dir = fs.make_temp_dir(name_version)
35 if not store_dir then
36 return nil, "Failed creating temporary directory."
37 end
38 util.schedule_function(fs.delete, store_dir)
39 else
40 store_dir = dest_dir
41 end
42 fs.change_dir(store_dir)
43 if not fs.execute(unpack(command)) then
44 return nil, "Failed cloning hg repository."
45 end
46 fs.change_dir(module)
47
48 fs.delete(dir.path(store_dir, module, ".hg"))
49 fs.delete(dir.path(store_dir, module, ".hgignore"))
50 fs.pop_dir()
51 fs.pop_dir()
52 return module, store_dir
53end
54