From a55a4a2dd465e7a2bd0abd30f13626f901414b3a Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Tue, 7 Aug 2012 09:32:34 +0200 Subject: [PATCH] Change generic_git module to a more encapsulated type Signed-off-by: Tobias Ulmer --- generic/generic_git.lua | 57 +++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/generic/generic_git.lua b/generic/generic_git.lua index d8a21ef..aec79a4 100644 --- a/generic/generic_git.lua +++ b/generic/generic_git.lua @@ -28,7 +28,7 @@ --- functions with '1' postfix take url strings as parameter. the others -- take server / location -module("generic_git", package.seeall) +local generic_git = {} local cache = require("cache") --- clone a git repository @@ -37,7 +37,7 @@ local cache = require("cache") -- @param skip_checkout bool: pass -n to git clone? -- @return true on success, false on error -- @return nil, an error object on failure -function git_clone_url1(surl, location, destdir, skip_checkout) +function generic_git.git_clone_url1(surl, location, destdir, skip_checkout) if (not surl) or (not location) or (not destdir) then e2lib.abort("git_clone_url1(): missing parameter") end @@ -48,7 +48,7 @@ function git_clone_url1(surl, location, destdir, skip_checkout) if not u then return false, e:cat(re) end - local src, re = git_url1(u) + local src, re = generic_git.git_url1(u) if not src then return false, e:cat(re) end @@ -72,7 +72,7 @@ end -- @param start_point string: where to start the branch -- @return bool -- @return nil, an error object on failure -function git_branch_new1(gitwc, track, branch, start_point) +function generic_git.git_branch_new1(gitwc, track, branch, start_point) -- git branch [--track|--no-track] local f_track = nil if track == true then @@ -95,7 +95,7 @@ end -- @param branch name of the branch to checkout -- @return bool -- @return an error object on failure -function git_checkout1(gitwc, branch) +function generic_git.git_checkout1(gitwc, branch) e2lib.log(3, string.format("checking out branch: %s", branch)) -- git checkout local cmd = string.format("cd %s && git checkout %s", e2lib.shquote(gitwc), @@ -112,7 +112,7 @@ end -- @param ref string: a reference, according to the git manual -- @return string: the commit id matching the ref parameter, or nil on error -- @return an error object on failure -function git_rev_list1(gitdir, ref) +function generic_git.git_rev_list1(gitdir, ref) e2lib.log(4, string.format("git_rev_list(): %s %s", tostring(gitdir), tostring(ref))) local e = new_error("git rev-list failed") @@ -145,7 +145,7 @@ end -- @param rurl string: remote url -- @return bool -- @return an error object on failure -function git_init_db1(rurl) +function generic_git.git_init_db1(rurl) if (not rurl) then e2lib.abort("git_init_db1(): missing parameter") end @@ -183,7 +183,7 @@ end -- @param refspec string: a git refspec -- @return bool -- @return an error object on failure -function git_push1(gitdir, rurl, refspec) +function generic_git.git_push1(gitdir, rurl, refspec) if (not rurl) or (not gitdir) or (not refspec) then e2lib.abort("git_push1(): missing parameter") end @@ -193,7 +193,7 @@ function git_push1(gitdir, rurl, refspec) if not u then return false, e:cat(re) end - local remote_git_url, re = git_url1(u) + local remote_git_url, re = generic_git.git_url1(u) if not remote_git_url then return false, e:cat(re) end @@ -213,7 +213,7 @@ end -- @param name string: remote name -- @return bool -- @return an error object on failure -function git_remote_add1(lurl, rurl, name) +function generic_git.git_remote_add1(lurl, rurl, name) if (not lurl) or (not rurl) or (not name) then e2lib.abort("missing parameter") end @@ -227,7 +227,7 @@ function git_remote_add1(lurl, rurl, name) if not rrepo then return false, e:cat(re) end - local giturl, re = git_url1(rrepo) + local giturl, re = generic_git.git_url1(rrepo) if not giturl then return false, e:cat(re) end @@ -245,7 +245,7 @@ end -- @param u url table -- @return string: the git url -- @return an error object on failure -function git_url1(u) +function generic_git.git_url1(u) e2lib.log(4, string.format("git_url(%s)", tostring(u))) local giturl if u.transport == "ssh" or u.transport == "scp" or @@ -267,7 +267,7 @@ end -- @param skip_checkout bool: pass -n to git clone? -- @return bool -- @return an error object on failure -function git_clone_from_server(c, server, location, destdir, +function generic_git.git_clone_from_server(c, server, location, destdir, skip_checkout) local rc, re local e = new_error("cloning git repository") @@ -275,7 +275,7 @@ function git_clone_from_server(c, server, location, destdir, if not surl then return false, e:cat(re) end - local rc, re = git_clone_url1(surl, "", destdir, skip_checkout) + local rc, re = generic_git.git_clone_url1(surl, "", destdir, skip_checkout) if not rc then return false, re end @@ -288,14 +288,14 @@ end -- @param location string: location -- @return bool -- @return an error object on failure -function git_init_db(c, server, location) +function generic_git.git_init_db(c, server, location) local rc, re local e = new_error("initializing git repository") local rurl, re = cache.remote_url(c, server, location) if not rurl then return false, e:cat(re) end - local rc, re = git_init_db1(rurl) + local rc, re = generic_git.git_init_db1(rurl) if not rc then return false, re end @@ -310,14 +310,14 @@ end -- @param refspec string: a git refspec -- @return bool -- @return an error object on failure -function git_push(c, gitdir, server, location, refspec) +function generic_git.git_push(c, gitdir, server, location, refspec) local rc, re local e = new_error("git push failed") local rurl, re = cache.remote_url(c, server, location) if not rurl then return false, e:cat(re) end - return git_push1(gitdir, rurl, refspec) + return generic_git.git_push1(gitdir, rurl, refspec) end --- do a git config query @@ -325,7 +325,7 @@ end -- @param query string: query to pass to git config -- @return string: the value printed to stdout by git config, or nil -- @return an error object on failure -function git_config(gitdir, query) +function generic_git.git_config(gitdir, query) local rc, re local e = new_error("running git config") local tmpfile = e2lib.mktempfile() @@ -349,7 +349,7 @@ end -- @param args string: args to pass to git add -- @return bool -- @return an error object on failure -function git_add(gitdir, args) +function generic_git.git_add(gitdir, args) local rc, re local e = new_error("running git add") if not gitdir then @@ -369,7 +369,7 @@ end -- @param args string: args to pass to git add -- @return bool -- @return an error object on failure -function git_commit(gitdir, args) +function generic_git.git_commit(gitdir, args) local rc, re local e = new_error("git commit failed") return e2lib.git("commit", gitdir, args) @@ -380,7 +380,7 @@ end -- @param tag string: tag name -- @return bool, or nil on error -- @return an error object on failure -function verify_remote_tag(gitdir, tag) +function generic_git.verify_remote_tag(gitdir, tag) e2lib.logf(4, "generic_git.verify_remote_tag(%s, %s)", tostring(gitdir), tostring(tag)) local e = new_error("verifying remote tag") @@ -397,11 +397,11 @@ function verify_remote_tag(gitdir, tag) end -- store commit ids for use in the error message, if any - local lrev = git_rev_list1(gitdir, tag) + local lrev = generic_git.git_rev_list1(gitdir, tag) if not lrev then return nil, e:cat(re) end - local rrev = git_rev_list1(gitdir, rtag) + local rrev = generic_git.git_rev_list1(gitdir, rtag) if not rrev then return nil, e:cat(re) end @@ -431,7 +431,7 @@ end -- @param gitwc string: path to a git working tree (default: .) -- @return bool, or nil on error -- @return an error object on failure -function verify_clean_repository(gitwc) +function generic_git.verify_clean_repository(gitwc) e2lib.logf(4, "generic_git.verify_clean_repository(%s)", tostring(gitwc)) gitwc = gitwc or "." local e = new_error("verifying that repository is clean") @@ -501,7 +501,7 @@ end -- @param tag string: tag name -- @return bool, or nil on error -- @return an error object on failure -function verify_head_match_tag(gitwc, verify_tag) +function generic_git.verify_head_match_tag(gitwc, verify_tag) e2lib.logf(4, "generic_git.verify_head_match_tag(%s, %s)", tostring(gitwc), tostring(verify_tag)) assert(verify_tag) @@ -533,7 +533,7 @@ function verify_head_match_tag(gitwc, verify_tag) return true end -function sourceset2ref(sourceset, branch, tag) +function generic_git.sourceset2ref(sourceset, branch, tag) if sourceset == "branch" or (sourceset == "lazytag" and tag == "^") then return string.format("refs/heads/%s", branch) @@ -553,7 +553,7 @@ end -- @param flags: table of flags -- @return bool -- @return nil, or an error string on error -function new_repository(c, lserver, llocation, rserver, rlocation, flags) +function generic_git.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) @@ -598,3 +598,4 @@ function new_repository(c, lserver, llocation, rserver, rlocation, flags) return true, nil end +return generic_git -- 2.39.5