summaryrefslogtreecommitdiff
path: root/lib/gall/repository.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gall/repository.lua')
-rw-r--r--lib/gall/repository.lua61
1 files changed, 26 insertions, 35 deletions
diff --git a/lib/gall/repository.lua b/lib/gall/repository.lua
index 70381cb..38ed398 100644
--- a/lib/gall/repository.lua
+++ b/lib/gall/repository.lua
@@ -84,14 +84,7 @@ end
if ll.git2 then
function repomethod:get_ref(ref)
- local rref = ll.git2.Reference.lookup(self.git2.repo, ref)
- if not rref then
- return nil
- end
- if rref:type() ~= ll.git2.REF_OID then
- return nil
- end
- return tostring(rref:oid())
+ return ll.git2.lookup_sha_from_ref(self.git2.repo, ref)
end
end
@@ -153,15 +146,9 @@ function repomethod:normalise(sha)
else
local fullsha
if ll.git2 then
- local refobj = ll.git2.Reference.lookup(self.git2.repo, sha)
+ local refobj = ll.git2.lookup_sha_from_ref(self.git2.repo, sha)
if refobj then
- if refobj:type() == ll.git2.REF_SYMBOLIC then
- refobj = ll.git2.Reference.lookup(self.git2.repo,
- refobj:target())
- end
- if refobj:type() == ll.git2.REF_OID then
- fullsha = tostring(refobj:oid())
- end
+ fullsha = refobj
end
end
if not fullsha then
@@ -228,16 +215,16 @@ if ll.git2 then
commitish_2 = commitish_2.content.object
end
end)
- local oid_1 = ll.git2.OID.hex(commitish_1.sha)
- local oid_2 = ll.git2.OID.hex(commitish_2.sha)
- local oid_base, err = ll.git2.merge.base(self.git2.repo, oid_1, oid_2)
+ local oid_base, err = ll.git2.merge_base(self.git2.repo,
+ commitish_1.sha,
+ commitish_2.sha)
if not oid_base then
if tostring(err) == "ENOTFOUND" then
return true
end
return nil, err
end
- return tostring(oid_base), err
+ return oid_base, err
end
end
@@ -282,17 +269,18 @@ end
if ll.git2 then
function repomethod:symbolic_ref(name, toref)
- local symref = ll.git2.Reference.lookup(self.git2.repo, name)
- if not symref then
- return nil, "No such ref: " .. tostring(toref)
- end
- if symref:type() ~= ll.git2.REF_SYMBOLIC then
- return false
- end
if toref then
- symref:set_target(toref)
+ -- Set the ref...
+ local ok, err = ll.git2.set_symbolic_ref(self.git2.repo, name, toref)
+ if not ok then
+ return nil, err
+ end
end
- return true, symref:target()
+ local symref, err = ll.git2.lookup_symbolic_ref(self.git2.repo, name)
+ if not symref then
+ return nil, "No such ref: " .. tostring(toref) .. " (" .. err .. ")"
+ end
+ return true, symref
end
end
@@ -305,6 +293,8 @@ function repomethod:config(confname, value)
end
end
+--[[
+-- TODO: Add config support to git2.c and convert this
if ll.git2 then
local old_config = repomethod.config
function repomethod:config(confname, value)
@@ -325,6 +315,7 @@ if ll.git2 then
end
end
end
+]]
local repomt = {
__index = repomethod,
@@ -350,14 +341,12 @@ local function _new(path)
local symref
if ll.git2 then
- local git2, msg = ll.git2.Repository(repopath)
+ local git2, msg = ll.git2.open_repo(repopath)
if not git2 then
return nil, "Unable to find Git repository at " .. path
end
- local odb = git2:odb()
- retrepo.git2 = { repo = git2, odb = odb }
- symref = ll.git2.Reference.lookup(git2, "HEAD")
- symref = symref:target()
+ retrepo.git2 = { repo = git2 }
+ symref = ll.git2.lookup_symbolic_ref(git2, "HEAD")
else
ok, symref = ll.symbolic_ref { "-q", "HEAD", stderr=true, repo=repopath }
if ok ~= 0 then
@@ -370,6 +359,8 @@ local function _new(path)
retrepo.work = workpath
retrepo.HEAD = symref
+--[[
+-- This seems redundant
if ll.git2 then
local git2, msg = ll.git2.Repository(retrepo.path)
if not git2 then
@@ -378,7 +369,7 @@ local function _new(path)
local odb = git2:odb()
retrepo.git2 = { repo = git2, odb = odb }
end
-
+--]]
return setmetatable(retrepo, repomt)
end