From e8d683e28ca8fcf7b37640e1a16587ca6ce652c9 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Mon, 18 Nov 2013 18:53:51 +0100 Subject: [PATCH] Remove shell command constructs from git.toresult() Signed-off-by: Tobias Ulmer --- plugins/git.lua | 65 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/plugins/git.lua b/plugins/git.lua index 634f998..1ef414c 100644 --- a/plugins/git.lua +++ b/plugins/git.lua @@ -545,7 +545,7 @@ function git.sourceid(info, sourcename, sourceset) end function git.toresult(info, sourcename, sourceset, directory) - local rc, re + local rc, re, argv local e = err.new("converting result") rc, re = scm.generic_source_check(info, sourcename, true) if not rc then @@ -564,30 +564,55 @@ function git.toresult(info, sourcename, sourceset, directory) end if sourceset == "tag" or sourceset == "branch" then - local ref = generic_git.sourceset2ref(sourceset, src.branch, src.tag) - -- git archive --format=tar | gzip > - cmd = string.format( - "cd %s/%s && git archive --format=tar --prefix=%s/ %s".. - " | gzip > %s/%s", - e2lib.shquote(info.root), e2lib.shquote(src.working), - e2lib.shquote(sourcename), e2lib.shquote(ref), - e2lib.shquote(sourcedir), e2lib.shquote(archive)) + local ref, tmpfn + + ref = generic_git.sourceset2ref(sourceset, src.branch, src.tag) + + tmpfn, re = e2lib.mktempfile() + if not tmpfn then + return false, e:cat(re) + end + + argv = generic_git.git_new_argv(nil, e2lib.join(info.root, src.working)) + table.insert(argv, "archive") + table.insert(argv, "--format=tar") -- older versions don't have "tar.gz" + table.insert(argv, string.format("--prefix=%s/", sourcename)) + table.insert(argv, "-o") + table.insert(argv, tmpfn) + table.insert(argv, ref) + + rc, re = generic_git.git(argv) + if not rc then + return false, e:cat(re) + end + + rc, re = e2lib.gzip({ "-n", tmpfn }) + if not rc then + return false, re + end + + rc, re = e2lib.mv(tmpfn..".gz", e2lib.join(sourcedir, archive)) + if not rc then + return false, re + end elseif sourceset == "working-copy" then - cmd = string.format("tar -C %s/%s " .. - "--transform=s,^./,./%s/, ".. - "--exclude=.git ".. - "-czf %s/%s .", - e2lib.shquote(info.root), e2lib.shquote(src.working), - e2lib.shquote(sourcename), e2lib.shquote(sourcedir), - e2lib.shquote(archive)) + argv = { + "-C", e2lib.join(info.root, src.working), + string.format("--transform=s,^./,./%s/,", sourcename), + "--exclude=.git", + "-czf", + e2lib.join(sourcedir, archive), + "." + } + + rc, re = e2lib.tar(argv) + if not rc then + return false, e:cat(re) + end else return false, e:append("sourceset not supported: %s", sourceset) end - rc, re = e2lib.callcmd_log(cmd) - if not rc or rc ~= 0 then - return false, e:cat(re) - end local fname = string.format("%s/%s", directory, makefile) local f, msg = io.open(fname, "w") if not f then -- 2.39.5