summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2019-07-12 09:37:10 -0500
committerPaul J. Davis <paul.joseph.davis@gmail.com>2019-07-31 11:55:30 -0500
commite5fefbe46738dcc8e6a5d2c8adb08a86f2b8f066 (patch)
tree9f645545be5c40c8cfc522c9e28900ec7d8bd31f
parentbf9fa0acb4a9a1c9921c0453bff025abe38b5b24 (diff)
downloadcouchdb-e5fefbe46738dcc8e6a5d2c8adb08a86f2b8f066.tar.gz
Fix revision tree extensions
Previously I was forgetting to keep the previous history around which ended up limiting the revision depth to two.
-rw-r--r--src/fabric/src/fabric2_db.erl19
-rw-r--r--src/fabric/src/fabric2_util.erl9
2 files changed, 20 insertions, 8 deletions
diff --git a/src/fabric/src/fabric2_db.erl b/src/fabric/src/fabric2_db.erl
index 3ea30e70f..43d555c0e 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 fb59d5923..48bf7d143 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},