From d4dc316b05257fb0dd05e8589471e5b968e8663b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 31 Jan 2021 21:59:05 +0100 Subject: Storage: encode digest algorithm alongside hash data --- src/storage.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/storage.cpp b/src/storage.cpp index 4cfa08d..63d3fd3 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -41,11 +41,7 @@ using std::to_string; FilesystemStorage::FilesystemStorage(const fs::path & path): root(path) { - if (!fs::is_directory(path)) - fs::create_directory(path); - - if (!fs::is_directory(path/"objects")) - fs::create_directory(path/"objects"); + fs::create_directories(path/"blake2"/"objects"); if (!fs::is_directory(path/"heads")) fs::create_directory(path/"heads"); @@ -358,9 +354,12 @@ void FilesystemStorage::inotifyWatch() fs::path FilesystemStorage::objectPath(const Digest & digest) const { string name(digest); + size_t delim = name.find('#'); + return root/"objects"/ - fs::path(name.begin(), name.begin() + 2)/ - fs::path(name.begin() + 2, name.end()); + fs::path(name.begin(), name.begin() + delim)/ + fs::path(name.begin() + delim + 1, name.begin() + delim + 3)/ + fs::path(name.begin() + delim + 3, name.end()); } fs::path FilesystemStorage::headPath(UUID type) const @@ -784,21 +783,25 @@ void Storage::watchHead(UUID type, UUID wid, const std::function> RecordT::decode(const S & st, items->emplace_back(name, ZonedTime(value)); else if (type == "u") items->emplace_back(name, UUID(value)); - else if (type == "r.b2") { + else if (type == "r") { if constexpr (is_same_v) { if (auto ref = st.ref(Digest(value))) items->emplace_back(name, ref.value()); @@ -1119,7 +1122,7 @@ vector RecordT::encodeInner() const type = "u"; value = string(*x); } else if (auto x = item.asRef()) { - type = "r.b2"; + type = "r"; value = string(x->digest()); } else if (auto x = item.asUnknown()) { type = x->type; -- cgit v1.2.3