#include "git.h" #include #include #include #include namespace GitFS { namespace Git { template<> [[noreturn]] void throwError(int err) { switch (err) { case GIT_ENOTFOUND: throw NetFS::SystemError(ENOENT); default: throw NetFS::SystemError(EIO); } } template<> [[noreturn]] void throwError(int) { throw NetFS::ConfigError(); } git_oid OidParse(const std::string_view & str) { git_oid oid; gitSafe(git_oid_fromstrn, &oid, str.data(), str.length()); return oid; } RepositoryPtr RepositoryOpenBare(const std::string & path) { return gitSafeGet( git_repository_open_bare, git_repository_free, path.c_str()); } BlobPtr BlobLookup(const RepositoryPtr & repo, const git_oid & blob) { return gitSafeGet( git_blob_lookup, git_blob_free, repo.get(), &blob); } CommitPtr CommitLookup(const RepositoryPtr & repo, const git_oid & commitId) { return gitSafeGet( git_commit_lookup, git_commit_free, repo.get(), &commitId); } TreePtr TreeLookup(const RepositoryPtr & repo, const git_oid & treeId) { return gitSafeGet( git_tree_lookup, git_tree_free, repo.get(), &treeId); } TreeEntryPtr TreeEntryByPath(const TreePtr & tree, const std::string & path) { return gitSafeGet( git_tree_entry_bypath, git_tree_entry_free, tree.get(), path.c_str() + 1); } } } namespace NetFS { Attr & operator<<(Attr & a, const git_tree_entry & e) { 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; } else if (S_ISLNK(a.mode)) { a.mode |= S_IRUSR | S_IRGRP | S_IROTH; } else { a.mode ^= S_IWUSR; } return a; } Attr & operator<<(Attr & a, const git_commit & c) { a.ctime = a.atime = a.mtime = git_commit_time(&c); return a; } Attr & operator<<(Attr & a, const git_blob & b) { a.blockSize = 1; a.blocks = a.size = git_blob_rawsize(&b); return a; } } 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); return s; } }