summaryrefslogtreecommitdiff
path: root/src/storage.cpp
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2022-08-09 22:11:08 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2022-08-09 22:13:32 +0200
commitc6d01458b4545500a964491c2602da3c3079bfc2 (patch)
tree6c0223c388c30880f813c639e1ad80f8b2b0ebe1 /src/storage.cpp
parent7aa7649e980ff4b335b41eaea34a9a11820c3e2d (diff)
Stored roots lookup
Diffstat (limited to 'src/storage.cpp')
-rw-r--r--src/storage.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/storage.cpp b/src/storage.cpp
index 5784309..c2d097e 100644
--- a/src/storage.cpp
+++ b/src/storage.cpp
@@ -1029,6 +1029,34 @@ Generation Ref::generationLocked() const
return gen;
}
+vector<Digest> Ref::roots() const
+{
+ scoped_lock lock(p->storage->p->rootsCacheLock);
+ return rootsLocked();
+}
+
+vector<Digest> Ref::rootsLocked() const
+{
+ auto it = p->storage->p->rootsCache.find(p->digest);
+ if (it != p->storage->p->rootsCache.end())
+ return it->second;
+
+ vector<Digest> roots;
+ auto prev = previous();
+
+ if (prev.empty()) {
+ roots.push_back(p->digest);
+ } else {
+ for (const auto & p : previous())
+ for (const auto & r : p.rootsLocked())
+ roots.push_back(r);
+
+ std::sort(roots.begin(), roots.end());
+ roots.erase(std::unique(roots.begin(), roots.end()), roots.end());
+ }
+ return roots;
+}
+
template<class S>
RecordT<S>::Item::operator bool() const