summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-11-26 22:41:40 +0800
committerruki <[email protected]>2018-11-26 10:10:01 +0800
commitec7326c033eea745ef5aa26533c55f4126c59609 (patch)
tree4412263e5e50ff6af596146a46fabef9f04796c7
parent37e8540596dbe4310fc6f4aad31b087f35bd7499 (diff)
support to set branch for repo
-rw-r--r--xmake/core/package/repository.lua23
-rw-r--r--xmake/core/sandbox/modules/import/core/package/repository.lua26
-rw-r--r--xmake/plugins/repo/main.lua14
-rw-r--r--xmake/plugins/repo/xmake.lua7
4 files changed, 44 insertions, 26 deletions
diff --git a/xmake/core/package/repository.lua b/xmake/core/package/repository.lua
index dd6983294..34bb1adec 100644
--- a/xmake/core/package/repository.lua
+++ b/xmake/core/package/repository.lua
@@ -35,7 +35,7 @@ local config = require("project/config")
local interpreter = require("base/interpreter")
-- new an instance
-function _instance.new(name, url, directory, is_global)
+function _instance.new(name, url, branch, directory, is_global)
-- new an instance
local instance = table.inherit(_instance)
@@ -43,6 +43,7 @@ function _instance.new(name, url, directory, is_global)
-- init instance
instance._NAME = name
instance._URL = url
+ instance._BRANCH = branch
instance._DIRECTORY = directory
instance._IS_GLOBAL = is_global
@@ -73,6 +74,11 @@ function _instance:url()
return self._URL
end
+-- get the repository branch
+function _instance:branch()
+ return self._BRANCH
+end
+
-- is global repository?
function _instance:is_global()
return self._IS_GLOBAL
@@ -172,7 +178,7 @@ function repository.directory(is_global)
end
-- load the repository
-function repository.load(name, url, is_global)
+function repository.load(name, url, branch, is_global)
-- get it directly from cache first
repository._REPOS = repository._REPOS or {}
@@ -184,7 +190,7 @@ function repository.load(name, url, is_global)
local repodir = os.isdir(url) and url or path.join(repository.directory(is_global), name)
-- new an instance
- local instance, errors = _instance.new(name, url, repodir, is_global)
+ local instance, errors = _instance.new(name, url, branch, repodir, is_global)
if not instance then
return nil, errors
end
@@ -202,12 +208,17 @@ function repository.get(name, is_global)
-- get it
local repositories = repository.repositories(is_global)
if repositories then
- return repositories[name]
+ local repoinfo = repositories[name]
+ if type(repoinfo) == "table" then
+ return repoinfo[1], repoinfo[2]
+ else
+ return repoinfo
+ end
end
end
-- add repository url to the given name
-function repository.add(name, url, is_global)
+function repository.add(name, url, branch, is_global)
-- no name?
if not name then
@@ -218,7 +229,7 @@ function repository.add(name, url, is_global)
local repositories = repository.repositories(is_global) or {}
-- set it
- repositories[name] = url
+ repositories[name] = {url, branch}
-- save repositories
repository._cache(is_global):set("repositories", repositories)
diff --git a/xmake/core/sandbox/modules/import/core/package/repository.lua b/xmake/core/sandbox/modules/import/core/package/repository.lua
index 63506dab5..e61e2d907 100644
--- a/xmake/core/sandbox/modules/import/core/package/repository.lua
+++ b/xmake/core/sandbox/modules/import/core/package/repository.lua
@@ -38,16 +38,14 @@ end
-- get repository url from the given name
function sandbox_core_package_repository.get(name, is_global)
-
- -- get it
return repository.get(name, is_global)
end
-- add repository url to the given name
-function sandbox_core_package_repository.add(name, url, is_global)
+function sandbox_core_package_repository.add(name, url, branch, is_global)
-- add it
- local ok, errors = repository.add(name, url, is_global)
+ local ok, errors = repository.add(name, url, branch, is_global)
if not ok then
raise(errors)
end
@@ -90,7 +88,7 @@ function sandbox_core_package_repository.repositories(is_global)
-- add main url
if #mainurls > 0 then
- local repo = repository.load("xmake-repo", mainurls[1], true)
+ local repo = repository.load("xmake-repo", mainurls[1], "master", true)
if repo then
table.insert(repositories, repo)
end
@@ -99,8 +97,14 @@ function sandbox_core_package_repository.repositories(is_global)
-- load repositories from repository cache
- for name, url in pairs(table.wrap(repository.repositories(is_global))) do
- local repo = repository.load(name, url, is_global)
+ for name, repoinfo in pairs(table.wrap(repository.repositories(is_global))) do
+ local url = repoinfo
+ local branch = nil
+ if type(repoinfo) == "table" then
+ url = repoinfo[1]
+ branch = repoinfo[2]
+ end
+ local repo = repository.load(name, url, branch, is_global)
if repo then
table.insert(repositories, repo)
end
@@ -110,13 +114,13 @@ function sandbox_core_package_repository.repositories(is_global)
--
-- in project xmake.lua:
--
- -- add_repositories("other-repo https://github.com/other/other-repo.git")
+ -- add_repositories("other-repo https://github.com/other/other-repo.git dev")
--
if not is_global then
for _, repo in ipairs(table.wrap(project.get("repositories"))) do
local repoinfo = repo:split(' ')
- if #repoinfo == 2 then
- local repo = repository.load(repoinfo[1], repoinfo[2], is_global)
+ if #repoinfo <= 3 then
+ local repo = repository.load(repoinfo[1], repoinfo[2], repoinfo[3], is_global)
if repo then
table.insert(repositories, repo)
end
@@ -128,7 +132,7 @@ function sandbox_core_package_repository.repositories(is_global)
-- load repository from builtin program directory
if is_global then
- local repo = repository.load("builtin-repo", path.join(os.programdir(), "repository"), true)
+ local repo = repository.load("builtin-repo", path.join(os.programdir(), "repository"), nil, true)
if repo then
table.insert(repositories, repo)
end
diff --git a/xmake/plugins/repo/main.lua b/xmake/plugins/repo/main.lua
index e91682fcf..73427dcaf 100644
--- a/xmake/plugins/repo/main.lua
+++ b/xmake/plugins/repo/main.lua
@@ -32,10 +32,10 @@ import("devel.git")
import("actions.require.impl.environment", {rootdir = os.programdir()})
-- add repository url
-function _add(name, url, is_global)
+function _add(name, url, branch, is_global)
-- add url
- repository.add(name, url, is_global)
+ repository.add(name, url, branch, is_global)
-- remove previous repository if exists
local repodir = path.join(repository.directory(is_global), name)
@@ -47,10 +47,12 @@ function _add(name, url, is_global)
environment.enter()
-- clone repository
- git.clone(url, {verbose = option.get("verbose"), branch = "master", outputdir = repodir})
+ if git.checkurl(url) then
+ git.clone(url, {verbose = option.get("verbose"), branch = branch or "master", outputdir = repodir})
+ end
-- trace
- cprint("${bright}add %s repository(%s): %s ok!", ifelse(is_global, "global", "local"), name, url)
+ cprint("${bright}add %s repository(%s): %s%s ok!", ifelse(is_global, "global", "local"), name, url, branch and (" " .. branch) or "")
-- leave environment
environment.leave()
@@ -175,7 +177,7 @@ function _list()
-- trace
local description = repo:get("description")
- print(" %s %s %s", repo:name(), repo:url(), description and ("(" .. description .. ")") or "")
+ print(" %s %s%s %s", repo:name(), repo:url(), repo:branch() and (" " .. repo:branch()) or "", description and ("(" .. description .. ")") or "")
-- update count
count = count + 1
@@ -218,7 +220,7 @@ function main()
-- add repository url
if option.get("add") then
- _add(option.get("name"), option.get("url"), option.get("global"))
+ _add(option.get("name"), option.get("url"), option.get("branch"), option.get("global"))
-- remove repository url
elseif option.get("remove") then
diff --git a/xmake/plugins/repo/xmake.lua b/xmake/plugins/repo/xmake.lua
index 4355afba7..172e6edd9 100644
--- a/xmake/plugins/repo/xmake.lua
+++ b/xmake/plugins/repo/xmake.lua
@@ -34,7 +34,7 @@ task("repo")
-- set menu
set_menu {
-- usage
- usage = "xmake repo [options] [name] [url]"
+ usage = "xmake repo [options] [name] [url] [branch]"
-- description
, description = "Manage package repositories."
@@ -52,5 +52,6 @@ task("repo")
, { }
, {nil, "name", "v", nil, "The repository name." }
, {nil, "url", "v", nil, "The repository url" }
- }
- }
+ , {nil, "branch", "v", nil, "The repository branch" }
+ }
+ }