Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support sparse-checkout for git #6072

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion xmake/core/package/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,19 @@ function _instance:url_version(url)
return self:extraconf("urls", url, "version")
end

-- get the excludes list of url for the archive extractor, @note need raw url
-- get the excludes paths of url
-- @note it supports the path pattern, but it only supports for archiver.
function _instance:url_excludes(url)
return self:extraconf("urls", url, "excludes")
end

-- get the includes paths of url
-- @note it does not support the path pattern, and it only supports for git url now.
-- @see https://github.com/xmake-io/xmake/issues/6071
function _instance:url_includes(url)
return self:extraconf("urls", url, "includes")
end

-- get the http headers of url, @note need raw url
function _instance:url_http_headers(url)
return self:extraconf("urls", url, "http_headers")
Expand Down
10 changes: 9 additions & 1 deletion xmake/modules/devel/git/checkout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

-- imports
import("core.base.option")
import("core.base.semver")
import("lib.detect.find_tool")

-- checkout to given branch, tag or commit
Expand All @@ -38,7 +39,7 @@ import("lib.detect.find_tool")
--
function main(commit, opt)
opt = opt or {}
local git = assert(find_tool("git"), "git not found!")
local git = assert(find_tool("git", {version = true}), "git not found!")
local argv = {}
if opt.fsmonitor then
table.insert(argv, "-c")
Expand All @@ -48,6 +49,13 @@ function main(commit, opt)
table.insert(argv, "core.fsmonitor=false")
end

-- @see https://github.com/xmake-io/xmake/issues/6071
-- https://github.blog/open-source/git/bring-your-monorepo-down-to-size-with-sparse-checkout/
if opt.includes and git.version and semver.compare(git.version, "2.25") >= 0 then
os.vrunv(git.program, {"sparse-checkout", "init", "--cone"}, {curdir = opt.repodir})
os.vrunv(git.program, table.join({"sparse-checkout", "set"}, opt.includes), {curdir = opt.repodir})
end

table.insert(argv, "checkout")
table.insert(argv, commit)
os.vrunv(git.program, argv, {curdir = opt.repodir})
Expand Down
10 changes: 5 additions & 5 deletions xmake/modules/private/action/require/impl/actions/download.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function _checkout(package, url, sourcedir, opt)
git.clone(url, {treeless = true, checkout = false, longpaths = longpaths, outputdir = packagedir})

-- attempt to checkout the given version
git.checkout(revision, {repodir = packagedir})
git.checkout(revision, {repodir = packagedir, includes = opt.url_includes})

-- update all submodules
if os.isfile(path.join(packagedir, ".gitmodules")) and opt.url_submodules ~= false then
Expand Down Expand Up @@ -260,11 +260,7 @@ end

-- download codes from script
function _download_from_script(package, script, opt)

-- do download
script(package, opt)

-- trace
tty.erase_line_to_start().cr()
cprint("${yellow} => ${clear}download %s .. ${color.success}${text.success}", opt.url)
end
Expand Down Expand Up @@ -314,6 +310,7 @@ function main(package, opt)
for idx, url in ipairs(urls) do
local url_alias = package:url_alias(url)
local url_excludes = package:url_excludes(url)
local url_includes = package:url_includes(url)
local url_http_headers = package:url_http_headers(url)
local url_submodules = package:extraconf("urls", url, "submodules")

Expand Down Expand Up @@ -349,16 +346,19 @@ function main(package, opt)
url = url,
url_alias = url_alias,
url_excludes = url_excludes,
url_includes = url_includes,
url_submodules = url_submodules})
elseif git.checkurl(url) then
_checkout(package, url, sourcedir, {
url_alias = url_alias,
url_includes = url_includes,
url_submodules = url_submodules})
else
_download(package, url, sourcedir, {
download_only = opt.download_only,
url_alias = url_alias,
url_excludes = url_excludes,
url_includes = url_includes,
url_http_headers = url_http_headers})
end
return true
Expand Down
Loading