diff options
author | Robert G. Jakabosky <bobby@sharedrealm.com> | 2011-01-07 10:45:11 -0800 |
---|---|---|
committer | Robert G. Jakabosky <bobby@sharedrealm.com> | 2011-01-07 10:45:11 -0800 |
commit | 4c770c5b37de769fb50ccd81b11c51367f57d8ba (patch) | |
tree | 9da7b5e85e2b5120439aa9b6719f6743c6602818 | |
parent | a4a95948e23558873801b9f4680d1a930a12da2f (diff) | |
download | luagit2-4c770c5b37de769fb50ccd81b11c51367f57d8ba.tar.gz |
Replace OType userdata with strings. Added missing rawsize() method.
-rw-r--r-- | blob.nobj.lua | 3 | ||||
-rw-r--r-- | database.nobj.lua | 2 | ||||
-rw-r--r-- | git2.nobj.lua | 1 | ||||
-rw-r--r-- | index_entry.nobj.lua | 5 | ||||
-rw-r--r-- | object.nobj.lua | 3 | ||||
-rw-r--r-- | otype.nobj.lua | 34 | ||||
-rw-r--r-- | rawobject.nobj.lua | 16 | ||||
-rw-r--r-- | repository.nobj.lua | 8 | ||||
-rw-r--r-- | revwalk.nobj.lua | 4 | ||||
-rw-r--r-- | test_rep.git.tbz | bin | 6804 -> 7790 bytes | |||
-rw-r--r-- | test_rep.lua | 110 |
11 files changed, 126 insertions, 60 deletions
diff --git a/blob.nobj.lua b/blob.nobj.lua index a97570d..9dcaf20 100644 --- a/blob.nobj.lua +++ b/blob.nobj.lua @@ -65,5 +65,8 @@ object "Blob" { ${buffer}_len = git_blob_rawsize(${this}); ]] }, + method "rawsize" { + c_call "int" "git_blob_rawsize" {} + }, } diff --git a/database.nobj.lua b/database.nobj.lua index 0f1aa67..014d346 100644 --- a/database.nobj.lua +++ b/database.nobj.lua @@ -46,6 +46,7 @@ object "Database" { var_out{"GitError", "err"}, c_source [[ RawObject raw_obj; + raw_obj.ref = LUA_NOREF; ${obj} = &(raw_obj); ${err} = git_odb_read(&(raw_obj.raw), ${this}, &(${id})); ]], @@ -56,6 +57,7 @@ object "Database" { var_out{"GitError", "err"}, c_source [[ RawObject raw_obj; + raw_obj.ref = LUA_NOREF; ${obj} = &(raw_obj); ${err} = git_odb_read_header(&(raw_obj.raw), ${this}, &(${id})); ]], diff --git a/git2.nobj.lua b/git2.nobj.lua index a7292e9..643636d 100644 --- a/git2.nobj.lua +++ b/git2.nobj.lua @@ -12,7 +12,6 @@ subfiles { "rawobject.nobj.lua", "index.nobj.lua", "index_entry.nobj.lua", -"otype.nobj.lua", "oid.nobj.lua", "error.nobj.lua", "object.nobj.lua", diff --git a/index_entry.nobj.lua b/index_entry.nobj.lua index b0c0af9..e3b11b6 100644 --- a/index_entry.nobj.lua +++ b/index_entry.nobj.lua @@ -23,6 +23,11 @@ typedef git_index_entry IndexEntry; ]] object "IndexEntry" { + const "NAMEMASK" { 0x0fff }, + const "STAGEMASK" { 0x3000 }, + const "EXTENDED" { 0x4000 }, + const "VALID" { 0x8000 }, + const "STAGESHIFT" { 12 }, constructor { c_source [[ ${this} = calloc(1, sizeof(IndexEntry)); diff --git a/object.nobj.lua b/object.nobj.lua index 518340f..2af52df 100644 --- a/object.nobj.lua +++ b/object.nobj.lua @@ -45,7 +45,8 @@ object "Object" { ]] }, method "type" { - c_call "OType" "git_object_type" {} + var_out{"const char *", "type"}, + c_source "${type} = git_object_type2string(git_object_type(${this}));" }, method "owner" { c_call "Repository *" "git_object_owner" {} diff --git a/otype.nobj.lua b/otype.nobj.lua deleted file mode 100644 index f4ffb6c..0000000 --- a/otype.nobj.lua +++ /dev/null @@ -1,34 +0,0 @@ --- Copyright (c) 2010 by Robert G. Jakabosky <bobby@sharedrealm.com> --- --- Permission is hereby granted, free of charge, to any person obtaining a copy --- of this software and associated documentation files (the "Software"), to deal --- in the Software without restriction, including without limitation the rights --- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --- copies of the Software, and to permit persons to whom the Software is --- furnished to do so, subject to the following conditions: --- --- The above copyright notice and this permission notice shall be included in --- all copies or substantial portions of the Software. --- --- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN --- THE SOFTWARE. - -c_source [[ -typedef git_otype OType; -]] - -object "OType" { - userdata_type = 'simple', - constructor { - c_call "OType" "git_object_string2type" {"const char *", "str"} - }, - method "__str__" { - c_call "const char *" "git_object_type2string" {} - }, -} - diff --git a/rawobject.nobj.lua b/rawobject.nobj.lua index 01e1ccb..0e6e28e 100644 --- a/rawobject.nobj.lua +++ b/rawobject.nobj.lua @@ -50,14 +50,14 @@ object "RawObject" { userdata_type = 'embed', default = 'NULL', constructor { - var_in{"OType", "type"}, + var_in{"const char *", "type"}, var_in{"const char *", "data"}, c_source [[ RawObject obj; ${this} = &(obj); obj.raw.data = NULL; obj.raw.len = 0; - obj.raw.type = ${type}; + obj.raw.type = git_object_string2type(${type}); obj.ref = LUA_NOREF; RawObject_set_data_and_ref(L, &obj, ${data}, ${data}_len, ${data::idx}); ]], @@ -87,16 +87,12 @@ object "RawObject" { ]], }, method "type" { - var_out{"OType", "type"}, - c_source [[ - ${type} = ${this}->raw.type; -]], + var_out{"const char *", "type"}, + c_source "${type} = git_object_type2string(${this}->raw.type);" }, method "set_type" { - var_in{"OType", "type"}, - c_source [[ - ${this}->raw.type = ${type}; -]], + var_in{"const char *", "type"}, + c_source "${this}->raw.type = git_object_string2type(${type});" }, method "hash" { var_out{"OID", "id"}, diff --git a/repository.nobj.lua b/repository.nobj.lua index aacbdeb..aa1bbd8 100644 --- a/repository.nobj.lua +++ b/repository.nobj.lua @@ -51,19 +51,19 @@ object "Repository" { }, method "lookup" { var_in{"OID", "id"}, - var_in{"OType", "type"}, + var_in{"const char *", "type"}, var_out{"Object *", "obj"}, var_out{"GitError", "err"}, c_source [[ - ${err} = git_repository_lookup(&(${obj}), ${this}, &(${id}), ${type}); + ${err} = git_repository_lookup(&(${obj}), ${this}, &(${id}), git_object_string2type(${type})); ]], }, method "newobject" { - var_in{"OType", "type"}, + var_in{"const char *", "type"}, var_out{"Object *", "obj"}, var_out{"GitError", "err"}, c_source [[ - ${err} = git_repository_newobject(&(${obj}), ${this}, ${type}); + ${err} = git_repository_newobject(&(${obj}), ${this}, git_object_string2type(${type})); ]], }, method "blob_writefile" { diff --git a/revwalk.nobj.lua b/revwalk.nobj.lua index ab87be4..43395e4 100644 --- a/revwalk.nobj.lua +++ b/revwalk.nobj.lua @@ -24,6 +24,10 @@ typedef git_revwalk RevWalk; object "RevWalk" { extends "Object", + const "SORT_NONE" { 0x00 }, + const "SORT_TOPOLOGICAL" { 0x01 }, + const "SORT_TIME" { 0x02 }, + const "SORT_REVERSE" { 0x04 }, constructor "new" { var_in{"Repository *", "repo"}, var_out{"GitError", "err"}, diff --git a/test_rep.git.tbz b/test_rep.git.tbz Binary files differindex 0fc32f3..6235845 100644 --- a/test_rep.git.tbz +++ b/test_rep.git.tbz diff --git a/test_rep.lua b/test_rep.lua index 3852930..f175b1d 100644 --- a/test_rep.lua +++ b/test_rep.lua @@ -18,21 +18,13 @@ 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") +local raw_obj = git2.RawObject('blob',"any ol content will do") print() print("dump RawObject interface") print(dbg_dump(raw_obj)) @@ -60,6 +52,10 @@ 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() print("test writing RawObject to database:") local oid, err = db:write(raw_obj) @@ -85,7 +81,7 @@ end local commit_id = git2.OID.str("d5a93c463d4cca0068750eb6af7b4b54eea8599b") print() print("test parsing a commit object: ", commit_id) -local commit2, err = rep:lookup(commit_id, git2.OType('commit')) +local commit2, err = rep:lookup(commit_id, 'commit') print(commit2, err) local commit1, err = git2.Commit.lookup(rep, commit_id) print(commit1, err) @@ -97,6 +93,12 @@ local function dump_signature(pre, sig) print(pre .. '.email = ', sig:email()) print(pre .. '.when = ', sig:when()) end +local function dump_blob(blob) + print("dump Blob interface") + print(dbg_dump(blob)) + print('blob.rawcontent.size =', blob:rawsize()) + print('blob.rawcontents =', blob:rawcontent()) +end local function dump_tree_entry(entry) if entry == nil then return @@ -104,6 +106,11 @@ 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() + print('tree_entry.object = ', obj) + if obj:type() == 'blob' then + dump_blob(obj) + end end local function dump_tree(tree) if tree == nil then @@ -139,6 +146,89 @@ local function dump_commit(commit) end dump_commit(commit1) +local index = rep:index() +print("dump Index interface") +print(dbg_dump(index)) +local function dump_index_entry(entry) + if entry == nil then + return + end + print(' idx.entry.ctime = ', entry:ctime()) + print(' idx.entry.mtime = ', entry:mtime()) + print(' idx.entry.dev = ', entry:dev()) + print(' idx.entry.ino = ', entry:ino()) + print(' idx.entry.mode = ', entry:mode()) + print(' idx.entry.uid = ', entry:uid()) + print(' idx.entry.gid = ', entry:gid()) + print(' idx.entry.file_size = ', entry:file_size()) + print(' idx.entry.id = ', entry:id()) + print(' idx.entry.flags = ', string.format('0x%08X', entry:flags())) + print(' idx.entry.flags_extended = ', string.format('0x%08X', entry:flags_extended())) + print(' idx.entry.path = ', entry:path()) +end +local function dump_index(index) + if index == nil then + return + end + local cnt = index:entrycount() + print('entrycount = ', cnt) + for i=0,cnt-1 do + local entry = index:get(i) + print('entry:', entry) + dump_index_entry(entry) + end +end +print('index:read():', index:read()) +dump_index(index) + +local revwalk = git2.RevWalk(rep) +print("dump RevWalk interface") +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)) +assert(revwalk:repository() == rep) + +local commit = revwalk:next() +while (commit ~= nil) do + dump_commit(commit) + -- get next commit + commit = revwalk:next() +end +local tag_id = git2.OID.str('82dfe36284d77b608ccc9d96e0ffa5782cb7c835') +local tag = git2.Tag.lookup(rep, tag_id) +print("dump Tag interface") +print(dbg_dump(tag)) +local function dump_tag(tag) + if tag == nil then + return + end + print('name = ', tag:name()) + dump_signature('tagger', tag:tagger()) + print('message = ', tag:message()) + local obj = tag:target() + print('target = ', obj) +end +dump_tag(tag) + + +revwalk = nil +head = nil +commit = nil +commit1 = nil +commit2 = nil +index = nil +rep = nil +db = nil + +collectgarbage"collect" +collectgarbage"collect" +collectgarbage"collect" + + +print() +print() print("finished") |