summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert G. Jakabosky <bobby@sharedrealm.com>2012-05-25 11:18:05 -0700
committerRobert G. Jakabosky <bobby@sharedrealm.com>2012-05-25 11:18:05 -0700
commitdccaacb3ba8ff3cc2cd6f2c58372aa2bf27bf190 (patch)
treeafe1fa1f08855e9d215c8180df52b72ce45fe56e
parent537df887b654de248d536beaf3e59886d3e9bc3b (diff)
downloadluagit2-dccaacb3ba8ff3cc2cd6f2c58372aa2bf27bf190.tar.gz
Test reference counting of custom backends.
-rw-r--r--src/odb_backend.nobj.lua1
-rw-r--r--tests/test_backend.lua12
2 files changed, 12 insertions, 1 deletions
diff --git a/src/odb_backend.nobj.lua b/src/odb_backend.nobj.lua
index cd5295b..57b6912 100644
--- a/src/odb_backend.nobj.lua
+++ b/src/odb_backend.nobj.lua
@@ -40,6 +40,7 @@ static void ODBBackend_ref(ODBBackend *backend) {
static void ODBBackend_unref(ODBBackend *backend) {
lua_State *L = backend->L;
+ assert(backend->ref_count > 0);
if((--backend->ref_count) == 0) {
luaL_unref(L, LUA_REGISTRYINDEX, backend->read);
luaL_unref(L, LUA_REGISTRYINDEX, backend->read_prefix);
diff --git a/tests/test_backend.lua b/tests/test_backend.lua
index ba0633a..bb17ed9 100644
--- a/tests/test_backend.lua
+++ b/tests/test_backend.lua
@@ -18,6 +18,11 @@ local function dump_obj(obj)
end
print('id = ', obj:id())
print('type = ', obj:type())
+ local data = obj:data()
+ print('data = ', data)
+ if data then
+ print('hash = ', git2.ODB.hash(data,git2.Object.string2type(obj:type())))
+ end
end
-- create odb
@@ -93,6 +98,8 @@ end,
local backend = git2.ODBBackend(cbs)
print('add backend:', assert(db:add_backend(backend, 0)))
+backend = nil
+collectgarbage"collect"
print("test writing test blob to odb:")
local oid, err = db:write("any ol content will do", 'blob')
@@ -127,6 +134,8 @@ db = rep:odb()
print("=============================================== repo db=", db)
backend = git2.ODBBackend(cbs)
print("add backend repository's odb:", assert(db:add_backend(backend, 0)))
+backend = nil
+collectgarbage"collect"
print()
print("try reading objects from repository:")
@@ -138,7 +147,8 @@ local object_ids = {
}
for _,obj in ipairs(object_ids) do
local oid = git2.OID.hex(obj[2])
- local obj, err = rep:lookup(oid, obj[1])
+ --local obj, err = rep:lookup(oid, obj[1])
+ local obj, err = db:read(oid)
print('read', obj, err)
print()
end