From 39f11bb10f8b0f8797110a6d8ce70b8c975e112f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Tue, 23 Nov 2021 20:38:07 +0100 Subject: Storage: reload head before update --- src/storage.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/storage.cpp b/src/storage.cpp index f68cb68..05b100a 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -821,14 +821,15 @@ bool Storage::replaceHead(UUID type, UUID id, const Ref & old, const Ref & ref) optional Storage::updateHead(UUID type, UUID id, const Ref & old, const std::function & f) { - Ref r = f(old); - if (r.digest() == old.digest() || replaceHead(type, id, old, r)) + auto cur = old.storage().headRef(type, id); + if (!cur) + return nullopt; + + Ref r = f(*cur); + if (r.digest() == cur->digest() || replaceHead(type, id, *cur, r)) return r; - if (auto cur = old.storage().headRef(type, id)) - return updateHead(type, id, *cur, f); - else - return nullopt; + return updateHead(type, id, *cur, f); } int Storage::watchHead(UUID type, UUID wid, const std::function watcher) const -- cgit v1.2.3