summaryrefslogtreecommitdiff
path: root/lib/gall/ll/git2.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gall/ll/git2.c')
-rw-r--r--lib/gall/ll/git2.c53
1 files changed, 51 insertions, 2 deletions
diff --git a/lib/gall/ll/git2.c b/lib/gall/ll/git2.c
index 4eecb91..27e2450 100644
--- a/lib/gall/ll/git2.c
+++ b/lib/gall/ll/git2.c
@@ -97,7 +97,7 @@ static int L_lookup_symbolic_ref(lua_State *L)
return 1;
}
-static int format_oid(lua_State *L, git_oid *oid)
+static int format_oid(lua_State *L, const git_oid *oid)
{
char oidstr[40];
git_oid_fmt(oidstr, oid);
@@ -145,6 +145,21 @@ static int L_merge_base(lua_State *L)
return push_git2_error(L);
}
+static int L_set_symbolic_ref(lua_State *L)
+{
+ git_repository *repo = to_repo(L, 1);
+ git_reference *ref;
+ if (git_reference_symbolic_create(&ref, repo,
+ luaL_checkstring(L, 2),
+ luaL_checkstring(L, 3),
+ 1, NULL, NULL) != 0) {
+ return push_git2_error(L);
+ }
+ git_reference_free(ref);
+ lua_pushboolean(L, 1);
+ return 1;
+}
+
static int L_gc_odb_object(lua_State *L)
{
git_odb_object **obj = lua_touserdata(L, 1);
@@ -229,7 +244,39 @@ static int L_get_object_raw(lua_State *L)
return 1;
}
-int luaopen_git2(lua_State *L)
+static int L_get_tree_table(lua_State *L)
+{
+ git_repository *repo = to_repo(L, 1);
+ git_oid oid;
+ git_tree *tree;
+ size_t ent;
+ if (parse_oid(L, 2, &oid) != 0)
+ return 2;
+ if (git_tree_lookup(&tree, repo, &oid) != 0)
+ return push_git2_error(L);
+ lua_newtable(L);
+ for (ent = 0; ent < git_tree_entrycount(tree); ++ent) {
+ const git_tree_entry *tree_ent =
+ git_tree_entry_byindex(tree, ent);
+ lua_pushnumber(L, ent+1);
+ lua_newtable(L);
+ lua_pushliteral(L, "name");
+ lua_pushstring(L, git_tree_entry_name(tree_ent));
+ lua_settable(L, -3);
+ lua_pushliteral(L, "sha");
+ format_oid(L, git_tree_entry_id(tree_ent));
+ lua_settable(L, -3);
+ lua_pushliteral(L, "perms");
+ lua_pushnumber(L, git_tree_entry_filemode_raw(tree_ent));
+ lua_settable(L, -3);
+ lua_settable(L, -3);
+ }
+
+ git_tree_free(tree);
+ return 1;
+}
+
+int luaopen_gall_ll_git2(lua_State *L)
{
lua_newtable(L);
lua_pushliteral(L, "LIBGIT2_VERSION");
@@ -260,9 +307,11 @@ int luaopen_git2(lua_State *L)
} while (0)
BASIC_FUNC(lookup_symbolic_ref);
BASIC_FUNC(lookup_sha_from_ref);
+ BASIC_FUNC(set_symbolic_ref);
BASIC_FUNC(merge_base);
BASIC_FUNC(get_object_size);
BASIC_FUNC(get_object_type);
BASIC_FUNC(get_object_raw);
+ BASIC_FUNC(get_tree_table);
return 1;
}