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.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/gall/ll/git2.c b/lib/gall/ll/git2.c
index ce72244..785f1dc 100644
--- a/lib/gall/ll/git2.c
+++ b/lib/gall/ll/git2.c
@@ -398,6 +398,30 @@ static int L_get_tree_table(lua_State *L)
}
/**
+ * Lookup the SHA1 pointed at by a sha1ish.
+ *
+ * @function revparse_single
+ * @tparam llrepo repository The repository to look up the reference in.
+ * @tparam string ref The sha1ish to look up.
+ * @treturn string The OID (SHA1) of the referent (or nil on error).
+ * @treturn string The error message if the OID is nil.
+ */
+
+static int L_revparse_single(lua_State *L)
+{
+ git_repository *repo = to_repo(L, 1);
+ const char *sha1ish = luaL_checkstring(L, 2);
+ git_object *obj;
+ int ret;
+ if ((ret = git_revparse_single(&obj, repo, sha1ish)) != 0) {
+ return push_git2_error(L, ret);
+ }
+ ret = format_oid(L, git_object_id(obj));
+ git_object_free(obj);
+ return ret;
+}
+
+/**
* The version of libgit2 which this instance of gall was built against.
*
* When Gall is compiled, the version of libgit2 is baked into the C binding
@@ -443,6 +467,7 @@ int luaopen_gall_ll_git2(lua_State *L)
BASIC_FUNC(get_object_type);
BASIC_FUNC(get_object_raw);
BASIC_FUNC(get_tree_table);
+ BASIC_FUNC(revparse_single);
#if LIBGIT2_SOVERSION > 22
git_libgit2_init();