aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-22 17:49:05 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-10-21 13:30:51 -0300
commitf86d6ad4897182543803d36e3b914a115f9925a4 (patch)
treea4ed0f4da68f4e4670d0edefa0a9531f72d19717
parent0dbdd0ce7b564d4c010e44058b6f1ff3671ee36a (diff)
downloadluarocks-f86d6ad4897182543803d36e3b914a115f9925a4.tar.gz
luarocks-f86d6ad4897182543803d36e3b914a115f9925a4.tar.bz2
luarocks-f86d6ad4897182543803d36e3b914a115f9925a4.zip
Teal: convert luarocks.fetch.git
-rw-r--r--src/luarocks/fetch/git.tl (renamed from src/luarocks/fetch/git.lua)37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.tl
index 29892e92..6d281a33 100644
--- a/src/luarocks/fetch/git.lua
+++ b/src/luarocks/fetch/git.tl
@@ -1,20 +1,23 @@
1 1
2--- Fetch back-end for retrieving sources from GIT. 2--- Fetch back-end for retrieving sources from GIT.
3local git = {} 3local record git
4 4
5local unpack = unpack or table.unpack 5end
6 6
7local fs = require("luarocks.fs") 7local fs = require("luarocks.fs")
8local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
9local vers = require("luarocks.core.vers") 9local vers = require("luarocks.core.vers")
10local util = require("luarocks.util") 10local util = require("luarocks.util")
11 11
12local cached_git_version 12local type Rockspec = require("luarocks.core.types.rockspec").Rockspec
13local type Version = require("luarocks.core.types.version").Version
14
15local cached_git_version: Version
13 16
14--- Get git version. 17--- Get git version.
15-- @param git_cmd string: name of git command. 18-- @param git_cmd string: name of git command.
16-- @return table: git version as returned by luarocks.core.vers.parse_version. 19-- @return table: git version as returned by luarocks.core.vers.parse_version.
17local function git_version(git_cmd) 20local function git_version(git_cmd: string): Version
18 if not cached_git_version then 21 if not cached_git_version then
19 local version_line = io.popen(fs.Q(git_cmd)..' --version'):read() 22 local version_line = io.popen(fs.Q(git_cmd)..' --version'):read()
20 local version_string = version_line:match('%d-%.%d+%.?%d*') 23 local version_string = version_line:match('%d-%.%d+%.?%d*')
@@ -28,7 +31,7 @@ end
28-- @param git_cmd string: name of git command. 31-- @param git_cmd string: name of git command.
29-- @param version string: required version. 32-- @param version string: required version.
30-- @return boolean: true if git matches version or is newer, false otherwise. 33-- @return boolean: true if git matches version or is newer, false otherwise.
31local function git_is_at_least(git_cmd, version) 34local function git_is_at_least(git_cmd: string, version: string): boolean
32 return git_version(git_cmd) >= vers.parse_version(version) 35 return git_version(git_cmd) >= vers.parse_version(version)
33end 36end
34 37
@@ -38,7 +41,7 @@ end
38-- given tag. 41-- given tag.
39-- @param git_cmd string: name of git command. 42-- @param git_cmd string: name of git command.
40-- @return boolean: Whether Git can clone by tag. 43-- @return boolean: Whether Git can clone by tag.
41local function git_can_clone_by_tag(git_cmd) 44local function git_can_clone_by_tag(git_cmd?: string): boolean
42 return git_is_at_least(git_cmd, "1.7.10") 45 return git_is_at_least(git_cmd, "1.7.10")
43end 46end
44 47
@@ -46,18 +49,18 @@ end
46-- submodules with large history. 49-- submodules with large history.
47-- @param git_cmd string: name of git command. 50-- @param git_cmd string: name of git command.
48-- @return boolean: Whether Git can fetch submodules shallowly. 51-- @return boolean: Whether Git can fetch submodules shallowly.
49local function git_supports_shallow_submodules(git_cmd) 52local function git_supports_shallow_submodules(git_cmd: string): boolean
50 return git_is_at_least(git_cmd, "1.8.4") 53 return git_is_at_least(git_cmd, "1.8.4")
51end 54end
52 55
53--- Git >= 2.10 can fetch submodules shallowly according to .gitmodules configuration, allowing more granularity. 56--- Git >= 2.10 can fetch submodules shallowly according to .gitmodules configuration, allowing more granularity.
54-- @param git_cmd string: name of git command. 57-- @param git_cmd string: name of git command.
55-- @return boolean: Whether Git can fetch submodules shallowly according to .gitmodules. 58-- @return boolean: Whether Git can fetch submodules shallowly according to .gitmodules.
56local function git_supports_shallow_recommendations(git_cmd) 59local function git_supports_shallow_recommendations(git_cmd: string): boolean
57 return git_is_at_least(git_cmd, "2.10.0") 60 return git_is_at_least(git_cmd, "2.10.0")
58end 61end
59 62
60local function git_identifier(git_cmd, ver) 63local function git_identifier(git_cmd: string, ver: string): string
61 if not (ver:match("^dev%-%d+$") or ver:match("^scm%-%d+$")) then 64 if not (ver:match("^dev%-%d+$") or ver:match("^scm%-%d+$")) then
62 return nil 65 return nil
63 end 66 end
@@ -70,7 +73,7 @@ local function git_identifier(git_cmd, ver)
70 if not date_hash then 73 if not date_hash then
71 return nil 74 return nil
72 end 75 end
73 local date, time, tz, hash = date_hash:match("([^%s]+) ([^%s]+) ([^%s]+)_([^%s]+)") 76 local date, time, _tz, hash = date_hash:match("([^%s]+) ([^%s]+) ([^%s]+)_([^%s]+)")
74 date = date:gsub("%-", "") 77 date = date:gsub("%-", "")
75 time = time:gsub(":", "") 78 time = time:gsub(":", "")
76 return date .. "." .. time .. "." .. hash 79 return date .. "." .. time .. "." .. hash
@@ -83,9 +86,7 @@ end
83-- @return (string, string) or (nil, string): The absolute pathname of 86-- @return (string, string) or (nil, string): The absolute pathname of
84-- the fetched source tarball and the temporary directory created to 87-- the fetched source tarball and the temporary directory created to
85-- store it; or nil and an error message. 88-- store it; or nil and an error message.
86function git.get_sources(rockspec, extract, dest_dir, depth) 89function git.get_sources(rockspec: Rockspec, extract: boolean, dest_dir?: string, depth?: string): string, string
87 assert(rockspec:type() == "rockspec")
88 assert(type(dest_dir) == "string" or not dest_dir)
89 90
90 local git_cmd = rockspec.variables.GIT 91 local git_cmd = rockspec.variables.GIT
91 local name_version = rockspec.name .. "-" .. rockspec.version 92 local name_version = rockspec.name .. "-" .. rockspec.version
@@ -93,12 +94,12 @@ function git.get_sources(rockspec, extract, dest_dir, depth)
93 -- Strip off .git from base name if present 94 -- Strip off .git from base name if present
94 module = module:gsub("%.git$", "") 95 module = module:gsub("%.git$", "")
95 96
96 local ok, err_msg = fs.is_tool_available(git_cmd, "Git") 97 local ok_available, err_msg = fs.is_tool_available(git_cmd, "Git")
97 if not ok then 98 if not ok_available then
98 return nil, err_msg 99 return nil, err_msg
99 end 100 end
100 101
101 local store_dir 102 local store_dir: string
102 if not dest_dir then 103 if not dest_dir then
103 store_dir = fs.make_temp_dir(name_version) 104 store_dir = fs.make_temp_dir(name_version)
104 if not store_dir then 105 if not store_dir then
@@ -124,7 +125,7 @@ function git.get_sources(rockspec, extract, dest_dir, depth)
124 table.insert(command, 3, "--branch=" .. tag_or_branch) 125 table.insert(command, 3, "--branch=" .. tag_or_branch)
125 end 126 end
126 end 127 end
127 if not fs.execute(unpack(command)) then 128 if not fs.execute(table.unpack(command)) then
128 return nil, "Failed cloning git repository." 129 return nil, "Failed cloning git repository."
129 end 130 end
130 ok, err = fs.change_dir(module) 131 ok, err = fs.change_dir(module)
@@ -146,7 +147,7 @@ function git.get_sources(rockspec, extract, dest_dir, depth)
146 table.insert(command, 5, "--depth=1") 147 table.insert(command, 5, "--depth=1")
147 end 148 end
148 149
149 if not fs.execute(unpack(command)) then 150 if not fs.execute(table.unpack(command)) then
150 return nil, 'Failed to fetch submodules.' 151 return nil, 'Failed to fetch submodules.'
151 end 152 end
152 end 153 end