diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2021-11-23 20:38:07 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2021-11-23 20:44:36 +0100 |
commit | 39f11bb10f8b0f8797110a6d8ce70b8c975e112f (patch) | |
tree | 9637a899d38963fe2816c9d8d758fc1f62a30b4d /src | |
parent | 61d29440aae4713320083d81df1c9745c638aca0 (diff) |
Storage: reload head before update
Diffstat (limited to 'src')
-rw-r--r-- | src/storage.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
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<Ref> Storage::updateHead(UUID type, UUID id, const Ref & old, const std::function<Ref(const Ref &)> & 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<void(const Ref &)> watcher) const |