diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-07-22 20:08:39 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-07-22 20:08:39 +0100 |
commit | 6168d85a886286a43b55a0cd6739a1e1e3987d90 (patch) | |
tree | 36360a309a20b6ab344f25ec80b902d2e27fbad5 /src/git.cpp | |
parent | Basically all the core functionality (diff) | |
download | netfs-gitfs-6168d85a886286a43b55a0cd6739a1e1e3987d90.tar.bz2 netfs-gitfs-6168d85a886286a43b55a0cd6739a1e1e3987d90.tar.xz netfs-gitfs-6168d85a886286a43b55a0cd6739a1e1e3987d90.zip |
Unline git helpers and throw NetFS exceptions
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); + } } } |