From 15f4cc9dc2cfcdd97de8c647913f35e4f6cb0ba0 Mon Sep 17 00:00:00 2001 From: "Robert G. Jakabosky" Date: Fri, 11 May 2012 18:25:54 -0700 Subject: Update code to libgit2 0.16.0 API. --- git2.nobj.lua | 15 +++++- src/commit.nobj.lua | 27 +++++----- src/database.nobj.lua | 74 ---------------------------- src/index.nobj.lua | 36 +++++++++++--- src/index_entry.nobj.lua | 100 ++++++++------------------------------ src/index_entry_unmerged.nobj.lua | 50 +++++++++++++++++++ src/object.nobj.lua | 4 +- src/odb.nobj.lua | 86 ++++++++++++++++++++++++++++++++ src/odb_object.nobj.lua | 10 ++-- src/oid.nobj.lua | 38 +++++++++++++-- src/oid_shorten.nobj.lua | 41 ++++++++++++++++ src/reference.nobj.lua | 4 +- src/repository.nobj.lua | 61 ++++++++++++++++++----- src/signature.nobj.lua | 12 +++-- src/tree.nobj.lua | 4 +- tests/test_rep.lua | 20 ++++---- 16 files changed, 367 insertions(+), 215 deletions(-) delete mode 100644 src/database.nobj.lua create mode 100644 src/index_entry_unmerged.nobj.lua create mode 100644 src/odb.nobj.lua create mode 100644 src/oid_shorten.nobj.lua diff --git a/git2.nobj.lua b/git2.nobj.lua index 66dd456..8ad1b29 100644 --- a/git2.nobj.lua +++ b/git2.nobj.lua @@ -1,4 +1,6 @@ +basetype "git_time_t" "integer" "0" + c_module "git2" { -- module settings. use_globals = false, @@ -33,6 +35,15 @@ EREVWALKOVER = "GIT_EREVWALKOVER", EINVALIDREFSTATE = "GIT_EINVALIDREFSTATE", ENOTIMPLEMENTED = "GIT_ENOTIMPLEMENTED", EEXISTS = "GIT_EEXISTS", +EOVERFLOW = "GIT_EOVERFLOW", +ENOTNUM = "GIT_ENOTNUM", +ESTREAM = "GIT_ESTREAM", +EINVALIDARGS = "GIT_EINVALIDARGS", +EOBJCORRUPTED = "GIT_EOBJCORRUPTED", +EAMBIGUOUSOIDPREFIX = "GIT_EAMBIGUOUSOIDPREFIX", +EPASSTHROUGH = "GIT_EPASSTHROUGH", +ENOMATCH = "GIT_ENOMATCH", +ESHORTBUFFER = "GIT_ESHORTBUFFER", }, -- reference types @@ -51,10 +62,12 @@ subfiles { "src/repository.nobj.lua", "src/odb_object.nobj.lua", "src/oid.nobj.lua", -"src/database.nobj.lua", +"src/oid_shorten.nobj.lua", +"src/odb.nobj.lua", --"src/database_backend.nobj.lua", "src/index.nobj.lua", "src/index_entry.nobj.lua", +"src/index_entry_unmerged.nobj.lua", "src/object.nobj.lua", "src/blob.nobj.lua", "src/signature.nobj.lua", diff --git a/src/commit.nobj.lua b/src/commit.nobj.lua index 269cf73..4ec72bb 100644 --- a/src/commit.nobj.lua +++ b/src/commit.nobj.lua @@ -33,13 +33,14 @@ typedef git_commit Commit; var_in{ "const char *", "update_ref" }, var_in{ "Signature *", "author" }, var_in{ "Signature *", "committer" }, + var_in{ "const char *", "message_encoding" }, var_in{ "const char *", "message" }, var_in{ "Tree *", "tree" }, var_in{ "Commit *", "parent" }, var_out{"GitError", "err"}, c_source "pre" [[ int parent_count = 0; - const git_oid **p_oids; + const git_commit **parents; int n; ]], c_source[[ @@ -50,30 +51,32 @@ typedef git_commit Commit; obj_type_Commit_check(L, ${parent::idx} + n); } /* now it is safe to allocate oid array. */ - p_oids = malloc(parent_count * sizeof(git_oid *)); + parents = malloc(parent_count * sizeof(git_commit *)); /* copy oids from all parents into oid array. */ - p_oids[0] = git_object_id((git_object *)${parent}); + parents[0] = ${parent}; for(n = 1; n < parent_count; n++) { - ${parent} = obj_type_Commit_check(L, ${parent::idx} + n); - p_oids[n] = git_object_id((git_object *)${parent}); + parents[n] = obj_type_Commit_check(L, ${parent::idx} + n); } ${err} = git_commit_create(&(${oid}), ${repo}, ${update_ref}, - ${author}, ${committer}, ${message}, git_object_id((git_object *)${tree}), - parent_count, p_oids); + ${author}, ${committer}, ${message_encoding}, ${message}, + ${tree}, parent_count, parents); /* free parent oid array. */ - free(p_oids); + free(parents); ]] }, + method "id" { + c_method_call { "OID", "*id" } "git_commit_id" {} + }, + method "message_encoding" { + c_method_call "const char *" "git_commit_message_encoding" {} + }, method "message" { c_method_call "const char *" "git_commit_message" {} }, - method "message_short" { - c_method_call "const char *" "git_commit_message_short" {} - }, method "time" { - c_method_call "time_t" "git_commit_time" {} + c_method_call "git_time_t" "git_commit_time" {} }, method "time_offset" { c_method_call "int" "git_commit_time_offset" {} diff --git a/src/database.nobj.lua b/src/database.nobj.lua deleted file mode 100644 index b663d15..0000000 --- a/src/database.nobj.lua +++ /dev/null @@ -1,74 +0,0 @@ --- Copyright (c) 2010 by Robert G. Jakabosky --- --- 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. - -object "Database" { - c_source [[ -typedef git_odb Database; -]], - constructor "new" { - c_call {"GitError", "err"} "git_odb_new" { "Database *", "&this" }, - }, - constructor "open" { - c_call {"GitError", "err"} "git_odb_open" - { "Database *", "&this", "const char *", "object_dir" }, - }, - destructor "close" { - c_method_call "void" "git_odb_close" {} - }, - --[=[ - method "add_backend" { - var_in{"DatabaseBackend *", "backend"}, - var_in{"int", "priority"}, - var_out{"GitError", "err"}, - c_source [[ - ${err} = git_odb_add_backend(${this}, &(${backend}->backend), ${priority}); - DatabaseBackend_ref(${backend}); -]], - }, - method "add_alternate" { - var_in{"DatabaseBackend *", "backend"}, - var_in{"int", "priority"}, - var_out{"GitError", "err"}, - c_source [[ - ${err} = git_odb_add_alternate(${this}, &(${backend}->backend), ${priority}); - DatabaseBackend_ref(${backend}); -]], - }, - --]=] - method "read" { - c_call "GitError" "git_odb_read" - { "!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<3" }, - c_call "GitError" "git_odb_write" - { "OID", "&id>1", "Database *", "this<1", "const char *", "data<2", "size_t", "#data", - "git_otype", "otype"}, - }, - method "exists" { - c_method_call { "GitError", "err" } "git_odb_exists" { "OID", "&id" } - }, -} - diff --git a/src/index.nobj.lua b/src/index.nobj.lua index 9fe5815..4d34acb 100644 --- a/src/index.nobj.lua +++ b/src/index.nobj.lua @@ -23,13 +23,9 @@ object "Index" { typedef git_index Index; ]], constructor "bare" { - c_call {"GitError", "err"} "git_index_open_bare" + c_call {"GitError", "err"} "git_index_open" { "Index *", "&this", "const char *", "index_path" }, }, - constructor "inrepo" { - c_call {"GitError", "err"} "git_index_open_inrepo" - { "Index *", "&this", "Repository *", "repo" }, - }, destructor { c_method_call "void" "git_index_free" {} }, @@ -39,23 +35,47 @@ typedef git_index Index; method "read" { c_method_call "GitError" "git_index_read" {} }, + method "write" { + c_method_call "GitError" "git_index_write" {} + }, method "find" { c_method_call "int" "git_index_find" { "const char *", "path" } }, + method "uniq" { + c_method_call "void" "git_index_uniq" {} + }, method "add" { c_method_call "GitError" "git_index_add" { "const char *", "path", "int", "stage" } }, + method "add2" { + c_method_call "GitError" "git_index_add2" { "IndexEntry *", "source_entry" } + }, + method "append" { + c_method_call "GitError" "git_index_append" { "const char *", "path", "int", "stage" } + }, + method "append2" { + c_method_call "GitError" "git_index_append2" { "IndexEntry *", "source_entry" } + }, method "remove" { c_method_call "GitError" "git_index_remove" { "int", "position" } }, - method "insert" { - c_method_call "GitError" "git_index_insert" { "IndexEntry *", "source_entry" } - }, method "get" { c_method_call "IndexEntry *" "git_index_get" { "int", "n" } }, method "entrycount" { c_method_call "unsigned int" "git_index_entrycount" {} }, + method "entrycount_unmerged" { + c_method_call "unsigned int" "git_index_entrycount_unmerged" {} + }, + method "get_unmerged_bypath" { + c_method_call "const IndexEntryUnmerged *" "git_index_get_unmerged_bypath" { "const char *", "path" } + }, + method "get_unmerged_byindex" { + c_method_call "const IndexEntryUnmerged *" "git_index_get_unmerged_byindex" { "int", "n" } + }, + method "read_tree" { + c_method_call "GitError" "git_index_read_tree" { "Tree *", "tree" } + }, } diff --git a/src/index_entry.nobj.lua b/src/index_entry.nobj.lua index fd39556..e47d79f 100644 --- a/src/index_entry.nobj.lua +++ b/src/index_entry.nobj.lua @@ -42,110 +42,50 @@ typedef git_index_entry IndexEntry; free(${this}); ]] }, + method "stage" { + c_method_call "int" "git_index_entry_stage" {}, + }, method "ctime" { - var_out{"time_t", "secs"}, - var_out{"time_t", "nanosecs"}, + var_out{"git_time_t", "secs"}, + var_out{"unsigned int", "nanosecs"}, c_source [[ ${secs} = ${this}->ctime.seconds; ${nanosecs} = ${this}->ctime.nanoseconds; ]] }, method "set_ctime" { - var_in{"time_t", "secs"}, - var_in{"time_t", "nanosecs"}, + var_in{"git_time_t", "secs"}, + var_in{"unsigned int", "nanosecs"}, c_source [[ ${this}->ctime.seconds = ${secs}; ${this}->ctime.nanoseconds = ${nanosecs}; ]] }, method "mtime" { - var_out{"time_t", "secs"}, - var_out{"time_t", "nanosecs"}, + var_out{"git_time_t", "secs"}, + var_out{"unsigned int", "nanosecs"}, c_source [[ ${secs} = ${this}->mtime.seconds; ${nanosecs} = ${this}->mtime.nanoseconds; ]] }, method "set_mtime" { - var_in{"time_t", "secs"}, - var_in{"time_t", "nanosecs"}, + var_in{"git_time_t", "secs"}, + var_in{"unsigned int", "nanosecs"}, c_source [[ ${this}->mtime.seconds = ${secs}; ${this}->mtime.nanoseconds = ${nanosecs}; ]] }, - method "dev" { - var_out{"unsigned int", "ret"}, - c_source "${ret} = ${this}->dev;" - }, - method "set_dev" { - var_in{"unsigned int", "val"}, - c_source "${this}->dev = ${val};" - }, - method "ino" { - var_out{"unsigned int", "ret"}, - c_source "${ret} = ${this}->ino;" - }, - method "set_ino" { - var_in{"unsigned int", "val"}, - c_source "${this}->ino = ${val};" - }, - method "mode" { - var_out{"unsigned int", "ret"}, - c_source "${ret} = ${this}->mode;" - }, - method "set_mode" { - var_in{"unsigned int", "val"}, - c_source "${this}->mode = ${val};" - }, - method "uid" { - var_out{"unsigned int", "ret"}, - c_source "${ret} = ${this}->uid;" - }, - method "set_uid" { - var_in{"unsigned int", "val"}, - c_source "${this}->uid = ${val};" - }, - method "gid" { - var_out{"unsigned int", "ret"}, - c_source "${ret} = ${this}->gid;" - }, - method "set_gid" { - var_in{"unsigned int", "val"}, - c_source "${this}->gid = ${val};" - }, - method "file_size" { - var_out{"off_t", "ret"}, - c_source "${ret} = ${this}->file_size;" - }, - method "set_file_size" { - var_in{"off_t", "val"}, - c_source "${this}->file_size = ${val};" - }, - method "id" { - var_out{"OID", "ret"}, - c_source "${ret} = ${this}->oid;" - }, - method "set_id" { - var_in{"OID", "val"}, - c_source "${this}->oid = ${val};" - }, - method "flags" { - var_out{"unsigned short", "ret"}, - c_source "${ret} = ${this}->flags;" - }, - method "set_flags" { - var_in{"unsigned short", "val"}, - c_source "${this}->flags = ${val};" - }, - method "flags_extended" { - var_out{"unsigned short", "ret"}, - c_source "${ret} = ${this}->flags_extended;" - }, - method "set_flags_extended" { - var_in{"unsigned short", "val"}, - c_source "${this}->flags_extended = ${val};" - }, + field "unsigned int" "dev", + field "unsigned int" "ino", + field "unsigned int" "mode", + field "unsigned int" "uid", + field "unsigned int" "gid", + field "off_t" "file_size", + field "OID" "oid", + field "unsigned int" "flags", + field "unsigned int" "flags_extended", method "path" { var_out{"const char *", "ret"}, c_source "${ret} = ${this}->path;" diff --git a/src/index_entry_unmerged.nobj.lua b/src/index_entry_unmerged.nobj.lua new file mode 100644 index 0000000..a38a9d5 --- /dev/null +++ b/src/index_entry_unmerged.nobj.lua @@ -0,0 +1,50 @@ +-- Copyright (c) 2010 by Robert G. Jakabosky +-- +-- 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. + +object "IndexEntryUnmerged" { + c_source [[ +typedef git_index_entry_unmerged IndexEntryUnmerged; +]], + method "mode" { + var_in{"int", "idx"}, + var_out{"unsigned int", "mode"}, + c_source [[ + if(${idx} < 0 || ${idx} >=3) { + return luaL_argerror(L, ${idx::idx}, "Index out-of-bounds (0-2)"); + } + ${mode} = ${this}->mode[${idx}]; +]] + }, + method "oid" { + var_in{"int", "idx"}, + var_out{"OID", "oid"}, + c_source [[ + if(${idx} < 0 || ${idx} >=3) { + return luaL_argerror(L, ${idx::idx}, "Index out-of-bounds (0-2)"); + } + ${oid} = ${this}->oid[${idx}]; +]] + }, + method "path" { + var_out{"const char *", "ret"}, + c_source "${ret} = ${this}->path;" + }, +} + diff --git a/src/object.nobj.lua b/src/object.nobj.lua index 54baa1d..30658bf 100644 --- a/src/object.nobj.lua +++ b/src/object.nobj.lua @@ -33,8 +33,8 @@ typedef git_object Object; GIT_OBJ_TAG = "Tag", }, }, - destructor "close" { - c_method_call "void" "git_object_close" {} + destructor "free" { + c_method_call "void" "git_object_free" {} }, method "id" { c_method_call { "OID", "*id" } "git_object_id" {}, diff --git a/src/odb.nobj.lua b/src/odb.nobj.lua new file mode 100644 index 0000000..1d706b4 --- /dev/null +++ b/src/odb.nobj.lua @@ -0,0 +1,86 @@ +-- Copyright (c) 2010 by Robert G. Jakabosky +-- +-- 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. + +object "ODB" { + c_source [[ +typedef git_odb ODB; +]], + constructor "new" { + c_call {"GitError", "err"} "git_odb_new" { "ODB *", "&this" }, + }, + constructor "open" { + c_call {"GitError", "err"} "git_odb_open" + { "ODB *", "&this", "const char *", "object_dir" }, + }, + destructor "free" { + c_method_call "void" "git_odb_free" {} + }, + --[=[ + method "add_backend" { + var_in{"ODBBackend *", "backend"}, + var_in{"int", "priority"}, + var_out{"GitError", "err"}, + c_source [[ + ${err} = git_odb_add_backend(${this}, &(${backend}->backend), ${priority}); + ODBBackend_ref(${backend}); +]], + }, + method "add_alternate" { + var_in{"ODBBackend *", "backend"}, + var_in{"int", "priority"}, + var_out{"GitError", "err"}, + c_source [[ + ${err} = git_odb_add_alternate(${this}, &(${backend}->backend), ${priority}); + ODBBackend_ref(${backend}); +]], + }, + --]=] + method "read" { + c_call "GitError" "git_odb_read" + { "!OdbObject *", "&out>1", "ODB *", "this", "OID", "&id"}, + }, + method "read_prefix" { + c_call "GitError" "git_odb_read_prefix" + { "!OdbObject *", "&out>1", "ODB *", "this", "OID", "&short_id", "unsigned int", "len"}, + }, + method "read_header" { + c_call { "GitError", "err>3" } "git_odb_read_header" + { "size_t", "&len_p>1", "git_otype", "&(otype)", "ODB *", "this", "OID", "&id"}, + c_call { "const char *", "type>2" } "git_object_type2string" { "git_otype", "otype" }, + }, + method "exists" { + c_method_call { "GitError", "err" } "git_odb_exists" { "OID", "&id" } + }, + method "write" { + c_call { "git_otype", "(otype)" } "git_object_string2type" { "const char *", "type<3" }, + c_call "GitError" "git_odb_write" + { "OID", "&id>1", "ODB *", "this<1", "const char *", "data<2", "size_t", "#data", + "git_otype", "otype"}, + }, + c_function "hash" { + c_call { "GitError", "err" } "git_odb_hash" + { "OID", "&id>1", "const char *", "data", "size_t", "#data", "git_otype", "otype"} + }, + c_function "hashfile" { + c_call { "GitError", "err" } "git_odb_hashfile" + { "OID", "&id>1", "const char *", "path", "git_otype", "otype"} + }, +} + diff --git a/src/odb_object.nobj.lua b/src/odb_object.nobj.lua index ac00b0c..5ca2753 100644 --- a/src/odb_object.nobj.lua +++ b/src/odb_object.nobj.lua @@ -22,8 +22,11 @@ object "OdbObject" { c_source [[ typedef git_odb_object OdbObject; ]], - destructor "close" { - c_method_call "void" "git_odb_object_close" {}, + destructor "free" { + c_method_call "void" "git_odb_object_free" {}, + }, + method "id" { + c_method_call { "OID", "*id" } "git_odb_object_id" {}, }, method "data" { c_method_call { "const char *", "data" } "git_odb_object_data" {}, @@ -36,8 +39,5 @@ typedef git_odb_object OdbObject; c_method_call { "git_otype", "(otype)" } "git_odb_object_type" {}, c_call { "const char *", "type" } "git_object_type2string" { "git_otype", "otype" }, }, - method "id" { - c_method_call { "OID", "*id" } "git_odb_object_id" {}, - }, } diff --git a/src/oid.nobj.lua b/src/oid.nobj.lua index cb00071..8121180 100644 --- a/src/oid.nobj.lua +++ b/src/oid.nobj.lua @@ -19,16 +19,46 @@ -- THE SOFTWARE. object "OID" { + export_definitions { + RAWSZ = "GIT_OID_RAWSZ", + HEXSZ = "GIT_OID_HEXSZ", + MINPREFIXLEN = "GIT_OID_MINPREFIXLEN", + }, c_source [[ typedef git_oid OID; ]], userdata_type = 'simple', - constructor "str" { - c_call {"GitError", "err"} "git_oid_mkstr" - { "OID", "&this", "const char *", "hex" }, + constructor "hex" { + c_call {"GitError", "err"} "git_oid_fromstrn" + { "OID", "&this", "const char *", "str", "size_t", "#str" }, }, constructor "raw" { - c_call "void" "git_oid_mkraw" { "OID", "&this", "const unsigned char *", "raw" }, + c_source[[ + if(${raw_len} < GIT_OID_RAWSZ) { + lua_pushnil(L); + lua_pushliteral(L, "Invalid RAW OID"); + return 2; + } + ]], + c_call "void" "git_oid_fromraw" { "OID", "&this", "const unsigned char *", "raw" }, + }, + method "pathfmt" { + var_out{"const char *", "ret"}, + c_source [[ + char buf[GIT_OID_HEXSZ+1+1]; + git_oid_pathfmt(buf, &(${this})); + buf[GIT_OID_HEXSZ] = 0; + ${ret} = buf; +]], + }, + method "fmt" { + var_out{"const char *", "ret"}, + c_source [[ + char buf[GIT_OID_HEXSZ+1]; + git_oid_fmt(buf, &(${this})); + buf[GIT_OID_HEXSZ] = 0; + ${ret} = buf; +]], }, method "__str__" { var_out{"const char *", "ret"}, diff --git a/src/oid_shorten.nobj.lua b/src/oid_shorten.nobj.lua new file mode 100644 index 0000000..b44ca89 --- /dev/null +++ b/src/oid_shorten.nobj.lua @@ -0,0 +1,41 @@ +-- Copyright (c) 2012 by Robert G. Jakabosky +-- +-- 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. + +object "OID_Shorten" { + c_source [[ +typedef git_oid_shorten OID_Shorten; +]], + constructor "new" { + c_call "OID_Shorten *" "git_oid_shorten_new" { "size_t", "min_length" }, + }, + destructor { + c_method_call "void" "git_oid_shorten_free" {} + }, + method "add" { + c_method_call { "GitError", "rc"} "git_oid_shorten_add" { "const char *", "text_oid" }, + c_source[[ + if(${rc} >= 0) { + lua_pushinteger(L, ${rc}); + return 1; + } + ]] + }, +} + diff --git a/src/reference.nobj.lua b/src/reference.nobj.lua index 6a005c2..a7226a0 100644 --- a/src/reference.nobj.lua +++ b/src/reference.nobj.lua @@ -53,7 +53,7 @@ typedef git_reference Reference; c_method_call "Repository *" "git_reference_owner" {} }, method "rename" { - c_method_call "GitError" "git_reference_rename" { "const char *", "new_name" } + c_method_call "GitError" "git_reference_rename" { "const char *", "new_name", "bool", "force" } }, method "delete" { c_method_call "GitError" "git_reference_delete" {} @@ -71,7 +71,7 @@ typedef git_reference Reference; ]], c_source[[ /* push this onto stack now, just encase there is a out-of-memory error. */ - ${array} = obj_type_StrArray_push(L, &tmp_array, OBJ_UDATA_FLAG_OWN); + ${array} = obj_type_StrArray_push(L, &tmp_array); ${err} = git_reference_listall(${array}, ${repo}, ${list_flags}); if(${err} == GIT_SUCCESS) { return 1; /* array is already on the stack. */ diff --git a/src/repository.nobj.lua b/src/repository.nobj.lua index 11bd4b8..626fc2d 100644 --- a/src/repository.nobj.lua +++ b/src/repository.nobj.lua @@ -26,16 +26,14 @@ typedef git_repository Repository; c_call { "GitError", "err" } "git_repository_open" { "Repository *", "&this>1", "const char *", "path" }, }, - constructor "open2" { - c_call { "GitError", "err" } "git_repository_open2" - { "Repository *", "&this>1", "const char *", "dir", "const char *", "object_directory", - "const char *", "index_file", "const char *", "work_tree" }, - }, - constructor "open3" { - c_call { "GitError", "err" } "git_repository_open3" - { "Repository *", "&this>1", "const char *", "dir", "Database *", "object_database", - "const char *", "index_file", "const char *", "work_tree" }, + --[=[ + constructor "discover" { + c_source[[ + ]], + c_call { "GitError", "err" } "git_repository_open" + { "Repository *", "&this>1", "const char *", "path" }, }, + --]=] constructor "init" { c_call { "GitError", "err" } "git_repository_init" { "Repository *", "&this>1", "const char *", "path", "unsigned int", "is_bare" }, @@ -43,12 +41,53 @@ typedef git_repository Repository; destructor { c_method_call "void" "git_repository_free" {} }, - method "database" { - c_method_call "Database *" "git_repository_database" {} + method "head" { + c_call { "GitError", "err" } "git_repository_head" + { "!Reference *", "&head>1", "Repository *", "this" }, + }, + method "head_detached" { + c_method_call "bool" "git_repository_head_detached" {} + }, + method "head_orphan" { + c_method_call "bool" "git_repository_head_orphan" {} + }, + method "is_empty" { + c_method_call "bool" "git_repository_is_empty" {} + }, + method "is_bare" { + c_method_call "bool" "git_repository_is_bare" {} + }, + method "path" { + c_method_call "const char *" "git_repository_path" {} + }, + method "workdir" { + c_method_call "const char *" "git_repository_workdir" {} + }, + method "set_workdir" { + c_method_call "GitError" "git_repository_set_workdir" { "const char *", "workdir"} + }, + --[[ TODO: + method "config" { + c_call { "GitError", "err" } "git_repository_config" + { "!Config *", "&config>1", "Repository *", "this" }, + }, + method "set_config" { + c_method_call "void" "git_repository_set_config" { "Config *", "config"} + }, + --]] + method "odb" { + c_call { "GitError", "err" } "git_repository_odb" + { "!ODB *", "&odb>1", "Repository *", "this" }, + }, + method "set_odb" { + c_method_call "void" "git_repository_set_odb" { "ODB *", "odb"} }, method "index" { c_call { "GitError", "err" } "git_repository_index" { "!Index *", "&index>1", "Repository *", "this" }, }, + method "set_index" { + c_method_call "void" "git_repository_set_index" { "Index *", "index"} + }, } diff --git a/src/signature.nobj.lua b/src/signature.nobj.lua index 8de250b..6eea7db 100644 --- a/src/signature.nobj.lua +++ b/src/signature.nobj.lua @@ -22,9 +22,13 @@ object "Signature" { c_source [[ typedef git_signature Signature; ]], - constructor { - c_call "Signature *" "git_signature_new" - { "const char *", "name", "const char *", "email", "time_t", "time", "int", "offset" }, + constructor "new" { + c_call "GitError" "git_signature_new" + { "Signature *", "&this>1", "const char *", "name", "const char *", "email", "git_time_t", "time", "int", "offset" }, + }, + constructor "now" { + c_call "GitError" "git_signature_now" + { "Signature *", "&this>1", "const char *", "name", "const char *", "email" }, }, destructor { c_method_call "void" "git_signature_free" {}, @@ -38,7 +42,7 @@ typedef git_signature Signature; c_source "${email} = ${this}->email;", }, method "when" { - var_out{"time_t", "time"}, + var_out{"git_time_t", "time"}, var_out{"int", "offset"}, c_source "${time} = ${this}->when.time; ${offset} = ${this}->when.offset;", }, diff --git a/src/tree.nobj.lua b/src/tree.nobj.lua index ab8fa22..fa54ec8 100644 --- a/src/tree.nobj.lua +++ b/src/tree.nobj.lua @@ -31,10 +31,10 @@ typedef git_tree Tree; c_method_call "size_t" "git_tree_entrycount" {} }, method "entry_byname" { - c_method_call "TreeEntry *" "git_tree_entry_byname" { "const char *", "filename" } + c_method_call "const TreeEntry *" "git_tree_entry_byname" { "const char *", "filename" } }, method "entry_byindex" { - c_method_call "TreeEntry *" "git_tree_entry_byindex" { "int", "index" } + c_method_call "const TreeEntry *" "git_tree_entry_byindex" { "int", "index" } }, } diff --git a/tests/test_rep.lua b/tests/test_rep.lua index 7829562..068ee72 100644 --- a/tests/test_rep.lua +++ b/tests/test_rep.lua @@ -7,7 +7,7 @@ if ( build_dir ) then package.cpath = build_dir .. "?.so;" .. package.cpath end -require"git2" +local git2 = require"git2" require"utils" print("dump git2 interface") @@ -18,12 +18,12 @@ local rep = assert(git2.Repository(git_path)) print("dump Repository interface") print(dbg_dump(rep)) -local oid = git2.OID.str("d5a93c463d4cca0068750eb6af7b4b54eea8599b") +local oid = git2.OID.hex("d5a93c463d4cca0068750eb6af7b4b54eea8599b") print("dump OID interface") print(dbg_dump(oid)) print('convert OID value to string = <' .. tostring(oid) .. '>') -local db = rep:database() +local db = rep:odb() print("dump Database interface") print(dbg_dump(db)) @@ -55,7 +55,7 @@ dump_odb_obj(odb_obj) print() print("test closing of OdbObject:") -odb_obj:close() +odb_obj:free() dump_odb_obj(odb_obj) print() @@ -67,7 +67,7 @@ local object_ids = { {'blob', "275a4019807c7bb7bc80c0ca8903bf84345e1bdf"}, } for _,obj in ipairs(object_ids) do - local oid = git2.OID.str(obj[2]) + local oid = git2.OID.hex(obj[2]) local odb_obj, err = db:read(oid) print() print(odb_obj, err) @@ -75,7 +75,7 @@ for _,obj in ipairs(object_ids) do end -local commit_id = git2.OID.str("d5a93c463d4cca0068750eb6af7b4b54eea8599b") +local commit_id = git2.OID.hex("d5a93c463d4cca0068750eb6af7b4b54eea8599b") print() print("test parsing a commit object: ", commit_id) local commit1, err = git2.Commit.lookup(rep, commit_id) @@ -123,8 +123,8 @@ local function dump_commit(commit) if commit == nil then return end + print('message_encoding = ', commit:message_encoding()) print('message = ', commit:message()) - print('message_short = ', commit:message_short()) print('time = ', commit:time()) print('tree = ', commit:tree()) dump_tree(commit:tree()) @@ -155,7 +155,7 @@ local function dump_index_entry(entry) 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.oid = ', entry:oid()) 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()) @@ -179,7 +179,7 @@ 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_id = git2.OID.hex("5c697d74eb692d650799ca1b0a10254d7130953d") local head = assert(git2.Commit.lookup(rep, head_id)) print('push:', revwalk:push(head_id)) assert(revwalk:repository() == rep) @@ -191,7 +191,7 @@ while (commit_oid ~= nil) do commit_oid = revwalk:next() end -local tag_id = git2.OID.str('82dfe36284d77b608ccc9d96e0ffa5782cb7c835') +local tag_id = git2.OID.hex('82dfe36284d77b608ccc9d96e0ffa5782cb7c835') local tag = git2.Tag.lookup(rep, tag_id) print("dump Tag interface") print(dbg_dump(tag)) -- cgit v1.2.1