#include "git.h" #include #include #include #include namespace GitFS { namespace Git { void throwError(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 }; } [[noreturn]] void ErrorToSystemError(const Error & e) { if (e.err == GIT_ENOTFOUND) { throw NetFS::SystemError(ENOENT); } throw NetFS::SystemError(EIO); } } } 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; } }