summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blob.cpp10
-rw-r--r--src/blob.h2
-rw-r--r--src/dir.cpp8
-rw-r--r--src/dir.h2
-rw-r--r--src/git.cpp124
-rw-r--r--src/git.h100
-rw-r--r--src/main.cpp11
-rw-r--r--src/repo.cpp60
-rw-r--r--src/repoList.cpp15
-rw-r--r--src/repoList.h2
10 files changed, 188 insertions, 146 deletions
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 <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;
}
}
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 <git2.h>
#include <ostream>
-namespace GitFS {
- namespace Git {
- template<typename E>
- [[noreturn]] void throwError(int err);
-
- template<typename E, typename ... P, typename ... A>
- void
- gitSafe(int (*func)(P...), A ... p)
- {
- if (int _giterror = func(p...)) {
- throwError<E>(_giterror);
- }
+namespace GitFS::Git {
+ template<typename E>
+ [[noreturn]] void throwError(int err);
+
+ template<typename E, typename ... P, typename ... A>
+ void
+ gitSafe(int (*func)(P...), A ... p)
+ {
+ if (int _giterror = func(p...)) {
+ throwError<E>(_giterror);
}
+ }
- template<typename T>
- using TPtr = std::shared_ptr<T>;
+ template<typename T>
+ using TPtr = std::shared_ptr<T>;
- template<typename E, typename R, typename ... P, typename ... A>
- auto
- gitSafeGet(int(*get)(R**, P...), void(*release)(R*), A ... p)
- {
- R * r = nullptr;
- gitSafe<E>(get, &r, p...);
- return TPtr<R>(r, release);
- }
+ template<typename E, typename R, typename ... P, typename ... A>
+ auto
+ gitSafeGet(int(*get)(R**, P...), void(*release)(R*), A ... p)
+ {
+ R * r = nullptr;
+ gitSafe<E>(get, &r, p...);
+ return TPtr<R>(r, release);
+ }
- template<typename E, typename R, typename ... P, typename ... A>
- auto
- gitSafeGet(int(*get)(R**, P...), A ... p)
- {
- R * r = nullptr;
- gitSafe<E>(get, &r, p...);
- return r;
- }
+ template<typename E, typename R, typename ... P, typename ... A>
+ auto
+ gitSafeGet(int(*get)(R**, P...), A ... p)
+ {
+ R * r = nullptr;
+ gitSafe<E>(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<std::exception>(
- git_repository_open_bare, git_repository_free, nullptr));
- RepositoryPtr RepositoryOpenBare(const std::string & path);
+ using RepositoryPtr = decltype(gitSafeGet<std::exception>(
+ git_repository_open_bare, git_repository_free, nullptr));
+ RepositoryPtr RepositoryOpenBare(const std::string & path);
- using BlobPtr = decltype(gitSafeGet<std::exception>(
- git_blob_lookup, git_blob_free, nullptr, nullptr));
- BlobPtr BlobLookup(const RepositoryPtr & repo, const git_oid & blob);
+ using BlobPtr = decltype(gitSafeGet<std::exception>(
+ git_blob_lookup, git_blob_free, nullptr, nullptr));
+ BlobPtr BlobLookup(const RepositoryPtr & repo, const git_oid & blob);
- using CommitPtr = decltype(gitSafeGet<std::exception>(
- git_commit_lookup, git_commit_free, nullptr, nullptr));
- CommitPtr CommitLookup(const RepositoryPtr & repo, const git_oid & commitId);
+ using CommitPtr = decltype(gitSafeGet<std::exception>(
+ git_commit_lookup, git_commit_free, nullptr, nullptr));
+ CommitPtr CommitLookup(const RepositoryPtr & repo, const git_oid & commitId);
- using TreePtr = decltype(gitSafeGet<std::exception>(
- git_tree_lookup, git_tree_free, nullptr, nullptr));
- TreePtr TreeLookup(const RepositoryPtr & repo, const git_oid & treeId);
+ using TreePtr = decltype(gitSafeGet<std::exception>(
+ git_tree_lookup, git_tree_free, nullptr, nullptr));
+ TreePtr TreeLookup(const RepositoryPtr & repo, const git_oid & treeId);
- using TreeEntryPtr = decltype(gitSafeGet<std::exception>(
- git_tree_entry_bypath, git_tree_entry_free, nullptr, nullptr));
- TreeEntryPtr TreeEntryByPath(const TreePtr & tree, const std::string & path);
+ using TreeEntryPtr = decltype(gitSafeGet<std::exception>(
+ git_tree_entry_bypath, git_tree_entry_free, nullptr, nullptr));
+ TreeEntryPtr TreeEntryByPath(const TreePtr & tree, const std::string & path);
- using RefPtr = decltype(gitSafeGet<std::exception>(
- 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<std::exception>(
+ 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<NetFS::Service, RepoList>(adp, "Service", ic->getProperties());
+ IceTray::Cube::addObject<NetFS::Service, RepoList>(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<NetFS::DirectoryV2Prx>(ice.adapter->addWithUUID(
- std::make_shared<Directory>(this, path)));
+ std::make_shared<Directory>(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<const ::std::string::value_type *>(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<NetFS::FilePrx>(ice.adapter->addWithUUID(
- std::make_shared<Blob>(this, path)));
+ std::make_shared<Blob>(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 <compileTimeFormatter.h>
-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<NetFS::VolumePrx>(
ice.adapter->addWithUUID(std::make_shared<Repo>(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;