summaryrefslogtreecommitdiff
path: root/src/repo.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2025-09-16 18:36:23 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2025-09-16 18:36:23 +0100
commit080ae2e8e02a5fd7d708e50a5c6458ef2a8e3d05 (patch)
tree402a4c492faae8ea42e46eedbbc3ca057171bafc /src/repo.cpp
parentInclude . and .. in readdir results (diff)
downloadnetfs-gitfs-080ae2e8e02a5fd7d708e50a5c6458ef2a8e3d05.tar.bz2
netfs-gitfs-080ae2e8e02a5fd7d708e50a5c6458ef2a8e3d05.tar.xz
netfs-gitfs-080ae2e8e02a5fd7d708e50a5c6458ef2a8e3d05.zip
Single definition of constructing Attr from git things
Adds getattr helpers to handle logic for setting members from entry and blob if available/appropriate, commit, gid, and uid.
Diffstat (limited to 'src/repo.cpp')
-rw-r--r--src/repo.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/repo.cpp b/src/repo.cpp
index 6bf442f..db21e61 100644
--- a/src/repo.cpp
+++ b/src/repo.cpp
@@ -120,16 +120,31 @@ GitFS::Repo::getattr(ReqEnv, const ::std::string path, const ::Ice::Current &)
throw NetFS::SystemError(EINVAL);
}
- NetFS::Attr attr {};
+ update();
if (path == "/") {
+ NetFS::Attr attr = getattr(nullptr, nullptr);
attr.mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
+ return attr;
}
- else {
- update();
- auto entry = Git::treeEntryByPath(tree, path);
+ return getattr(Git::treeEntryByPath(tree, path).get());
+}
+
+NetFS::Attr
+GitFS::Repo::getattr(const git_tree_entry * entry) const
+{
+ if (S_ISREG(git_tree_entry_filemode(entry))) {
+ return getattr(entry, Git::blobLookup(repo, *git_tree_entry_id(entry)).get());
+ }
+ return getattr(entry, nullptr);
+}
+
+NetFS::Attr
+GitFS::Repo::getattr(const git_tree_entry * entry, const git_blob * blob) const
+{
+ NetFS::Attr attr {};
+ if (entry) {
attr << *entry;
- if (S_ISREG(git_tree_entry_filemode(entry.get()))) {
- auto blob = Git::blobLookup(repo, *git_tree_entry_id(entry.get()));
+ if (blob) {
attr << *blob;
}
}