summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-08-31 00:40:56 +0800
committerruki <[email protected]>2023-08-31 00:40:56 +0800
commit39afcd4821aab51f2eaacdb163c87e9d55e2a4c7 (patch)
tree4ae03ffd055175f0c2b52c2bce2339510e1cf498
parent2db1266629941c424b9a758221e8293e09fb7f32 (diff)
improve to clone tag #4151
-rw-r--r--xmake/modules/devel/git/clone.lua15
-rw-r--r--xmake/modules/private/action/require/impl/actions/download.lua37
2 files changed, 44 insertions, 8 deletions
diff --git a/xmake/modules/devel/git/clone.lua b/xmake/modules/devel/git/clone.lua
index 58f43462d..469d36c2e 100644
--- a/xmake/modules/devel/git/clone.lua
+++ b/xmake/modules/devel/git/clone.lua
@@ -20,9 +20,24 @@
-- imports
import("core.base.option")
+import("core.base.semver")
import("lib.detect.find_tool")
import("net.proxy")
+-- can clone tag?
+-- @see https://github.com/xmake-io/xmake/issues/4151
+function can_clone_tag()
+ local can = _g.can_clone_tag
+ if can == nil then
+ local git = assert(find_tool("git", {version = true}), "git not found!")
+ if git.version and semver.compare(git.version, "1.7.10") >= 0 then
+ can = true
+ end
+ _g.can_clone_tag = can or false
+ end
+ return can or false
+end
+
-- clone url
--
-- @param url the git url
diff --git a/xmake/modules/private/action/require/impl/actions/download.lua b/xmake/modules/private/action/require/impl/actions/download.lua
index 06ebae308..f222fcd39 100644
--- a/xmake/modules/private/action/require/impl/actions/download.lua
+++ b/xmake/modules/private/action/require/impl/actions/download.lua
@@ -84,6 +84,8 @@ function _checkout(package, url, sourcedir, opt)
-- we need to enable longpaths on windows
local longpaths = package:policy("platform.longpaths")
+ print("rev", package:revision(opt.url_alias))
+ print("tag", package:tag())
-- download package from branches?
packagedir = path.join(sourcedir .. ".tmp", package:name())
local branch = package:branch()
@@ -101,16 +103,35 @@ function _checkout(package, url, sourcedir, opt)
-- download package from revision or tag?
else
- -- clone whole history and tags
- git.clone(url, {longpaths = longpaths, outputdir = packagedir})
+ -- get tag and revision?
+ local tag
+ local revision = package:revision(opt.url_alias)
+ if revision and (#revision ~= 40 or not revision:match("%w+")) then
+ tag = revision
+ end
+ if not tag then
+ tag = package:tag()
+ end
+ if not revision then
+ revision = tag or package:commit() or package:version_str()
+ end
- -- attempt to checkout the given version
- local revision = package:revision(opt.url_alias) or package:tag() or package:commit() or package:version_str()
- git.checkout(revision, {repodir = packagedir})
+ -- only shallow clone this tag
+ -- @see https://github.com/xmake-io/xmake/issues/4151
+ if tag and git.clone.can_clone_tag() then
+ git.clone(url, {depth = 1, recursive = true, shallow_submodules = true, longpaths = longpaths, branch = tag, outputdir = packagedir})
+ else
- -- update all submodules
- if os.isfile(path.join(packagedir, ".gitmodules")) and opt.url_submodules ~= false then
- git.submodule.update({init = true, recursive = true, longpaths = longpaths, repodir = packagedir})
+ -- clone whole history and tags
+ git.clone(url, {longpaths = longpaths, outputdir = packagedir})
+
+ -- attempt to checkout the given version
+ git.checkout(revision, {repodir = packagedir})
+
+ -- update all submodules
+ if os.isfile(path.join(packagedir, ".gitmodules")) and opt.url_submodules ~= false then
+ git.submodule.update({init = true, recursive = true, longpaths = longpaths, repodir = packagedir})
+ end
end
end