summaryrefslogtreecommitdiff
path: root/src/repo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/repo.cpp')
-rw-r--r--src/repo.cpp67
1 files changed, 35 insertions, 32 deletions
diff --git a/src/repo.cpp b/src/repo.cpp
index 2bced8a..6bf442f 100644
--- a/src/repo.cpp
+++ b/src/repo.cpp
@@ -15,21 +15,23 @@
#include <unistd.h>
#include <utility>
-std::string
-operator/(const std::string & a, const std::string & b)
-{
- return a.empty() ? b : a;
+namespace {
+ std::string
+ operator/(const std::string & value, const std::string & fallback)
+ {
+ return value.empty() ? fallback : value;
+ }
}
GitFS::Repo::Repo(const PropertyReader & properties) :
- repo(Git::RepositoryOpenBare(properties("gitdir"))), commitish(properties("commitish") / "main"), isBranch(false),
+ repo(Git::repositoryOpenBare(properties("gitdir"))), commitish(properties("commitish") / "main"), isBranch(false),
resolvedAt(0), gid(properties("gid") / "root"), uid(properties("uid") / "root")
{
if (commitish.length() == GIT_OID_HEXSZ) {
- commit = Git::CommitLookup(repo, Git::OidParse(commitish));
+ commit = Git::commitLookup(repo, Git::oidParse(commitish));
}
else {
- ref = Git::Commitish(repo, commitish);
+ ref = Git::commitish(repo, commitish);
isBranch = git_reference_is_branch(ref.get());
}
update();
@@ -38,17 +40,18 @@ GitFS::Repo::Repo(const PropertyReader & properties) :
void
GitFS::Repo::update()
{
- if (!commit || (isBranch && ref && resolvedAt < std::time(nullptr) - 30)) {
- commit = Git::CommitLookup(repo, *git_reference_target(Git::Resolve(ref).get()));
+ constexpr time_t MIN_CHECK_TIME = 30;
+ if (!commit || (isBranch && ref && resolvedAt < std::time(nullptr) - MIN_CHECK_TIME)) {
+ commit = Git::commitLookup(repo, *git_reference_target(Git::resolve(ref).get()));
resolvedAt = std::time(nullptr);
}
- tree = Git::TreeLookup(repo, *git_commit_tree_id(commit.get()));
+ tree = Git::treeLookup(repo, *git_commit_tree_id(commit.get()));
}
void
-GitFS::Repo::disconnect(const ::Ice::Current & current)
+GitFS::Repo::disconnect(const ::Ice::Current & ice)
{
- current.adapter->remove(current.id);
+ ice.adapter->remove(ice.id);
}
NetFS::DirectoryPrxPtr
@@ -73,7 +76,7 @@ GitFS::Repo::statfs(ReqEnv, ::std::string path, const ::Ice::Current &)
}
int
-GitFS::Repo::access(ReqEnv, ::std::string path, int mode, const ::Ice::Current &)
+GitFS::Repo::access(ReqEnv, const ::std::string path, const int mode, const ::Ice::Current &)
{
if (mode & W_OK) {
return EACCES;
@@ -87,8 +90,8 @@ GitFS::Repo::access(ReqEnv, ::std::string path, int mode, const ::Ice::Current &
try {
update();
- auto e = Git::TreeEntryByPath(tree, path);
- const auto emode = git_tree_entry_filemode(e.get());
+ auto entry = Git::treeEntryByPath(tree, path);
+ const auto emode = git_tree_entry_filemode(entry.get());
if (S_ISDIR(emode)) {
return 0;
@@ -111,46 +114,46 @@ GitFS::Repo::access(ReqEnv, ::std::string path, int mode, const ::Ice::Current &
}
NetFS::Attr
-GitFS::Repo::getattr(ReqEnv, ::std::string path, const ::Ice::Current &)
+GitFS::Repo::getattr(ReqEnv, const ::std::string path, const ::Ice::Current &)
{
if (path.empty()) {
throw NetFS::SystemError(EINVAL);
}
- NetFS::Attr a {};
+ NetFS::Attr attr {};
if (path == "/") {
- a.mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
+ attr.mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
}
else {
update();
- auto entry = Git::TreeEntryByPath(tree, path);
- a << *entry;
+ auto entry = Git::treeEntryByPath(tree, path);
+ attr << *entry;
if (S_ISREG(git_tree_entry_filemode(entry.get()))) {
- auto blob = Git::BlobLookup(repo, *git_tree_entry_id(entry.get()));
- a << *blob;
+ auto blob = Git::blobLookup(repo, *git_tree_entry_id(entry.get()));
+ attr << *blob;
}
}
- a << *commit;
- a.gid = gid;
- a.uid = uid;
- return a;
+ attr << *commit;
+ attr.gid = gid;
+ attr.uid = uid;
+ return attr;
}
::std::string
-GitFS::Repo::readlink(ReqEnv, ::std::string path, const ::Ice::Current &)
+GitFS::Repo::readlink(ReqEnv, const ::std::string path, const ::Ice::Current &)
{
if (path.empty() || path == "/") {
throw NetFS::SystemError(EINVAL);
}
update();
- auto e = Git::TreeEntryByPath(tree, path);
- if (!S_ISLNK(git_tree_entry_filemode(e.get()))) {
+ auto entry = Git::treeEntryByPath(tree, path);
+ if (!S_ISLNK(git_tree_entry_filemode(entry.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())};
+ auto blob = Git::blobLookup(repo, *git_tree_entry_id(entry.get()));
+ auto content = static_cast<const ::std::string::value_type *>(git_blob_rawcontent(blob.get()));
+ return {content, git_blob_rawsize(blob.get())};
}
NetFS::FilePrxPtr