From 080ae2e8e02a5fd7d708e50a5c6458ef2a8e3d05 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 16 Sep 2025 18:36:23 +0100 Subject: 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. --- src/repo.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/repo.cpp') 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; } } -- cgit v1.2.3