]> git.e2factory.org Git - e2factory.git/commitdiff
move check_workingcopy() into the source classes
authorTobias Ulmer <tu@emlix.com>
Fri, 20 Jan 2017 17:23:57 +0000 (18:23 +0100)
committerTobias Ulmer <tu@emlix.com>
Mon, 30 Jan 2017 13:33:34 +0000 (14:33 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
local/scm.lua
local/source.lua
plugins/cvs.lua
plugins/files.lua
plugins/git.lua
plugins/gitrepo.lua
plugins/svn.lua

index d1a1134344e9fda3e831007e4538604cb68f96af..2232b0716605a975a5366df9e8b7c56d5991a5bc 100644 (file)
@@ -147,7 +147,7 @@ function scm.generic_source_check(info, sourcename, require_workingcopy)
     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
@@ -158,7 +158,6 @@ scm.register_interface("toresult")
 scm.register_interface("prepare_source")
 scm.register_interface("fetch_source")
 scm.register_interface("update")
-scm.register_interface("check_workingcopy")
 
 return strict.lock(scm)
 
index 15228de1d7d8f84e8db756d848fc44284d6c16a0..849c2a3f823dea40bfcc79e9aa4fed1a77bf7fc3 100644 (file)
@@ -142,12 +142,23 @@ end
 -- @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 = {}
 
index 9ad22e56baa828e938c7d10d865c6d6e599a4a28..a7c98b55968d4104d27e5bc6dafd69b97fcdfeb1 100644 (file)
@@ -289,6 +289,12 @@ function cvs.cvs_source:working_copy_available()
     return true
 end
 
+function cvs.cvs_source:check_workingcopy()
+    return true
+end
+
+--------------------------------------------------------------------------------
+
 --- Build the cvsroot string.
 -- @param info Info table.
 -- @param sourcename Source name.
@@ -500,10 +506,6 @@ function cvs.toresult(info, sourcename, sourceset, directory)
     return true, nil
 end
 
-function cvs.check_workingcopy(info, sourcename)
-    return true
-end
-
 strict.lock(cvs)
 
 -- vim:sw=4:sts=4:et:
index 8be0247e633f5ca485cbc3dcc2c5edae247ae0ea..4334a38eb0c9caf518db7375f273c96410a95538 100644 (file)
@@ -297,6 +297,12 @@ function files.files_source:working_copy_available()
     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]
@@ -702,15 +708,6 @@ function files.toresult(info, sourcename, sourceset, directory)
     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).
index 4d4079b0b2bbec4ba7f7541c3d08b27fdf1e5682..5ddac52a6b355d82034c96ddc2384aef8b0af195 100644 (file)
@@ -76,6 +76,8 @@ plugin_descriptor = {
     exit = function (ctx) return true end,
 }
 
+--------------------------------------------------------------------------------
+
 git.git_source = class("git_source", source.basic_source)
 
 function git.git_source.static:is_scm_source_class()
@@ -284,6 +286,96 @@ function git.git_source:working_copy_available()
     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
@@ -306,7 +398,7 @@ function git.git_commit_id(info, sourcename, sourceset, check_remote)
         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
@@ -631,29 +723,6 @@ function git.prepare_source(info, sourcename, sourceset, buildpath)
     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")
@@ -751,73 +820,6 @@ function git.toresult(info, sourcename, sourceset, directory)
     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:
index d4bf261b6dfb845e1a5ba2fc4399b5a227b07ac8..22b98e9f33226a8bf9d3e8c5eefada70ccef2b7a 100644 (file)
@@ -230,6 +230,95 @@ function gitrepo_source:working_copy_available()
     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.
@@ -430,95 +519,6 @@ function gitrepo.update(info, sourcename)
     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
index 56711dfb5cda34cb3b597fc2fdb01f224c4e0c0e..85fd09693a81540a6576a4dc8ac7db7492f7b7b6 100644 (file)
@@ -376,6 +376,30 @@ function svn.svn_source:working_copy_available()
     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)
@@ -448,31 +472,6 @@ function svn.prepare_source(info, sourcename, sourceset, build_path)
     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