From 5d2fa3cf29bebe58675720f7fdd3ebd0dbe069ed Mon Sep 17 00:00:00 2001 From: Gordon Hecker Date: Thu, 11 Feb 2010 14:33:43 +0100 Subject: [PATCH] cleanup: move generic code to generic_git module, fix a call to generic_git.new_repository() Signed-off-by: Gordon Hecker --- generic/generic_git.lua | 54 +++++++++++++++++++++++++++++++++++++++++ local/git.lua | 54 ----------------------------------------- local/new-source.lua | 2 +- 3 files changed, 55 insertions(+), 55 deletions(-) diff --git a/generic/generic_git.lua b/generic/generic_git.lua index 6a06dc3..66d2aac 100644 --- a/generic/generic_git.lua +++ b/generic/generic_git.lua @@ -541,3 +541,57 @@ function sourceset2ref(sourceset, branch, tag) return nil, "invalid sourceset" end +--- create a new git source repository +-- @param c cache table +-- @param lserver string: local server +-- @param llocation string: working copy location on local server +-- @param rserver string: remote server +-- @param rlocation string: repository location on remote server +-- @param flags: table of flags +-- @return bool +-- @return nil, or an error string on error +function new_repository(c, lserver, llocation, rserver, rlocation, flags) + local rc, re + local e = new_error("setting up new git repository failed") + local lserver_url, re = cache.remote_url(c, lserver, llocation) + if not lserver_url then + return false, e:cat(re) + end + local lurl, re = url.parse(lserver_url) + if not lurl then + return false, e:cat(re) + end + local rc = e2lib.mkdir(string.format("/%s", lurl.path), "-p") + if not rc then + return false, e:cat("can't create path to local git repository") + end + rc = generic_git.git_init_db(c, lserver, llocation) + if not rc then + return false, e:cat("can't initialize local git repository") + end + rc = git.git_remote_add(c, lserver, llocation, "origin", + rserver, rlocation) + if not rc then + return false, e:cat("git remote add failed") + end + rc = e2lib.chdir("/"..lurl.path) + if not rc then + return false, e:cat(re) + end + local targs = { + string.format("'branch.master.remote' 'origin'"), + string.format("'branch.master.merge' 'refs/heads/master'"), + } + for _,args in ipairs(targs) do + rc, re = e2lib.git(".", "config", args) + if not rc then + return false, e:cat(re) + end + end + rc = generic_git.git_init_db(c, rserver, rlocation) + if not rc then + return false, e:cat("can't initialize remote git repository") + end + return true, nil +end + diff --git a/local/git.lua b/local/git.lua index bb96888..fe05748 100644 --- a/local/git.lua +++ b/local/git.lua @@ -540,60 +540,6 @@ function git.git_remote_add(c, lserver, llocation, name, rserver, rlocation) return true, nil end ---- create a new git source repository --- @param c cache table --- @param lserver string: local server --- @param llocation string: working copy location on local server --- @param rserver string: remote server --- @param rlocation string: repository location on remote server --- @param flags: table of flags --- @return bool --- @return nil, or an error string on error -function git.new_git_source(c, lserver, llocation, rserver, rlocation, flags) - local rc, re - local e = new_error("setting up new git repository failed") - local lserver_url, re = cache.remote_url(c, lserver, llocation) - if not lserver_url then - return false, e:cat(re) - end - local lurl, re = url.parse(lserver_url) - if not lurl then - return false, e:cat(re) - end - local rc = e2lib.mkdir(string.format("/%s", lurl.path), "-p") - if not rc then - return false, e:cat("can't create path to local git repository") - end - rc = generic_git.git_init_db(c, lserver, llocation) - if not rc then - return false, e:cat("can't initialize local git repository") - end - rc = git.git_remote_add(c, lserver, llocation, "origin", - rserver, rlocation) - if not rc then - return false, e:cat("git remote add failed") - end - rc = e2lib.chdir("/"..lurl.path) - if not rc then - return false, e:cat(re) - end - local targs = { - string.format("'branch.master.remote' 'origin'"), - string.format("'branch.master.merge' 'refs/heads/master'"), - } - for _,args in ipairs(targs) do - rc, re = e2lib.git(".", "config", args) - if not rc then - return false, e:cat(re) - end - end - rc = generic_git.git_init_db(c, rserver, rlocation) - if not rc then - return false, e:cat("can't initialize remote git repository") - end - return true, nil -end - --- create a table of lines for display -- @param info the info structure -- @param sourcename string diff --git a/local/new-source.lua b/local/new-source.lua index cbb1c46..574115a 100644 --- a/local/new-source.lua +++ b/local/new-source.lua @@ -259,7 +259,7 @@ if opts.git then local lserver = info.root_server_name local llocation = string.format("in/%s/.git", name) local flags = {} - local rc, re = e2scm["git"].new_git_source(info.cache, lserver, llocation, + local rc, re = generic_git.new_repository(info.cache, lserver, llocation, rserver, rlocation, flags) if not rc then e2lib.abort(re) -- 2.39.5