diff options
author | Robert G. Jakabosky <bobby@sharedrealm.com> | 2011-01-07 07:12:52 -0800 |
---|---|---|
committer | Robert G. Jakabosky <bobby@sharedrealm.com> | 2011-01-07 07:12:52 -0800 |
commit | 4f690f7de90fd7474de05a51d404d3ab0ec119fa (patch) | |
tree | 71bf82b0d6114d3e538e5e77ecd95507995ae8b7 | |
parent | 42f8736a3145c7993cab83c1af02d38428efde72 (diff) | |
download | luagit2-4f690f7de90fd7474de05a51d404d3ab0ec119fa.tar.gz |
Fixed bug with RawObject.
-rw-r--r-- | database.nobj.lua | 18 | ||||
-rw-r--r-- | rawobject.nobj.lua | 37 | ||||
-rw-r--r-- | test_rep.lua | 40 |
3 files changed, 69 insertions, 26 deletions
diff --git a/database.nobj.lua b/database.nobj.lua index 0626d7f..aa486a8 100644 --- a/database.nobj.lua +++ b/database.nobj.lua @@ -42,26 +42,32 @@ object "Database" { -- TODO: add_backend method "read" { var_in{"OID", "id"}, - var_out{"RawObject", "obj"}, + var_out{"RawObject *", "obj"}, var_out{"GitError", "err"}, c_source [[ - ${err} = git_odb_read(&(${obj}.raw), ${this}, &(${id})); + RawObject raw_obj; + ${obj} = &(raw_obj); + ${err} = git_odb_read(&(raw_obj.raw), ${this}, &(${id})); ]], }, method "read_header" { var_in{"OID", "id"}, - var_out{"RawObject", "obj"}, + var_out{"RawObject *", "obj"}, var_out{"GitError", "err"}, c_source [[ - ${err} = git_odb_read_header(&(${obj}.raw), ${this}, &(${id})); + RawObject raw_obj; + ${obj} = &(raw_obj); + ${err} = git_odb_read_header(&(raw_obj.raw), ${this}, &(${id})); ]], }, method "write" { var_in{"OID", "id"}, - var_in{"RawObject", "obj"}, + var_in{"RawObject *", "obj"}, var_out{"GitError", "err"}, c_source [[ - ${err} = git_odb_write(&(${id}), ${this}, &(${obj}.raw)); + RawObject raw_obj; + ${obj} = &(raw_obj); + ${err} = git_odb_write(&(${id}), ${this}, &(raw_obj.raw)); ]], }, method "exists" { diff --git a/rawobject.nobj.lua b/rawobject.nobj.lua index d7ac0b4..d273097 100644 --- a/rawobject.nobj.lua +++ b/rawobject.nobj.lua @@ -26,60 +26,65 @@ typedef struct RawObject { ]] object "RawObject" { - userdata_type = 'simple', - default = '{ .raw = { .data = NULL, .len = 0, .type = GIT_OBJ_BAD }, .ref = LUA_NOREF }', + userdata_type = 'embed', + default = 'NULL', constructor { var_in{"OType", "type"}, var_in{"const char *", "data"}, c_source [[ - ${this}.raw.data = (void *)${data}; - ${this}.raw.len = ${data}_len; - ${this}.raw.type = ${type}; + RawObject obj; + ${this} = &(obj); + obj.raw.data = (void *)${data}; + obj.raw.len = ${data}_len; + obj.raw.type = ${type}; if(${data}) { /* keep a reference to the Lua string. */ lua_pushvalue(L, ${data::idx}); - ${this}.ref = luaL_ref(L, LUA_REGISTRYINDEX); + obj.ref = luaL_ref(L, LUA_REGISTRYINDEX); } else { - ${this}.ref = LUA_NOREF; + obj.ref = LUA_NOREF; } ]], }, destructor "close" { c_source [[ - if(${this}.ref == LUA_NOREF) { - if(${this}.raw.data != NULL) { - git_rawobj_close(&(${this}.raw)); + if(${this}->ref == LUA_NOREF) { + if(${this}->raw.data != NULL) { + git_rawobj_close(&(${this}->raw)); } } else { /* this raw object was pointing to a Lua string, release our reference to it. */ - luaL_unref(L, LUA_REGISTRYINDEX, ${this}.ref); + luaL_unref(L, LUA_REGISTRYINDEX, ${this}->ref); + ${this}->ref = LUA_NOREF; } + ${this}->raw.data = NULL; + ${this}->raw.len = 0; ]], }, method "data" { var_out{"const char *", "data", has_length = true}, c_source [[ - ${data} = ${this}.raw.data; - ${data}_len = ${this}.raw.len; + ${data} = ${this}->raw.data; + ${data}_len = ${this}->raw.len; ]], }, method "len" { var_out{"size_t", "len"}, c_source [[ - ${len} = ${this}.raw.len; + ${len} = ${this}->raw.len; ]], }, method "type" { var_out{"OType", "type"}, c_source [[ - ${type} = ${this}.raw.type; + ${type} = ${this}->raw.type; ]], }, method "hash" { var_out{"OID", "id"}, var_out{"GitError", "err"}, c_source [[ - ${err} = git_rawobj_hash(&(${id}), &(${this}.raw)); + ${err} = git_rawobj_hash(&(${id}), &(${this}->raw)); ]], }, } diff --git a/test_rep.lua b/test_rep.lua index 959570b..6fb63c8 100644 --- a/test_rep.lua +++ b/test_rep.lua @@ -1,9 +1,9 @@ #!/usr/bin/env lua +local build_dir = arg[1] +local git_path = arg[2] or "./test_rep/.git" -- Make it easier to test -local src_dir, build_dir = ... -if ( src_dir ) then - package.path = src_dir .. "?.lua;" .. package.path +if ( build_dir ) then package.cpath = build_dir .. "?.so;" .. package.cpath end @@ -13,7 +13,39 @@ require"utils" print("dump git2 interface") print(dbg_dump(git2)) -local rep = assert(git2.Repository.open("./test_rep/.git")) +local rep = assert(git2.Repository.open(git_path)) + +print("dump Repository interface") +print(dbg_dump(rep)) + +local db = rep:database() +print("dump Database interface") +print(dbg_dump(db)) + +local index = rep:index() +print("dump Index interface") +print(dbg_dump(index)) + +local oid = git2.OID.str("d5a93c463d4cca0068750eb6af7b4b54eea8599b") +print("dump OID interface") +print(dbg_dump(oid)) +print('convert OID value to string = <' .. tostring(oid) .. '>') + +print('test writing to the object database:') +local raw_obj = git2.RawObject(git2.OType('blob'),"any ol content will do") +print("dump RawObject interface") +print(dbg_dump(raw_obj)) +print("dump RawObject info:") +print('hash = ', raw_obj:hash()) +print('data = "' .. tostring(raw_obj:data()) .. '"') +print('len = ', raw_obj:len()) +print('type = ', raw_obj:type()) +print("test closing of RawObject:") +raw_obj:close() +print('hash = ', raw_obj:hash()) +print('data = "' .. tostring(raw_obj:data()) .. '"') +print('len = ', raw_obj:len()) +print('type = ', raw_obj:type()) print("finished") |