]> git.e2factory.org Git - e2factory.git/commitdiff
Unify git refs formatting
authorTobias Ulmer <tu@emlix.com>
Mon, 15 Jan 2018 17:49:23 +0000 (18:49 +0100)
committerTobias Ulmer <tu@emlix.com>
Mon, 10 Dec 2018 17:00:11 +0000 (18:00 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/generic_git.lua
plugins/git.lua

index 0764c1f173c3c0d3d755245c40f448139e137923..43fa60557c0fb9701f6aadad920a1ba4f4441a59 100644 (file)
@@ -79,6 +79,26 @@ local function git_clone_url(surl, destdir, skip_checkout)
     return true
 end
 
+--- Helper to generate refs/tags string.
+-- @param tag Tag
+-- @return refs/tags/tag
+function generic_git.refs_tags(tag)
+    assertIsStringN(tag)
+    return "refs/tags/"..tag
+end
+
+local refs_tags = generic_git.refs_tags
+
+--- Helper to generate refs/heads string
+-- @param branch Branch
+-- @return refs/heads/branch
+function generic_git.refs_heads(branch)
+    assertIsStringN(branch)
+    return "refs/heads/"..branch
+end
+
+local refs_heads = generic_git.refs_heads
+
 --- Create argument vector for calling git.
 -- Defaults: If git_dir is given and the default for work_tree is requested,
 -- it's assumed to be one directory level up. If work_tree is given and the
@@ -625,7 +645,7 @@ function generic_git.verify_remote_tag(gitdir, tag)
     local e = err.new("verifying remote tag")
     local rc, re, rtag, argv, rid, lid
 
-    rc, re, rid = generic_git.lookup_id(gitdir, true, "refs/tags/" .. tag)
+    rc, re, rid = generic_git.lookup_id(gitdir, true, refs_tags(tag))
     if not rc then
         return false, e:cat(re)
     end
@@ -636,7 +656,7 @@ function generic_git.verify_remote_tag(gitdir, tag)
         return false, e:cat(re)
     end
 
-    rc, re, lid = generic_git.lookup_id(gitdir, false, "refs/tags/" .. tag)
+    rc, re, lid = generic_git.lookup_id(gitdir, false, refs_tags(tag))
     if not rc then
         return false, e:cat(re)
     end
@@ -789,7 +809,7 @@ function generic_git.new_repository(c, lserver, llocation, rserver, rlocation)
     end
 
     argv = { "--git-dir="..gitdir, "config", "branch.master.merge",
-        "refs/heads/master" }
+        refs_heads("master") }
     rc, re = generic_git.git(argv)
     if not rc then
         return false, e:cat(re)
index 7ea6fb78889e7efa327f9e14fe9c8266b1bfe2ab..2a8fb4a68c892a7230678b35aa35bbf7f0a922b9 100644 (file)
@@ -35,6 +35,9 @@ local strict = require("strict")
 local tools = require("tools")
 local url = require("url")
 
+local refs_tags = generic_git.refs_tags
+local refs_heads = generic_git.refs_heads
+
 git.git_source = class("git_source", source.basic_source)
 
 function git.git_source.static:is_scm_source_class()
@@ -178,14 +181,14 @@ function git.git_source:git_commit_id(sourceset, check_remote)
     gitdir = e2lib.join(e2tool.root(), self:get_working(), ".git")
 
     if sourceset == "branch" then
-        ref = string.format("refs/heads/%s", self:get_branch())
+        ref = refs_heads(self:get_branch())
 
         rc, re, id = generic_git.lookup_id(gitdir, false, ref)
         if not rc then
             return false, e:cat(re)
         end
     elseif sourceset == "tag" then
-        ref = string.format("refs/tags/%s", self:get_tag())
+        ref = refs_tags(self:get_tag())
 
         rc, re, id = generic_git.lookup_id(gitdir, false, ref)
         if not rc then
@@ -328,7 +331,7 @@ function git.git_source:check_workingcopy()
 
     -- check if branch exists
     local gitdir = e2lib.join(e2tool.root(), self:get_working(), ".git")
-    local ref = string.format("refs/heads/%s", self._branch)
+    local ref = refs_heads(self._branch)
     local id
 
     rc = self:working_copy_available()
@@ -410,7 +413,7 @@ function git.git_source:fetch_source()
     end
 
     rc, re, id = generic_git.lookup_id(git_dir, false,
-        "refs/heads/" .. self:get_branch())
+        refs_heads(self:get_branch()))
     if not rc then
         return false, e:cat(re)
     elseif not id then
@@ -421,7 +424,7 @@ function git.git_source:fetch_source()
         end
 
         rc, re = generic_git.git_checkout1(work_tree,
-            "refs/heads/" .. self:get_branch())
+            refs_heads(self:get_branch()))
         if not rc then
             return false, e:cat(re)
         end
@@ -476,7 +479,7 @@ function git.git_source:update_source()
         return true
     end
 
-    if branch ~= "refs/heads/" .. self:get_branch() then
+    if branch ~= refs_heads(self:get_branch()) then
         e2lib.warnf("WOTHER", "not on configured branch. Skipping.")
         return true
     end
@@ -570,9 +573,9 @@ function git.git_source:prepare_source(sourceset, buildpath)
     table.insert(git_argv, "--format=tar")
 
     if sourceset == "branch" then
-        table.insert(git_argv, "refs/heads/" .. self:get_branch())
+        table.insert(git_argv, refs_heads(self:get_branch()))
     elseif sourceset == "tag" then
-        table.insert(git_argv, "refs/tags/" .. self:get_tag())
+        table.insert(git_argv, refs_tags(self:get_tag()))
     else
         error(err.new("invalid sourceset: %s", sourceset))
     end
@@ -706,9 +709,9 @@ local function git_to_result(src, sourceset, directory)
         local ref, tmpfn
 
         if sourceset == "tag" then
-            ref = string.format("refs/tags/%s", src:get_tag())
+            ref = refs_tags(src:get_tag())
         else
-            ref = string.format("refs/heads/%s", src:get_branch())
+            ref = refs_heads(src:get_branch())
         end
 
         tmpfn, re = e2lib.mktempfile()