diff options
Diffstat (limited to 'src/git.cpp')
-rw-r--r-- | src/git.cpp | 124 |
1 files changed, 60 insertions, 64 deletions
diff --git a/src/git.cpp b/src/git.cpp index b169fa2..f3f437e 100644 --- a/src/git.cpp +++ b/src/git.cpp @@ -4,75 +4,71 @@ #include <types.h> #include <sys/stat.h> -namespace GitFS { - namespace Git { - template<> - [[noreturn]] - void - throwError<NetFS::SystemError>(int err) - { - switch (err) { - case GIT_ENOTFOUND: - throw NetFS::SystemError(ENOENT); - default: - throw NetFS::SystemError(EIO); - } +namespace GitFS::Git { + template<> + [[noreturn]] + void + throwError<NetFS::SystemError>(int err) + { + if (err == GIT_ENOTFOUND) { + throw NetFS::SystemError(ENOENT); } + throw NetFS::SystemError(EIO); + } - template<> - [[noreturn]] - void - throwError<NetFS::ConfigError>(int) - { - throw NetFS::ConfigError(); - } + template<> + [[noreturn]] + void + throwError<NetFS::ConfigError>(int) + { + 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; - } + 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()); - } + 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); - } + 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); - } + 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); - } + 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); - } - RefPtr Commitish(const RepositoryPtr & repo, const std::string & name) - { - return gitSafeGet<NetFS::ConfigError>( - git_reference_dwim, git_reference_free, repo.get(), name.c_str()); - } - RefPtr Resolve(const RefPtr & ref) - { - return gitSafeGet<NetFS::ConfigError>( - git_reference_resolve, git_reference_free, ref.get()); - } + 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); + } + RefPtr Commitish(const RepositoryPtr & repo, const std::string & name) + { + return gitSafeGet<NetFS::ConfigError>( + git_reference_dwim, git_reference_free, repo.get(), name.c_str()); + } + RefPtr Resolve(const RefPtr & ref) + { + return gitSafeGet<NetFS::ConfigError>( + git_reference_resolve, git_reference_free, ref.get()); } } @@ -110,9 +106,9 @@ namespace std { std::ostream & operator<<(std::ostream & s, const git_oid & oid) { - char str[GIT_OID_HEXSZ + 1]; - git_oid_tostr(str, sizeof(str), &oid); - s.write(str, GIT_OID_HEXSZ); + std::array<char, GIT_OID_HEXSZ + 1> str {}; + git_oid_tostr(str.data(), str.size(), &oid); + s.write(str.data(), GIT_OID_HEXSZ); return s; } } |