]> git.e2factory.org Git - e2factory.git/commitdiff
move working_copy_available() into the source classes
authorTobias Ulmer <tu@emlix.com>
Fri, 20 Jan 2017 15:59:03 +0000 (16:59 +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 ab0171d00884b8766843dbefbae698baa9dc48ba..d1a1134344e9fda3e831007e4538604cb68f96af 100644 (file)
@@ -1,7 +1,7 @@
 --- SCM Interface
 -- @module local.scm
 
--- Copyright (C) 2007-2016 emlix GmbH, see file AUTHORS
+-- Copyright (C) 2007-2017 emlix GmbH, see file AUTHORS
 --
 -- This file is part of e2factory, the emlix embedded build system.
 -- For more information see http://www.e2factory.org
@@ -140,9 +140,10 @@ end
 -- @return bool
 -- @return an error object on failure
 function scm.generic_source_check(info, sourcename, require_workingcopy)
-    local rc, re
+    local rc, re, src
+    src = source.sources[sourcename]
 
-    rc, re = scm.working_copy_available(info, sourcename)
+    rc, re = src:working_copy_available()
     if (not rc) and require_workingcopy then
         return false, err.new("working copy is not available")
     end
@@ -150,7 +151,7 @@ function scm.generic_source_check(info, sourcename, require_workingcopy)
     if not rc then
         return false, re
     end
-    return true, nil
+    return true
 end
 
 scm.register_interface("toresult")
@@ -158,7 +159,6 @@ scm.register_interface("prepare_source")
 scm.register_interface("fetch_source")
 scm.register_interface("update")
 scm.register_interface("check_workingcopy")
-scm.register_interface("working_copy_available")
 
 return strict.lock(scm)
 
index 0f4fd0bc30237d99cd22503b376cd008ecc9858e..15228de1d7d8f84e8db756d848fc44284d6c16a0 100644 (file)
@@ -137,6 +137,15 @@ function source.basic_source:display()
         self._type, self._name))
 end
 
+--- Check whether the working copy is available. Sources that don't have a
+-- working copy should return false and an error object. Abstract method.
+-- @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",
+        self._type, self._name))
+end
+
 --- @section end
 
 --- Dictionary holding all source objects indexed by their name.
index 67c53a9f54cc01d8968333517eff61a50c54a9d9..9ad22e56baa828e938c7d10d865c6d6e599a4a28 100644 (file)
@@ -282,6 +282,13 @@ function cvs.cvs_source:display()
     return d
 end
 
+function cvs.cvs_source:working_copy_available()
+    if not e2lib.isdir(e2lib.join(e2tool.root(), self._working)) then
+        return false, err.new("working copy for %s is not available", self._name)
+    end
+    return true
+end
+
 --- Build the cvsroot string.
 -- @param info Info table.
 -- @param sourcename Source name.
@@ -319,13 +326,13 @@ end
 function cvs.fetch_source(info, sourcename)
     local rc, re, e, src, cvsroot, workdir, argv
 
-    if scm.working_copy_available(info, sourcename) then
-        return true
-    end
-
     e = err.new("fetching source failed: %s", sourcename)
     src = source.sources[sourcename]
 
+    if src:working_copy_available() then
+        return true
+    end
+
     cvsroot, re = mkcvsroot(info, sourcename)
     if not cvsroot then
         return false, e:cat(re)
@@ -411,7 +418,7 @@ function cvs.update(info, sourcename)
     e = err.new("updating source '%s' failed", sourcename)
     src = source.sources[sourcename]
 
-    rc, re = scm.working_copy_available(info, sourcename)
+    rc, re = src:working_copy_available()
     if not rc then
         return false, e:cat(re)
     end
@@ -427,15 +434,6 @@ function cvs.update(info, sourcename)
     return true
 end
 
-function cvs.working_copy_available(info, sourcename)
-    local src = source.sources[sourcename]
-    local dir = e2lib.join(e2tool.root(), src:get_working())
-    if not e2lib.isdir(dir) then
-        return false, err.new("working copy for %s is not available", sourcename)
-    end
-    return true
-end
-
 function cvs.toresult(info, sourcename, sourceset, directory)
     -- <directory>/source/<sourcename>.tar.gz
     -- <directory>/makefile
index 2b0b3701d7799bce1882670ed456c8e9bbeeee67..8be0247e633f5ca485cbc3dcc2c5edae247ae0ea 100644 (file)
@@ -293,6 +293,10 @@ function files.files_source:display()
     return d
 end
 
+function files.files_source:working_copy_available()
+    return false, err.new("source %s doesn't require a working copy", self._name)
+end
+
 function files.fetch_source(info, sourcename)
     local rc, re
     local src = source.sources[sourcename]
@@ -313,10 +317,6 @@ function files.fetch_source(info, sourcename)
     return true
 end
 
-function files.working_copy_available(info, sourcename)
-    return false, err.new("source %s doesn't require a working copy", sourcename)
-end
-
 --- Handle file:copy() in a way that appears intuitive to the user. Returns
 -- a directory and filename that can be passed to eg. mkdir -p and cp.
 -- @param buildpath Base build path (string).
index 5ef74756a894e34c11d749503c051ea06caea0cd..4d4079b0b2bbec4ba7f7541c3d08b27fdf1e5682 100644 (file)
@@ -274,6 +274,18 @@ function git.git_source:display()
     return d
 end
 
+--- Check if a working copy for a git repository is available
+-- @return True if available, false otherwise.
+-- @return Error object if no directory.
+function git.git_source:working_copy_available()
+    if not e2lib.isdir(e2lib.join(e2tool.root(), self._working)) then
+        return false, err.new("working copy for %s is not available", self._name)
+    end
+    return true
+end
+
+--------------------------------------------------------------------------------
+
 --- Return the git commit ID of the specified source configuration. Specific to
 -- sources of type git, useful for writing plugins.
 -- @param info Info table.
@@ -289,7 +301,7 @@ function git.git_commit_id(info, sourcename, sourceset, check_remote)
     e = err.new("getting commit ID failed for source: %s", sourcename)
     src = source.sources[sourcename]
 
-    rc, re = scm.working_copy_available(info, sourcename)
+    rc, re = src:working_copy_available()
     if not rc then
         return false, e:cat(re)
     end
@@ -346,7 +358,7 @@ function git.update(info, sourcename)
     src = source.sources[sourcename]
     e = err.new("updating source '%s' failed", sourcename)
 
-    rc, re = scm.working_copy_available(info, sourcename)
+    rc, re = src:working_copy_available()
     if not rc then
         return false, e:cat(re)
     end
@@ -415,13 +427,13 @@ end
 function git.fetch_source(info, sourcename)
     local e, rc, re, src, git_dir, work_tree, id
 
-    if scm.working_copy_available(info, sourcename) then
-        return true
-    end
-
     src = source.sources[sourcename]
     e = err.new("fetching source failed: %s", sourcename)
 
+    if src:working_copy_available() then
+        return true
+    end
+
     work_tree = e2lib.join(e2tool.root(), src:get_working())
     git_dir = e2lib.join(work_tree, ".git")
 
@@ -619,22 +631,6 @@ function git.prepare_source(info, sourcename, sourceset, buildpath)
     return true
 end
 
---- Check if a working copy for a git repository is available
--- @param info the info structure
--- @param sourcename string
--- @return True if available, false otherwise.
--- @return Error object if no directory.
-function git.working_copy_available(info, sourcename)
-    local rc
-    local src = source.sources[sourcename]
-    local gitwc = e2lib.join(e2tool.root(), src:get_working())
-
-    if not e2lib.isdir(gitwc) then
-        return false, err.new("working copy for %s is not available", sourcename)
-    end
-    return true
-end
-
 --- turn server:location into a git-style url
 -- @param c table: a cache
 -- @param server string: server name
@@ -759,18 +755,19 @@ function git.check_workingcopy(info, sourcename)
     local rc, re
     local e = err.new("checking working copy of source %s failed", sourcename)
 
-    rc = scm.working_copy_available(info, 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
 
-    -- 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, re, id = generic_git.lookup_id(gitdir, false, ref)
     if not rc then
index 96e37a458795a36297e51a0eeb6db4e3cb255ad5..d4bf261b6dfb845e1a5ba2fc4399b5a227b07ac8 100644 (file)
@@ -220,25 +220,18 @@ function gitrepo_source:display()
     return d
 end
 
---------------------------------------------------------------------------------
-
 --- Check if a working copy for a git repository is available
--- @param info the info structure
--- @param sourcename string
--- @return True if working copy is available, false otherwise.
--- @return Informative error object if directory does not exist
-function gitrepo.working_copy_available(info, sourcename)
-    assertIsTable(info)
-    assertIsStringN(sourcename)
-
-    local src = source.sources[sourcename]
-
-    if not e2lib.isdir(e2lib.join(e2tool.root(), src:get_working())) then
-        return false, err.new("working copy for %s is not available", sourcename)
+-- @return True if available, false otherwise.
+-- @return Error object if no directory.
+function gitrepo_source:working_copy_available()
+    if not e2lib.isdir(e2lib.join(e2tool.root(), self._working)) then
+        return false, err.new("working copy for %s is not available", self._name)
     end
     return true
 end
 
+--------------------------------------------------------------------------------
+
 --- Fetch a gitrepo source. Adapted from git plugin.
 -- @param info the info structure
 -- @param sourcename string
@@ -250,13 +243,13 @@ function gitrepo.fetch_source(info, sourcename)
 
     local e, rc, re, src, git_dir, work_tree, id
 
-    if scm.working_copy_available(info, sourcename) then
-        return true
-    end
-
     src = source.sources[sourcename]
     e = err.new("fetching source failed: %s", sourcename)
 
+    if src:working_copy_available() then
+        return true
+    end
+
     work_tree = e2lib.join(e2tool.root(), src:get_working())
     git_dir = e2lib.join(work_tree, ".git")
 
@@ -464,19 +457,19 @@ function gitrepo.check_workingcopy(info, sourcename)
     local rc, re
     local e = err.new("checking working copy of source %s failed", sourcename)
 
-    rc = scm.working_copy_available(info, sourcename)
-    if not rc then
-        e2lib.warnf("WOTHER", "in source %s: ", sourcename)
-        e2lib.warnf("WOTHER", " working copy is not available")
-        return true, nil
-    end
-
     -- 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)
index a54010e5b18da64c0b97eb443f6bc303219e42da..56711dfb5cda34cb3b597fc2fdb01f224c4e0c0e 100644 (file)
@@ -369,6 +369,15 @@ function svn.svn_source:display()
     return d
 end
 
+function svn.svn_source:working_copy_available()
+    if not e2lib.isdir(e2lib.join(e2tool.root(), self._working)) then
+        return false, err.new("working copy for %s is not available", self._name)
+    end
+    return true
+end
+
+--------------------------------------------------------------------------------
+
 function svn.fetch_source(info, sourcename)
     local rc, re
     local e = err.new("fetching source failed: %s", sourcename)
@@ -384,7 +393,7 @@ function svn.fetch_source(info, sourcename)
         return false, e:cat(re)
     end
 
-    if scm.working_copy_available(info, sourcename) then
+    if src:working_copy_available() then
         return true
     end
 
@@ -439,17 +448,6 @@ function svn.prepare_source(info, sourcename, sourceset, build_path)
     return true, nil
 end
 
-function svn.working_copy_available(info, sourcename)
-    local rc, re
-    local src = source.sources[sourcename]
-
-    local dir = e2lib.join(e2tool.root(), src:get_working())
-    if not e2lib.isdir(dir) then
-        return false, err.new("working copy for %s is not available", sourcename)
-    end
-    return true
-end
-
 function svn.check_workingcopy(info, sourcename)
     local rc, re
     local e = err.new("checking working copy failed")