diff options
Diffstat (limited to 'src/git.cpp')
-rw-r--r-- | src/git.cpp | 62 |
1 files changed, 50 insertions, 12 deletions
diff --git a/src/git.cpp b/src/git.cpp index 850b8b3..045d146 100644 --- a/src/git.cpp +++ b/src/git.cpp @@ -6,25 +6,63 @@ namespace GitFS { namespace Git { + template<> + [[noreturn]] void - throwError(int err) + throwError<NetFS::SystemError>(int err) { -#if LIBGIT2_VER_MINOR >= 28 - const git_error * e = git_error_last(); -#else - const git_error * e = giterr_last(); -#endif - throw Error { err, e->klass, e->message }; + switch (err) { + case GIT_ENOTFOUND: + throw NetFS::SystemError(ENOENT); + default: + throw NetFS::SystemError(EIO); + } } - [[noreturn]] void ErrorToSystemError(const Error & e) + template<> + [[noreturn]] + void + throwError<NetFS::ConfigError>(int) { - if (e.err == GIT_ENOTFOUND) { - throw NetFS::SystemError(ENOENT); - } - throw NetFS::SystemError(EIO); + throw NetFS::ConfigError(); + } + + git_oid OidParse(const std::string_view & str) + { + git_oid oid; + gitSafe<NetFS::ConfigError>(git_oid_fromstrn, &oid, str.data(), str.length()); + return oid; + } + + RepositoryPtr RepositoryOpenBare(const std::string & path) + { + return gitSafeGet<NetFS::ConfigError>( + git_repository_open_bare, git_repository_free, path.c_str()); + } + + BlobPtr BlobLookup(const RepositoryPtr & repo, const git_oid & blob) + { + return gitSafeGet<NetFS::SystemError>( + git_blob_lookup, git_blob_free, repo.get(), &blob); + } + + CommitPtr CommitLookup(const RepositoryPtr & repo, const git_oid & commitId) + { + return gitSafeGet<NetFS::ConfigError>( + git_commit_lookup, git_commit_free, repo.get(), &commitId); } + TreePtr TreeLookup(const RepositoryPtr & repo, const git_oid & treeId) + { + return gitSafeGet<NetFS::SystemError>( + git_tree_lookup, git_tree_free, repo.get(), &treeId); + } + + TreeEntryPtr TreeEntryByPath(const TreePtr & tree, const std::string & path) + { + return gitSafeGet<NetFS::SystemError>( + git_tree_entry_bypath, git_tree_entry_free, tree.get(), path.c_str() + 1); + } } } |