if (not rc) and require_workingcopy then
return false, err.new("working copy is not available")
end
- rc, re = scm.check_workingcopy(info, sourcename)
+ rc, re = src:check_workingcopy()
if not rc then
return false, re
end
scm.register_interface("prepare_source")
scm.register_interface("fetch_source")
scm.register_interface("update")
-scm.register_interface("check_workingcopy")
return strict.lock(scm)
-- @return True or false.
-- @return Error object on false
function source.basic_source:working_copy_available()
- error(err.new("called working_copy_availabley() of source base class, type %s name %s",
+ error(err.new("called working_copy_available() of source base class, type %s name %s",
+ self._type, self._name))
+end
+
+--- Verify the consistency of the working copy, for example when building
+-- a release.
+-- @return True on success, false on error.
+-- Error object on failure.
+function source.basic_source:check_workingcopy()
+ error(err.new("called check_workingcopy() of source base class, type %s name %s",
self._type, self._name))
end
--- @section end
+--------------------------------------------------------------------------------
+
--- Dictionary holding all source objects indexed by their name.
source.sources = {}
return true
end
+function cvs.cvs_source:check_workingcopy()
+ return true
+end
+
+--------------------------------------------------------------------------------
+
--- Build the cvsroot string.
-- @param info Info table.
-- @param sourcename Source name.
return true, nil
end
-function cvs.check_workingcopy(info, sourcename)
- return true
-end
-
strict.lock(cvs)
-- vim:sw=4:sts=4:et:
return false, err.new("source %s doesn't require a working copy", self._name)
end
+function files.files_source:check_workingcopy()
+ return true
+end
+
+--------------------------------------------------------------------------------
+
function files.fetch_source(info, sourcename)
local rc, re
local src = source.sources[sourcename]
return true
end
---- Check for working copy availability.
--- @param info The info table.
--- @param sourcename The name of the source (string).
--- @return Boolean, true on success.
--- @return An error object on failure.
-function files.check_workingcopy(info, sourcename)
- return true, nil
-end
-
--- Update the source.
-- @param info The info table.
-- @param sourcename The name of the source (string).
exit = function (ctx) return true end,
}
+--------------------------------------------------------------------------------
+
git.git_source = class("git_source", source.basic_source)
function git.git_source.static:is_scm_source_class()
return true
end
+function git.git_source:check_workingcopy()
+
+ --- turn server:location into a git-style url
+ -- @param c table: a cache
+ -- @param server string: server name
+ -- @param location string: location
+ -- @return string: the git url, or nil
+ -- @return an error object on failure
+ local function git_url(c, server, location)
+ local e = err.new("translating server:location to git url")
+ local rurl, re = cache.remote_url(c, server, location)
+ if not rurl then
+ return nil, e:cat(re)
+ end
+ local u, re = url.parse(rurl)
+ if not u then
+ return nil, e:cat(re)
+ end
+ local g, re = generic_git.git_url1(u)
+ if not g then
+ return nil, e:cat(re)
+ end
+ return g, nil
+ end
+
+ local rc, re
+ local e = err.new("checking working copy of source %s failed", self._name)
+
+ -- check if branch exists
+ local gitdir = e2lib.join(e2tool.root(), self:get_working(), ".git")
+ local ref = string.format("refs/heads/%s", self._branch)
+ local id
+
+ rc = self:working_copy_available()
+ if not rc then
+ e2lib.warnf("WOTHER", "in source %s: ", self._name)
+ e2lib.warnf("WOTHER", " working copy is not available")
+ return true, nil
+ end
+
+
+ rc, re, id = generic_git.lookup_id(gitdir, false, ref)
+ if not rc then
+ return false, e:cat(re)
+ elseif not id then
+ return false, e:cat(err.new("branch %q does not exist", self._branch))
+ end
+
+ -- git config branch.<branch>.remote == "origin"
+ local query, expect, res
+ query = string.format("branch.%s.remote", self._branch)
+ res, re = generic_git.git_config(gitdir, query)
+ if not res then
+ e:append("remote is not configured for branch \"%s\"", self._branch)
+ return false, e
+ elseif res ~= "origin" then
+ e:append("%s is not \"origin\"", query)
+ return false, e
+ end
+
+ -- git config remote.origin.url == server:location
+ query = string.format("remote.origin.url")
+ expect, re = git_url(e2tool.info().cache, self._server, self._location)
+ if not expect then
+ return false, e:cat(re)
+ end
+ res, re = generic_git.git_config(gitdir, query)
+ if not res then
+ return false, e:cat(re)
+ end
+
+ local function remove_trailing_slashes(s)
+ while s:sub(#s) == "/" do
+ s = s:sub(1, #s-1)
+ end
+ return s
+ end
+
+ res = remove_trailing_slashes(res)
+ expect = remove_trailing_slashes(expect)
+ if res ~= expect then
+ e:append('git variable "%s" does not match e2 source configuration.',
+ query)
+ e:append('expected "%s" but got "%s" instead.', expect, res)
+ return false, e
+ end
+
+ return true
+end
+
--------------------------------------------------------------------------------
--- Return the git commit ID of the specified source configuration. Specific to
return false, e:cat(re)
end
- rc, re = scm.check_workingcopy(info, sourcename)
+ rc, re = src:check_workingcopy()
if not rc then
return false, e:cat(re)
end
return true
end
---- turn server:location into a git-style url
--- @param c table: a cache
--- @param server string: server name
--- @param location string: location
--- @return string: the git url, or nil
--- @return an error object on failure
-local function git_url(c, server, location)
- local e = err.new("translating server:location to git url")
- local rurl, re = cache.remote_url(c, server, location)
- if not rurl then
- return nil, e:cat(re)
- end
- local u, re = url.parse(rurl)
- if not u then
- return nil, e:cat(re)
- end
- local g, re = generic_git.git_url1(u)
- if not g then
- return nil, e:cat(re)
- end
- return g, nil
-end
-
function git.toresult(info, sourcename, sourceset, directory)
local rc, re, argv
local e = err.new("converting result")
return true, nil
end
-function git.check_workingcopy(info, sourcename)
- local rc, re
- local e = err.new("checking working copy of source %s failed", sourcename)
-
- -- check if branch exists
- local src = source.sources[sourcename]
- local gitdir = e2lib.join(e2tool.root(), src:get_working(), ".git")
- local ref = string.format("refs/heads/%s", src:get_branch())
- local id
-
- rc = src:working_copy_available()
- if not rc then
- e2lib.warnf("WOTHER", "in source %s: ", sourcename)
- e2lib.warnf("WOTHER", " working copy is not available")
- return true, nil
- end
-
-
- rc, re, id = generic_git.lookup_id(gitdir, false, ref)
- if not rc then
- return false, e:cat(re)
- elseif not id then
- return false, e:cat(err.new("branch %q does not exist", src:get_branch()))
- end
-
- -- git config branch.<branch>.remote == "origin"
- local query, expect, res
- query = string.format("branch.%s.remote", src:get_branch())
- res, re = generic_git.git_config(gitdir, query)
- if not res then
- e:append("remote is not configured for branch \"%s\"", src:get_branch())
- return false, e
- elseif res ~= "origin" then
- e:append("%s is not \"origin\"", query)
- return false, e
- end
-
- -- git config remote.origin.url == server:location
- query = string.format("remote.origin.url")
- expect, re = git_url(info.cache, src:get_server(), src:get_location())
- if not expect then
- return false, e:cat(re)
- end
- res, re = generic_git.git_config(gitdir, query)
- if not res then
- return false, e:cat(re)
- end
-
- local function remove_trailing_slashes(s)
- while s:sub(#s) == "/" do
- s = s:sub(1, #s-1)
- end
- return s
- end
-
- res = remove_trailing_slashes(res)
- expect = remove_trailing_slashes(expect)
- if res ~= expect then
- e:append('git variable "%s" does not match e2 source configuration.',
- query)
- e:append('expected "%s" but got "%s" instead.', expect, res)
- return false, e
- end
-
- return true
-end
-
strict.lock(git)
-- vim:sw=4:sts=4:et:
return true
end
+function gitrepo_source:check_workingcopy()
+
+ --- turn server:location into a git-style url
+ -- @param c table: a cache
+ -- @param server string: server name
+ -- @param location string: location
+ -- @return string: the git url, or nil
+ -- @return an error object on failure
+ local function git_url(c, server, location)
+ local e = err.new("translating server:location to git url")
+ local rurl, re = cache.remote_url(c, server, location)
+ if not rurl then
+ return nil, e:cat(re)
+ end
+ local u, re = url.parse(rurl)
+ if not u then
+ return nil, e:cat(re)
+ end
+ local g, re = generic_git.git_url1(u)
+ if not g then
+ return nil, e:cat(re)
+ end
+ return g, nil
+ end
+
+ local rc, re
+ local e = err.new("checking working copy of source %s failed", self._name)
+
+ -- check if branch exists
+ local gitdir = e2lib.join(e2tool.root(), self:get_working(), ".git")
+ local ref = string.format("refs/heads/%s", self._branch)
+ local id
+
+ rc = self:working_copy_available()
+ if not rc then
+ e2lib.warnf("WOTHER", "in source %s: ", self._name)
+ e2lib.warnf("WOTHER", " working copy is not available")
+ return true, nil
+ end
+
+ rc, re, id = generic_git.lookup_id(gitdir, false, ref)
+ if not rc then
+ return false, e:cat(re)
+ elseif not id then
+ return false, e:cat(err.new("branch %q does not exist", self._branch))
+ end
+
+ -- git config branch.<branch>.remote == "origin"
+ local query, expect, res
+ query = string.format("branch.%s.remote", self._branch)
+ res, re = generic_git.git_config(gitdir, query)
+ if not res then
+ e:append("remote is not configured for branch \"%s\"", self._branch)
+ return false, e
+ elseif res ~= "origin" then
+ e:append("%s is not \"origin\"", query)
+ return false, e
+ end
+
+ -- git config remote.origin.url == server:location
+ query = string.format("remote.origin.url")
+ expect, re = git_url(e2tool.info().cache, self._server, self._location)
+ if not expect then
+ return false, e:cat(re)
+ end
+ res, re = generic_git.git_config(gitdir, query)
+ if not res then
+ return false, e:cat(re)
+ end
+
+ local function remove_trailing_slashes(s)
+ while s:sub(#s) == "/" do
+ s = s:sub(1, #s-1)
+ end
+ return s
+ end
+
+ res = remove_trailing_slashes(res)
+ expect = remove_trailing_slashes(expect)
+ if res ~= expect then
+ e:append('git variable "%s" does not match e2 source configuration.',
+ query)
+ e:append('expected "%s" but got "%s" instead.', expect, res)
+ return false, e
+ end
+
+ return true
+end
+
--------------------------------------------------------------------------------
--- Fetch a gitrepo source. Adapted from git plugin.
return true
end
---- turn server:location into a git-style url
--- @param c table: a cache
--- @param server string: server name
--- @param location string: location
--- @return string: the git url, or nil
--- @return an error object on failure
-local function git_url(c, server, location)
- local e = err.new("translating server:location to git url")
- local rurl, re = cache.remote_url(c, server, location)
- if not rurl then
- return nil, e:cat(re)
- end
- local u, re = url.parse(rurl)
- if not u then
- return nil, e:cat(re)
- end
- local g, re = generic_git.git_url1(u)
- if not g then
- return nil, e:cat(re)
- end
- return g, nil
-end
-
-function gitrepo.check_workingcopy(info, sourcename)
- local rc, re
- local e = err.new("checking working copy of source %s failed", sourcename)
-
- -- check if branch exists
- local src = source.sources[sourcename]
- local gitdir = e2lib.join(e2tool.root(), src:get_working(), ".git")
- local ref = string.format("refs/heads/%s", src:get_branch())
- local id
-
- rc = src:working_copy_available()
- if not rc then
- e2lib.warnf("WOTHER", "in source %s: ", sourcename)
- e2lib.warnf("WOTHER", " working copy is not available")
- return true, nil
- end
-
- rc, re, id = generic_git.lookup_id(gitdir, false, ref)
- if not rc then
- return false, e:cat(re)
- elseif not id then
- return false, e:cat(err.new("branch %q does not exist", src:get_branch()))
- end
-
- -- git config branch.<branch>.remote == "origin"
- local query, expect, res
- query = string.format("branch.%s.remote", src:get_branch())
- res, re = generic_git.git_config(gitdir, query)
- if not res then
- e:append("remote is not configured for branch \"%s\"", src:get_branch())
- return false, e
- elseif res ~= "origin" then
- e:append("%s is not \"origin\"", query)
- return false, e
- end
-
- -- git config remote.origin.url == server:location
- query = string.format("remote.origin.url")
- expect, re = git_url(info.cache, src:get_server(), src:get_location())
- if not expect then
- return false, e:cat(re)
- end
- res, re = generic_git.git_config(gitdir, query)
- if not res then
- return false, e:cat(re)
- end
-
- local function remove_trailing_slashes(s)
- while s:sub(#s) == "/" do
- s = s:sub(1, #s-1)
- end
- return s
- end
-
- res = remove_trailing_slashes(res)
- expect = remove_trailing_slashes(expect)
- if res ~= expect then
- e:append('git variable "%s" does not match e2 source configuration.',
- query)
- e:append('expected "%s" but got "%s" instead.', expect, res)
- return false, e
- end
-
- return true
-end
-
--- Archives the source and prepares the necessary files outside the archive
-- @param info the info structure
-- @param sourcename string
return true
end
+function svn.svn_source:check_workingcopy()
+ local rc, re
+ local e = err.new("checking working copy failed")
+ e:append("in source %s (svn configuration):", self._name)
+ e:setcount(0)
+ if e:getcount() > 0 then
+ return false, e
+ end
+ -- check if the configured branch and tag exist
+ local d
+ d = e2lib.join(e2tool.root(), self:get_working(), self._branch)
+ if not e2lib.isdir(d) then
+ e:append("branch does not exist: %s", self._branch)
+ end
+ d = e2lib.join(e2tool.root(), self:get_working(), self._tag)
+ if not e2lib.isdir(d) then
+ e:append("tag does not exist: %s", self._tag)
+ end
+ if e:getcount() > 0 then
+ return false, e
+ end
+ return true
+end
+
--------------------------------------------------------------------------------
function svn.fetch_source(info, sourcename)
return true, nil
end
-function svn.check_workingcopy(info, sourcename)
- local rc, re
- local e = err.new("checking working copy failed")
- e:append("in source %s (svn configuration):", sourcename)
- e:setcount(0)
- local src = source.sources[sourcename]
- if e:getcount() > 0 then
- return false, e
- end
- -- check if the configured branch and tag exist
- local d
- d = e2lib.join(e2tool.root(), src:get_working(), src:get_branch())
- if not e2lib.isdir(d) then
- e:append("branch does not exist: %s", src:get_branch())
- end
- d = e2lib.join(e2tool.root(), src:get_working(), src:get_tag())
- if not e2lib.isdir(d) then
- e:append("tag does not exist: %s", src:get_tag())
- end
- if e:getcount() > 0 then
- return false, e
- end
- return true
-end
-
function svn.toresult(info, sourcename, sourceset, directory)
-- <directory>/source/<sourcename>.tar.gz
-- <directory>/makefile