couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [couchdb] 03/03: Fix revision tree extensions
Date Fri, 12 Jul 2019 14:40:25 GMT
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch prototype/fdb-layer
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit cd24f02fb9e375e4bd5bf542ec35d22fea1c7f0a
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
AuthorDate: Fri Jul 12 09:37:10 2019 -0500

    Fix revision tree extensions
    
    Previously I was forgetting to keep the previous history around which
    ended up limiting the revision depth to two.
---
 src/fabric/src/fabric2_db.erl   | 19 +++++++++++--------
 src/fabric/src/fabric2_util.erl |  9 +++++++++
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/fabric/src/fabric2_db.erl b/src/fabric/src/fabric2_db.erl
index 3ea30e7..43d555c 100644
--- a/src/fabric/src/fabric2_db.erl
+++ b/src/fabric/src/fabric2_db.erl
@@ -1098,16 +1098,19 @@ update_doc_interactive(Db, Doc0, Future, _Options) ->
             end
     end,
 
-    % When recreating a deleted document we want to extend
-    % the winning revision branch rather than create a
-    % new branch. If we did not do this we could be
-    % recreating into a state that previously existed.
     Doc1 = case Winner of
         #{deleted := true} when not Doc0#doc.deleted ->
-            {WinnerRevPos, WinnerRev} = maps:get(rev_id, Winner),
-            WinnerRevPath = maps:get(rev_path, Winner),
-            Doc0#doc{revs = {WinnerRevPos, [WinnerRev | WinnerRevPath]}};
-        _ ->
+            % When recreating a deleted document we want to extend
+            % the winning revision branch rather than create a
+            % new branch. If we did not do this we could be
+            % recreating into a state that previously existed.
+            Doc0#doc{revs = fabric2_util:revinfo_to_revs(Winner)};
+        #{} ->
+            % Otherwise we're extending the target's revision
+            % history with this update
+            Doc0#doc{revs = fabric2_util:revinfo_to_revs(Target)};
+        not_found ->
+            % Creating a new doc means our revs start empty
             Doc0
     end,
 
diff --git a/src/fabric/src/fabric2_util.erl b/src/fabric/src/fabric2_util.erl
index fb59d59..48bf7d1 100644
--- a/src/fabric/src/fabric2_util.erl
+++ b/src/fabric/src/fabric2_util.erl
@@ -14,6 +14,7 @@
 
 
 -export([
+    revinfo_to_revs/1,
     revinfo_to_path/1,
     sort_revinfos/1,
 
@@ -37,6 +38,14 @@
 -include_lib("couch/include/couch_db.hrl").
 
 
+revinfo_to_revs(RevInfo) ->
+    #{
+        rev_id := {RevPos, Rev},
+        rev_path := RevPath
+    } = RevInfo,
+    {RevPos, [Rev | RevPath]}.
+
+
 revinfo_to_path(RevInfo) ->
     #{
         rev_id := {RevPos, Rev},


Mime
View raw message