diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2015-07-16 11:19:51 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2015-07-16 11:19:51 +0100 |
commit | 69d1e8ffd45739db90986ea0bbf4ae646a8382da (patch) | |
tree | 7bf895648918c910ed6572ee4ccc4b685726cbb1 | |
parent | a1859fcefffd48651f1086f1bb786d4e4bb83009 (diff) | |
download | gall-69d1e8ffd45739db90986ea0bbf4ae646a8382da.tar.gz |
Support situations where there is no git_error available
-rw-r--r-- | lib/gall/ll/git2.c | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/lib/gall/ll/git2.c b/lib/gall/ll/git2.c index 27e2450..9188ab8 100644 --- a/lib/gall/ll/git2.c +++ b/lib/gall/ll/git2.c @@ -31,11 +31,15 @@ static inline git_odb *to_odb(lua_State *L, int idx) } /* Push the most recent error from libgit2 */ -static int push_git2_error(lua_State *L) +static int push_git2_error(lua_State *L, int retcode) { const git_error *err = giterr_last(); lua_pushnil(L); - lua_pushstring(L, err->message); + if (err == NULL) { + lua_pushfstring(L, "Unknown error: %d", retcode); + } else { + lua_pushstring(L, err->message); + } return 2; } @@ -63,12 +67,12 @@ static int L_open_repo(lua_State *L) ret = git_repository_open(&real->repo, repopath); if (ret != 0) { - return push_git2_error(L); + return push_git2_error(L, ret); } ret = git_repository_odb(&real->odb, real->repo); if (ret != 0) { - push_git2_error(L); + push_git2_error(L, ret); git_repository_free(real->repo); return 2; } @@ -83,8 +87,9 @@ static int L_lookup_symbolic_ref(lua_State *L) git_repository *repo = to_repo(L, 1); const char *refname = luaL_checkstring(L, 2); git_reference *ref = NULL; - if (git_reference_lookup(&ref, repo, refname) != 0) { - return push_git2_error(L); + int ret; + if ((ret = git_reference_lookup(&ref, repo, refname)) != 0) { + return push_git2_error(L, ret); } if (git_reference_type(ref) != GIT_REF_SYMBOLIC) { git_reference_free(ref); @@ -110,8 +115,9 @@ static int L_lookup_sha_from_ref(lua_State *L) git_repository *repo = to_repo(L, 1); const char *refname = luaL_checkstring(L, 2); git_oid ref; - if (git_reference_name_to_id(&ref, repo, refname) != 0) { - return push_git2_error(L); + int ret; + if ((ret = git_reference_name_to_id(&ref, repo, refname)) != 0) { + return push_git2_error(L, ret); } return format_oid(L, &ref); } @@ -121,7 +127,7 @@ static int parse_oid(lua_State *L, int spos, git_oid *oid) const char *oid_s = luaL_checkstring(L, spos); int ret = git_oid_fromstr(oid, oid_s); if (ret != 0) - return push_git2_error(L); + return push_git2_error(L, ret); return 0; } @@ -142,18 +148,19 @@ static int L_merge_base(lua_State *L) lua_pushliteral(L, "ENOTFOUND"); return 2; } - return push_git2_error(L); + return push_git2_error(L, ret); } 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); + int ret; + if ((ret = git_reference_symbolic_create(&ref, repo, + luaL_checkstring(L, 2), + luaL_checkstring(L, 3), + 1, NULL, NULL)) != 0) { + return push_git2_error(L, ret); } git_reference_free(ref); lua_pushboolean(L, 1); @@ -174,10 +181,11 @@ static int L_get_object(lua_State *L) git_odb *odb = to_odb(L, 1); git_odb_object **obj = lua_newuserdata(L, sizeof(*obj)); git_oid oid; + int ret; if (parse_oid(L, 2, &oid) != 0) return 2; - if (git_odb_read(obj, odb, &oid) != 0) - return push_git2_error(L); + if ((ret = git_odb_read(obj, odb, &oid)) != 0) + return push_git2_error(L, ret); lua_pushvalue(L, lua_upvalueindex(1)); lua_setmetatable(L, -2); return 1; @@ -250,10 +258,11 @@ static int L_get_tree_table(lua_State *L) git_oid oid; git_tree *tree; size_t ent; + int ret; if (parse_oid(L, 2, &oid) != 0) return 2; - if (git_tree_lookup(&tree, repo, &oid) != 0) - return push_git2_error(L); + if ((ret = git_tree_lookup(&tree, repo, &oid)) != 0) + return push_git2_error(L, ret); lua_newtable(L); for (ent = 0; ent < git_tree_entrycount(tree); ++ent) { const git_tree_entry *tree_ent = |