diff options
Diffstat (limited to 'src/git.cpp')
-rw-r--r-- | src/git.cpp | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/src/git.cpp b/src/git.cpp index e6aed3f..b242545 100644 --- a/src/git.cpp +++ b/src/git.cpp @@ -2,6 +2,7 @@ #include <array> #include <cerrno> #include <exceptions.h> +#include <numeric.h> #include <sys/stat.h> #include <types.h> @@ -24,7 +25,7 @@ namespace GitFS::Git { } git_oid - OidParse(const std::string_view & str) + oidParse(const std::string_view str) { git_oid oid; gitSafe<NetFS::ConfigError>(git_oid_fromstrn, &oid, str.data(), str.length()); @@ -32,41 +33,44 @@ namespace GitFS::Git { } RepositoryPtr - RepositoryOpenBare(const std::string & path) + 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) + 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) + 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) + 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) + treeEntryByPath(const TreePtr & tree, const std::string & path) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) Skip leading / with C interface 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) + 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) + resolve(const RefPtr & ref) { return gitSafeGet<NetFS::ConfigError>(git_reference_resolve, git_reference_free, ref.get()); } @@ -74,44 +78,44 @@ namespace GitFS::Git { namespace NetFS { Attr & - operator<<(Attr & a, const git_tree_entry & e) + operator<<(Attr & attr, const git_tree_entry & entry) { - a.mode = git_tree_entry_filemode(&e); - if (S_ISDIR(a.mode)) { - a.mode |= S_IXUSR | S_IXGRP | S_IXOTH | S_IRUSR | S_IRGRP | S_IROTH; + attr.mode = git_tree_entry_filemode(&entry); + if (S_ISDIR(attr.mode)) { + attr.mode |= S_IXUSR | S_IXGRP | S_IXOTH | S_IRUSR | S_IRGRP | S_IROTH; } - else if (S_ISLNK(a.mode)) { - a.mode |= S_IRUSR | S_IRGRP | S_IROTH; + else if (S_ISLNK(attr.mode)) { + attr.mode |= S_IRUSR | S_IRGRP | S_IROTH; } else { - a.mode ^= S_IWUSR; + attr.mode ^= S_IWUSR; } - return a; + return attr; } Attr & - operator<<(Attr & a, const git_commit & c) + operator<<(Attr & attr, const git_commit & commit) { - a.ctime = a.atime = a.mtime = git_commit_time(&c); - return a; + attr.ctime = attr.atime = attr.mtime = git_commit_time(&commit); + return attr; } Attr & - operator<<(Attr & a, const git_blob & b) + operator<<(Attr & attr, const git_blob & blob) { - a.blockSize = 1; - a.blocks = a.size = static_cast<decltype(Attr::blocks)>(git_blob_rawsize(&b)); - return a; + attr.blockSize = 1; + attr.blocks = attr.size = safe {git_blob_rawsize(&blob)}; + return attr; } } namespace std { std::ostream & - operator<<(std::ostream & s, const git_oid & oid) + operator<<(std::ostream & strm, const git_oid & oid) { 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; + strm.write(str.data(), GIT_OID_HEXSZ); + return strm; } } |