From 97b1aae251a48af7b85eafd76e5284458d42f181 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 27 Oct 2019 12:01:06 +0000 Subject: Fixes for tidy --- src/blob.cpp | 10 +++-- src/blob.h | 2 +- src/dir.cpp | 8 ++-- src/dir.h | 2 +- src/git.cpp | 124 +++++++++++++++++++++++++++---------------------------- src/git.h | 100 ++++++++++++++++++++++---------------------- src/main.cpp | 11 ++++- src/repo.cpp | 60 ++++++++++++++++++++------- src/repoList.cpp | 15 +++++-- src/repoList.h | 2 +- 10 files changed, 188 insertions(+), 146 deletions(-) (limited to 'src') diff --git a/src/blob.cpp b/src/blob.cpp index 188c9c5..59e5f83 100644 --- a/src/blob.cpp +++ b/src/blob.cpp @@ -3,7 +3,7 @@ #include "blob.h" #include "repo.h" -GitFS::Blob::Blob(const Repo * const r, const std::string & path) : +GitFS::Blob::Blob(const Repo * const r, std::string && path) : repo(r), entry(Git::TreeEntryByPath(repo->tree, path)), blob(getBlob()), @@ -17,8 +17,12 @@ GitFS::Blob::getBlob() const { const auto mode = git_tree_entry_filemode(entry.get()); - if (S_ISDIR(mode)) throw NetFS::SystemError(EISDIR); - if (S_ISLNK(mode)) throw NetFS::SystemError(ELOOP); + if (S_ISDIR(mode)) { + throw NetFS::SystemError(EISDIR); + } + if (S_ISLNK(mode)) { + throw NetFS::SystemError(ELOOP); + } return Git::BlobLookup(repo->repo, *git_tree_entry_id(entry.get())); } diff --git a/src/blob.h b/src/blob.h index 335186e..923d53d 100644 --- a/src/blob.h +++ b/src/blob.h @@ -9,7 +9,7 @@ namespace GitFS { class Repo; class Blob : public File { public: - Blob(const Repo * const r, const std::string &); + Blob(const Repo * const r, std::string &&); void close(const ::Ice::Current& current) override; Attr fgetattr(ReqEnv env, const ::Ice::Current& current) override; diff --git a/src/dir.cpp b/src/dir.cpp index f59dd92..78ff83a 100644 --- a/src/dir.cpp +++ b/src/dir.cpp @@ -3,9 +3,9 @@ #include "repo.h" #include "dir.h" -GitFS::Directory::Directory(Repo * const r, const std::string & p) : +GitFS::Directory::Directory(Repo * const r, std::string && p) : repo(r), - path(p), + path(std::move(p)), subTreeCacheRootId({}) { getSubtree(); @@ -21,7 +21,9 @@ GitFS::Directory::getSubtree() const } else { auto e = Git::TreeEntryByPath(repo->tree, path); - if (!S_ISDIR(git_tree_entry_filemode(e.get()))) throw NetFS::SystemError(ENOTDIR); + if (!S_ISDIR(git_tree_entry_filemode(e.get()))) { + throw NetFS::SystemError(ENOTDIR); + } subTreeCache = Git::TreeLookup(repo->repo, *git_tree_entry_id(e.get())); } subTreeCacheRootId = *git_tree_id(repo->tree.get()); diff --git a/src/dir.h b/src/dir.h index 365adcc..51b4bc7 100644 --- a/src/dir.h +++ b/src/dir.h @@ -9,7 +9,7 @@ namespace GitFS { class Repo; class Directory : public DirectoryV2 { public: - Directory(Repo * const r, const std::string &); + Directory(Repo * const r, std::string &&); void close(const ::Ice::Current& current) override; NameList readdir(const ::Ice::Current& current) override; 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 #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); - } +namespace GitFS::Git { + template<> + [[noreturn]] + void + throwError(int err) + { + if (err == GIT_ENOTFOUND) { + throw NetFS::SystemError(ENOENT); } + throw NetFS::SystemError(EIO); + } - template<> - [[noreturn]] - void - throwError(int) - { - throw NetFS::ConfigError(); - } + 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; - } + 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()); - } + 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); - } + 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); - } + 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); - } + 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); - } - RefPtr Commitish(const RepositoryPtr & repo, const std::string & name) - { - return gitSafeGet( - git_reference_dwim, git_reference_free, repo.get(), name.c_str()); - } - RefPtr Resolve(const RefPtr & ref) - { - return gitSafeGet( - git_reference_resolve, git_reference_free, ref.get()); - } + 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); + } + RefPtr Commitish(const RepositoryPtr & repo, const std::string & name) + { + return gitSafeGet( + git_reference_dwim, git_reference_free, repo.get(), name.c_str()); + } + RefPtr Resolve(const RefPtr & ref) + { + return gitSafeGet( + 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 str {}; + git_oid_tostr(str.data(), str.size(), &oid); + s.write(str.data(), GIT_OID_HEXSZ); return s; } } diff --git a/src/git.h b/src/git.h index 068e8cf..90eb4f9 100644 --- a/src/git.h +++ b/src/git.h @@ -5,68 +5,66 @@ #include #include -namespace GitFS { - namespace Git { - template - [[noreturn]] void throwError(int err); - - template - void - gitSafe(int (*func)(P...), A ... p) - { - if (int _giterror = func(p...)) { - throwError(_giterror); - } +namespace GitFS::Git { + template + [[noreturn]] void throwError(int err); + + template + void + gitSafe(int (*func)(P...), A ... p) + { + if (int _giterror = func(p...)) { + throwError(_giterror); } + } - template - using TPtr = std::shared_ptr; + template + using TPtr = std::shared_ptr; - template - auto - gitSafeGet(int(*get)(R**, P...), void(*release)(R*), A ... p) - { - R * r = nullptr; - gitSafe(get, &r, p...); - return TPtr(r, release); - } + template + auto + gitSafeGet(int(*get)(R**, P...), void(*release)(R*), A ... p) + { + R * r = nullptr; + gitSafe(get, &r, p...); + return TPtr(r, release); + } - template - auto - gitSafeGet(int(*get)(R**, P...), A ... p) - { - R * r = nullptr; - gitSafe(get, &r, p...); - return r; - } + template + auto + gitSafeGet(int(*get)(R**, P...), A ... p) + { + R * r = nullptr; + gitSafe(get, &r, p...); + return r; + } - git_oid OidParse(const std::string_view & str); + git_oid OidParse(const std::string_view & str); - using RepositoryPtr = decltype(gitSafeGet( - git_repository_open_bare, git_repository_free, nullptr)); - RepositoryPtr RepositoryOpenBare(const std::string & path); + using RepositoryPtr = decltype(gitSafeGet( + git_repository_open_bare, git_repository_free, nullptr)); + RepositoryPtr RepositoryOpenBare(const std::string & path); - using BlobPtr = decltype(gitSafeGet( - git_blob_lookup, git_blob_free, nullptr, nullptr)); - BlobPtr BlobLookup(const RepositoryPtr & repo, const git_oid & blob); + using BlobPtr = decltype(gitSafeGet( + git_blob_lookup, git_blob_free, nullptr, nullptr)); + BlobPtr BlobLookup(const RepositoryPtr & repo, const git_oid & blob); - using CommitPtr = decltype(gitSafeGet( - git_commit_lookup, git_commit_free, nullptr, nullptr)); - CommitPtr CommitLookup(const RepositoryPtr & repo, const git_oid & commitId); + using CommitPtr = decltype(gitSafeGet( + git_commit_lookup, git_commit_free, nullptr, nullptr)); + CommitPtr CommitLookup(const RepositoryPtr & repo, const git_oid & commitId); - using TreePtr = decltype(gitSafeGet( - git_tree_lookup, git_tree_free, nullptr, nullptr)); - TreePtr TreeLookup(const RepositoryPtr & repo, const git_oid & treeId); + using TreePtr = decltype(gitSafeGet( + git_tree_lookup, git_tree_free, nullptr, nullptr)); + TreePtr TreeLookup(const RepositoryPtr & repo, const git_oid & treeId); - using TreeEntryPtr = decltype(gitSafeGet( - git_tree_entry_bypath, git_tree_entry_free, nullptr, nullptr)); - TreeEntryPtr TreeEntryByPath(const TreePtr & tree, const std::string & path); + using TreeEntryPtr = decltype(gitSafeGet( + git_tree_entry_bypath, git_tree_entry_free, nullptr, nullptr)); + TreeEntryPtr TreeEntryByPath(const TreePtr & tree, const std::string & path); - using RefPtr = decltype(gitSafeGet( - git_reference_dwim, git_reference_free, nullptr, nullptr)); - RefPtr Commitish(const RepositoryPtr & repo, const std::string & name); - RefPtr Resolve(const RefPtr &); - } + using RefPtr = decltype(gitSafeGet( + git_reference_dwim, git_reference_free, nullptr, nullptr)); + RefPtr Commitish(const RepositoryPtr & repo, const std::string & name); + RefPtr Resolve(const RefPtr &); } namespace NetFS { diff --git a/src/main.cpp b/src/main.cpp index 0666a3c..c6b1c90 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,14 +12,21 @@ namespace GitFS { git_libgit2_init(); } - ~Main() + ~Main() override { git_libgit2_shutdown(); } + Main(const Main &) = delete; + Main(Main &&) = delete; + + Main & operator=(const Main &) = delete; + Main & operator=(Main &&) = delete; + void addObjects(const std::string &, const Ice::CommunicatorPtr & ic, const Ice::StringSeq &, const Ice::ObjectAdapterPtr & adp) override { - IceTray::Cube::addObject(adp, "Service", ic->getProperties()); + IceTray::Cube::addObject(adp, "Service", + std::move(ic->getProperties())); } }; diff --git a/src/repo.cpp b/src/repo.cpp index 634fe07..51f5fd1 100644 --- a/src/repo.cpp +++ b/src/repo.cpp @@ -48,17 +48,21 @@ GitFS::Repo::disconnect(const ::Ice::Current& current) NetFS::DirectoryPrxPtr GitFS::Repo::opendir(ReqEnv, ::std::string path, const ::Ice::Current& ice) { - if (path.empty()) throw NetFS::SystemError(EINVAL); + if (path.empty()) { + throw NetFS::SystemError(EINVAL); + } return Ice::uncheckedCast(ice.adapter->addWithUUID( - std::make_shared(this, path))); + std::make_shared(this, std::move(path)))); } NetFS::VFS GitFS::Repo::statfs(ReqEnv, ::std::string path, const ::Ice::Current&) { - if (path.empty()) throw NetFS::SystemError(EINVAL); + if (path.empty()) { + throw NetFS::SystemError(EINVAL); + } return {}; } @@ -67,19 +71,33 @@ GitFS::Repo::statfs(ReqEnv, ::std::string path, const ::Ice::Current&) int GitFS::Repo::access(ReqEnv, ::std::string path, int mode, const ::Ice::Current&) { - if (mode & W_OK) return EACCES; - if (path.empty()) return EINVAL; - if (path == "/") return 0; + if (mode & W_OK) { + return EACCES; + } + if (path.empty()) { + return EINVAL; + } + if (path == "/") { + return 0; + } try { update(); auto e = Git::TreeEntryByPath(tree, path); const auto emode = git_tree_entry_filemode(e.get()); - if (S_ISDIR(emode)) return 0; - if (S_ISLNK(emode)) return 0; - if (mode & R_OK && !(S_IRUSR & emode)) return EACCES; - if (mode & X_OK && !(S_IXUSR & emode)) return EACCES; + if (S_ISDIR(emode)) { + return 0; + } + if (S_ISLNK(emode)) { + return 0; + } + if (mode & R_OK && !(S_IRUSR & emode)) { + return EACCES; + } + if (mode & X_OK && !(S_IXUSR & emode)) { + return EACCES; + } return 0; } @@ -92,7 +110,9 @@ GitFS::Repo::access(ReqEnv, ::std::string path, int mode, const ::Ice::Current&) NetFS::Attr GitFS::Repo::getattr(ReqEnv, ::std::string path, const ::Ice::Current&) { - if (path.empty()) throw NetFS::SystemError(EINVAL); + if (path.empty()) { + throw NetFS::SystemError(EINVAL); + } NetFS::Attr a {}; if (path == "/") { @@ -117,11 +137,15 @@ GitFS::Repo::getattr(ReqEnv, ::std::string path, const ::Ice::Current&) ::std::string GitFS::Repo::readlink(ReqEnv, ::std::string path, const ::Ice::Current&) { - if (path.empty() || path == "/") throw NetFS::SystemError(EINVAL); + if (path.empty() || path == "/") { + throw NetFS::SystemError(EINVAL); + } update(); auto e = Git::TreeEntryByPath(tree, path); - if (!S_ISLNK(git_tree_entry_filemode(e.get()))) throw NetFS::SystemError(EINVAL); + if (!S_ISLNK(git_tree_entry_filemode(e.get()))) { + throw NetFS::SystemError(EINVAL); + } auto blob = Git::BlobLookup(repo, *git_tree_entry_id(e.get())); auto n = static_cast(git_blob_rawcontent(blob.get())); return { n, n + git_blob_rawsize(blob.get()) }; @@ -131,12 +155,16 @@ GitFS::Repo::readlink(ReqEnv, ::std::string path, const ::Ice::Current&) NetFS::FilePrxPtr GitFS::Repo::open(ReqEnv, ::std::string path, int, const ::Ice::Current& ice) { - if (path.empty()) throw NetFS::SystemError(EINVAL); - if (path == "/") throw NetFS::SystemError(EISDIR); + if (path.empty()) { + throw NetFS::SystemError(EINVAL); + } + if (path == "/") { + throw NetFS::SystemError(EISDIR); + } update(); return Ice::uncheckedCast(ice.adapter->addWithUUID( - std::make_shared(this, path))); + std::make_shared(this, std::move(path)))); } diff --git a/src/repoList.cpp b/src/repoList.cpp index 9fc2848..4eb76af 100644 --- a/src/repoList.cpp +++ b/src/repoList.cpp @@ -5,7 +5,8 @@ #include -GitFS::RepoList::RepoList(const Ice::PropertiesPtr & p) : properties(p) +GitFS::RepoList::RepoList(Ice::PropertiesPtr && p) : + properties(std::move(p)) { } @@ -15,14 +16,20 @@ NetFS::VolumePrxPtr GitFS::RepoList::connect(const ::std::string volume, const ::std::string auth, const ::Ice::Current & ice) { - if (volume.empty()) throw NetFS::ConfigError(); + if (volume.empty()) { + throw NetFS::ConfigError(); + } const auto propReader = std::bind(&Ice::Properties::getProperty, properties, std::bind((std::string(*)(const std::string_view &, const std::string_view &)) (&RepoPropertyName::get), volume, std::placeholders::_1)); - if (propReader("gitdir").empty()) throw NetFS::ConfigError(); - if (propReader("authkey") != auth) throw NetFS::AuthError(); + if (propReader("gitdir").empty()) { + throw NetFS::ConfigError(); + } + if (propReader("authkey") != auth) { + throw NetFS::AuthError(); + } return Ice::uncheckedCast( ice.adapter->addWithUUID(std::make_shared(propReader))); } diff --git a/src/repoList.h b/src/repoList.h index 6929e5b..0c2ed4b 100644 --- a/src/repoList.h +++ b/src/repoList.h @@ -7,7 +7,7 @@ namespace GitFS { class RepoList : public NetFS::Service { public: - RepoList(const Ice::PropertiesPtr &); + RepoList(Ice::PropertiesPtr &&); NetFS::VolumePrxPtr connect(const ::std::string volume, const ::std::string auth, const ::Ice::Current& current) override; -- cgit v1.2.3