Permalink
Browse files

Fix ownership issues. Update test code.

  • Loading branch information...
Neopallium committed Apr 3, 2011
1 parent 8fcc9f3 commit a5b54bd6c9679b09fdcc83ec65077905b61ec05f
Showing with 40 additions and 54 deletions.
  1. +1 −1 src/commit.nobj.lua
  2. +3 −3 src/database.nobj.lua
  3. +0 −7 src/odb_object.nobj.lua
  4. +1 −1 src/repository.nobj.lua
  5. +1 −1 src/tree_entry.nobj.lua
  6. +34 −41 tests/test_rep.lua
View
@@ -85,7 +85,7 @@ typedef git_commit Commit;
c_method_call "const Signature *" "git_commit_author" {}
},
method "tree" {
- c_call "GitError" "git_commit_tree" { "Tree *", "&tree>1", "Commit *", "this" }
+ c_call "GitError" "git_commit_tree" { "!Tree *", "&tree>1", "Commit *", "this" }
},
method "parentcount" {
c_method_call "unsigned int" "git_commit_parentcount" {}
View
@@ -54,17 +54,17 @@ typedef git_odb Database;
--]=]
method "read" {
c_call "GitError" "git_odb_read"
- { "OdbObject *", "&out>1", "Database *", "this", "OID", "&id"},
+ { "!OdbObject *", "&out>1", "Database *", "this", "OID", "&id"},
},
method "read_header" {
c_call { "GitError", "err>3" } "git_odb_read_header"
{ "size_t", "&size>1", "git_otype", "&(otype)", "Database *", "this", "OID", "&id"},
c_call { "const char *", "type>2" } "git_object_type2string" { "git_otype", "otype" },
},
method "write" {
- c_call { "git_otype", "(otype)" } "git_object_string2type" { "const char *", "type<4" },
+ c_call { "git_otype", "(otype)" } "git_object_string2type" { "const char *", "type<3" },
c_call "GitError" "git_odb_write"
- { "OID", "&id<2", "Database *", "this<1", "const char *", "data", "size_t", "#data",
+ { "OID", "&id>1", "Database *", "this<1", "const char *", "data<2", "size_t", "#data",
"git_otype", "otype"},
},
method "exists" {
View
@@ -39,12 +39,5 @@ typedef git_odb_object OdbObject;
method "id" {
c_method_call { "OID", "*id" } "git_odb_object_id" {},
},
- method "hash" {
- c_method_call { "const void *", "(data)" } "git_odb_object_data" {},
- c_method_call { "size_t", "(size)" } "git_odb_object_size" {},
- c_method_call { "git_otype", "(otype)" } "git_odb_object_type" {},
- c_call { "GitError", "err>2" } "git_odb_hash"
- { "OID", "&id>1", "const void *", "data", "size_t", "size", "git_otype", "otype" },
- },
}
View
@@ -48,7 +48,7 @@ typedef git_repository Repository;
},
method "index" {
c_call { "GitError", "err" } "git_repository_index"
- { "Index *", "&index>1", "Repository *", "this" },
+ { "!Index *", "&index>1", "Repository *", "this" },
},
}
View
@@ -34,7 +34,7 @@ typedef git_tree_entry TreeEntry;
},
method "object" {
c_call "GitError" "git_tree_entry_2object"
- { "Object *", "&obj>1", "Repository *", "repo", "TreeEntry *", "this" }
+ { "!Object *", "&obj>1", "Repository *", "repo", "TreeEntry *", "this" }
},
}
View
@@ -23,46 +23,43 @@ print("dump OID interface")
print(dbg_dump(oid))
print('convert OID value to string = <' .. tostring(oid) .. '>')
+local db = rep:database()
+print("dump Database interface")
+print(dbg_dump(db))
+
+print()
print('test writing to the object database:')
-local raw_obj = git2.RawObject('blob',"any ol content will do")
+local oid, err = db:write("any ol content will do", 'blob')
+print(oid, err)
+
+print("read written object out of the database.")
+local odb_obj = db:read(oid)
print()
-print("dump RawObject interface")
-print(dbg_dump(raw_obj))
-local function dump_rawobj(obj)
- print('dump RawObject:', obj)
- if obj == nil then
+print("dump OdbObject interface")
+print(dbg_dump(odb_obj))
+local function dump_odb_obj(obj)
+ -- check obj type
+ if obj == nil or not tostring(obj):match('^OdbObject: ') then
+ print('dump invalid OdbObject: ', obj)
return
end
- print('hash = ', obj:hash())
+ print('dump OdbObject:', obj)
+ print('oid = ', obj:id())
print('data = "' .. tostring(obj:data()) .. '"')
- print('len = ', obj:len())
+ print('size = ', obj:size())
print('type = ', obj:type())
end
print()
-print("dump RawObject info:")
-dump_rawobj(raw_obj)
-
-print()
-print("test closing of RawObject:")
-raw_obj:close()
-dump_rawobj(raw_obj)
-
-print()
-print("test setting data of RawObject:")
-raw_obj:set_data("any ol content will do")
-dump_rawobj(raw_obj)
-
-local db = rep:database()
-print("dump Database interface")
-print(dbg_dump(db))
+print("dump OdbObject info:")
+dump_odb_obj(odb_obj)
print()
-print("test writing RawObject to database:")
-local oid, err = db:write(raw_obj)
-print(oid, err)
+print("test closing of OdbObject:")
+odb_obj:close()
+dump_odb_obj(odb_obj)
print()
-print("test reading RawObjects from database:")
+print("test reading OdbObjects from database:")
local object_ids = {
{'tree', "31f3d5703ce27f0b63c3eb0d829abdc95b51deae"},
{'commit', "d5a93c463d4cca0068750eb6af7b4b54eea8599b"},
@@ -71,21 +68,18 @@ local object_ids = {
}
for _,obj in ipairs(object_ids) do
local oid = git2.OID.str(obj[2])
- local raw_obj, err = db:read(oid)
+ local odb_obj, err = db:read(oid)
print()
- print(raw_obj, err)
- dump_rawobj(raw_obj)
+ print(odb_obj, err)
+ dump_odb_obj(odb_obj)
end
local commit_id = git2.OID.str("d5a93c463d4cca0068750eb6af7b4b54eea8599b")
print()
print("test parsing a commit object: ", commit_id)
-local commit2, err = rep:lookup(commit_id, 'commit')
-print(commit2, err)
local commit1, err = git2.Commit.lookup(rep, commit_id)
print(commit1, err)
-assert(commit1 == commit2)
print("dump Commit interface")
print(dbg_dump(commit1))
local function dump_signature(pre, sig)
@@ -106,7 +100,7 @@ local function dump_tree_entry(entry)
print('tree_entry.id = ', entry:id())
print('tree_entry.name = ', entry:name())
print('tree_entry.attributes = ', string.format('0x%08X', entry:attributes()))
- local obj = entry:object()
+ local obj = entry:object(rep)
print('tree_entry.object = ', obj)
if obj:type() == 'blob' then
dump_blob(obj)
@@ -187,14 +181,14 @@ print(dbg_dump(revwalk))
print('sorting:', revwalk:sorting(revwalk.SORT_TOPOLOGICAL + revwalk.SORT_REVERSE))
local head_id = git2.OID.str("5c697d74eb692d650799ca1b0a10254d7130953d")
local head = assert(git2.Commit.lookup(rep, head_id))
-print('push:', revwalk:push(head))
+print('push:', revwalk:push(head_id))
assert(revwalk:repository() == rep)
-local commit = revwalk:next()
-while (commit ~= nil) do
- dump_commit(commit)
+local commit_oid = revwalk:next()
+while (commit_oid ~= nil) do
+ dump_commit(assert(git2.Commit.lookup(rep, commit_oid)))
-- get next commit
- commit = revwalk:next()
+ commit_oid = revwalk:next()
end
local tag_id = git2.OID.str('82dfe36284d77b608ccc9d96e0ffa5782cb7c835')
@@ -218,7 +212,6 @@ revwalk = nil
head = nil
commit = nil
commit1 = nil
-commit2 = nil
index = nil
rep = nil
db = nil

0 comments on commit a5b54bd

Please sign in to comment.