summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@gmail.com>2017-05-13 14:15:04 +0100
committerRichard Maw <richard.maw@gmail.com>2017-05-13 14:15:04 +0100
commit7acacb951b8a099b901b1f3b5e67f1d4c69cbfe3 (patch)
treeb1170cbf4a19dfc8d48f7ec9834c9a1e26eb7c61
parent2989f8359d04ce67a3607984fe402a12353e46b3 (diff)
downloadgall-7acacb951b8a099b901b1f3b5e67f1d4c69cbfe3.tar.bz2
ll.git2: Add revparse_single interface
This permits a wider range of git revision specifications to be parsed without falling back to the command-line.
-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();