From: Tobias Ulmer Date: Tue, 26 Nov 2013 15:34:52 +0000 (+0100) Subject: Directly checkout or copy instead of using callcmd_pipe with tar X-Git-Tag: e2factory-2.3.15rc1~333 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=425e4b5235d4a9e09d3098da62619911ead35777;p=e2factory.git Directly checkout or copy instead of using callcmd_pipe with tar Signed-off-by: Tobias Ulmer --- diff --git a/plugins/git.lua b/plugins/git.lua index c761394..d3d09d9 100644 --- a/plugins/git.lua +++ b/plugins/git.lua @@ -324,84 +324,91 @@ function git.prepare_source(info, sourcename, sourceset, buildpath) if not rc then return false, e:cat(re) end - local gitdir = info.root .. "/" .. src.working .. "/.git/" + local gitdir = e2lib.join(info.root, src.working, ".git") if sourceset == "branch" or (sourceset == "lazytag" and src.tag == "^") then + local argv, work_tree + rc, re = git.git_commit_id(info, sourcename, sourceset) if not rc then return false, e:cat(re) end - gitdir = string.format("%s/%s/.git", info.root, src.working) - local git = string.format("GIT_DIR=%s ".. - "git archive --format=tar --prefix=%s/ refs/heads/%s", - e2lib.shquote(gitdir), e2lib.shquote(sourcename), - e2lib.shquote(src.branch)) - local tar = string.format("tar -C %s -xf -", e2lib.shquote(buildpath)) - rc, re = e2lib.callcmd_pipe({git, tar}) + + work_tree = e2lib.join(buildpath, sourcename) + rc, re = e2lib.mkdir_recursive(work_tree) + if not rc then + return e:cat(re) + end + + argv = generic_git.git_new_argv(gitdir, work_tree, "checkout") + table.insert(argv, "refs/heads/" .. src.branch) + table.insert(argv, "--") + + rc, re = generic_git.git(argv) if not rc then return false, e:cat(re) end elseif sourceset == "tag" or (sourceset == "lazytag" and src.tag ~= "^") then + local argv, work_tree + rc, re = git.git_commit_id(info, sourcename, sourceset) if not rc then return false, e:cat(re) end - gitdir = string.format("%s/%s/.git", info.root, src.working) - local git = string.format("GIT_DIR=%s ".. - "git archive --format=tar --prefix=%s/ refs/tags/%s", - e2lib.shquote(gitdir), e2lib.shquote(sourcename), e2lib.shquote(src.tag)) - local tar = string.format("tar -C %s -xf -", e2lib.shquote(buildpath)) - rc, re = e2lib.callcmd_pipe({git, tar}) + + work_tree = e2lib.join(buildpath, sourcename) + rc, re = e2lib.mkdir_recursive(work_tree) + if not rc then + return e:cat(re) + end + + argv = generic_git.git_new_argv(gitdir, work_tree, "checkout") + table.insert(argv, "refs/tags/" .. src.tag) + table.insert(argv, "--") + + rc, re = generic_git.git(argv) if not rc then return false, e:cat(re) end elseif sourceset == "working-copy" then - -- warn for empty working-copy - local working = string.format("%s/%s", info.root, src.working) - local empty = true - for f, re in e2lib.directory(working, false) do + local working, destdir, empty + + working = e2lib.join(info.root, src.working) + destdir = e2lib.join(buildpath, sourcename) + + rc, re = e2lib.mkdir_recursive(destdir) + if not rc then + return false, e:cat(re) + end + + empty = true + for f, re in e2lib.directory(working, true) do if not f then return false, e:cat(re) end - empty = false - break + if string.sub(f, 1, 1) ~= "." then + empty = false + end + + if f ~= ".git" then + rc, re = e2lib.cp(e2lib.join(working, f), destdir, true) + if not rc then + return false, e:cat(re) + end + end end + if empty then e2lib.warnf("WOTHER", "in result: %s", src.name) e2lib.warnf("WOTHER", "working copy seems empty") end - local dir = string.format("%s/%s", buildpath, sourcename) - local rc, re = e2lib.mkdir_recursive(dir) - if not rc then - return false, re - end - local tar, re = tools.get_tool("tar") - if not tar then - return false, e:cat(re) - end - local tarflags, re = tools.get_tool_flags("tar") - if not tarflags then - return false, e:cat(re) - end - - tarflags = table.concat(tarflags, " ") - - local cmd1 = string.format("%s %s -c -C %s/%s --exclude '.git' .", - e2lib.shquote(tar), tarflags, e2lib.shquote(info.root), - e2lib.shquote(src.working)) - local cmd2 = string.format("%s %s -x -C %s/%s", e2lib.shquote(tar), - tarflags, e2lib.shquote(buildpath), e2lib.shquote(sourcename)) - rc, re = e2lib.callcmd_pipe({ cmd1, cmd2 }) - if not rc then - return false, e:cat(re) - end else return false, err.new("invalid sourceset: %s", sourceset) end - return true, nil + return true end --- check if a working copy for a git repository is available