Skip to content

Commit

Permalink
Rename doc_to_tree -> to_path and move to couch_doc
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1043453 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
kocolosk committed Dec 8, 2010
1 parent f9e1dc5 commit 4169123
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
15 changes: 2 additions & 13 deletions src/couchdb/couch_db.erl
Expand Up @@ -18,7 +18,7 @@
-export([update_doc/3,update_doc/4,update_docs/4,update_docs/2,update_docs/3,delete_doc/3]).
-export([get_doc_info/2,open_doc/2,open_doc/3,open_doc_revs/4]).
-export([set_revs_limit/2,get_revs_limit/1]).
-export([get_missing_revs/2,name/1,doc_to_tree/1,get_update_seq/1,get_committed_update_seq/1]).
-export([get_missing_revs/2,name/1,get_update_seq/1,get_committed_update_seq/1]).
-export([enum_docs/4,enum_docs_since/5]).
-export([enum_docs_since_reduce_to_count/1,enum_docs_reduce_to_count/1]).
-export([increment_update_seq/1,get_purge_seq/1,purge_docs/2,get_last_purged/1]).
Expand Down Expand Up @@ -558,7 +558,7 @@ prep_and_validate_replicated_updates(Db, [Bucket|RestBuckets], [OldInfo|RestOldI
{ok, #full_doc_info{rev_tree=OldTree}} ->
NewRevTree = lists:foldl(
fun(NewDoc, AccTree) ->
{NewTree, _} = couch_key_tree:merge(AccTree, couch_db:doc_to_tree(NewDoc)),
{NewTree, _} = couch_key_tree:merge(AccTree, couch_doc:to_path(NewDoc)),
NewTree
end,
OldTree, Bucket),
Expand Down Expand Up @@ -1142,17 +1142,6 @@ read_doc(#db{fd=Fd}, Pos) ->
couch_file:pread_term(Fd, Pos).


doc_to_tree(#doc{revs={Start, RevIds}}=Doc) ->
[Tree] = doc_to_tree_simple(Doc, lists:reverse(RevIds)),
{Start - length(RevIds) + 1, Tree}.


doc_to_tree_simple(Doc, [RevId]) ->
[{RevId, Doc, []}];
doc_to_tree_simple(Doc, [RevId | Rest]) ->
[{RevId, ?REV_MISSING, doc_to_tree_simple(Doc, Rest)}].


make_doc(#db{updater_fd = Fd} = Db, Id, Deleted, Bp, RevisionPath) ->
{BodyData, Atts} =
case Bp of
Expand Down
4 changes: 4 additions & 0 deletions src/couchdb/couch_db.hrl
Expand Up @@ -45,6 +45,10 @@
gen_event:sync_notify(error_logger,
{self(), couch_error, {Format, Args}})).

% Tree::term() is really a tree(), but we don't want to require R13B04 yet
-type branch() :: {Key::term(), Value::term(), Tree::term()}.
-type path() :: {Start::pos_integer(), branch()}.
-type tree() :: [branch()]. % sorted by key

-record(rev_info,
{
Expand Down
6 changes: 3 additions & 3 deletions src/couchdb/couch_db_updater.erl
Expand Up @@ -493,7 +493,7 @@ merge_rev_trees(Limit, MergeConflicts, [NewDocs|RestDocsList],
NewRevTree0 = lists:foldl(
fun({Client, #doc{revs={Pos,[_Rev|PrevRevs]}}=NewDoc}, AccTree) ->
if not MergeConflicts ->
case couch_key_tree:merge(AccTree, couch_db:doc_to_tree(NewDoc)) of
case couch_key_tree:merge(AccTree, couch_doc:to_path(NewDoc)) of
{_NewTree, conflicts} when (not OldDeleted) ->
send_result(Client, Id, {Pos-1,PrevRevs}, conflict),
AccTree;
Expand Down Expand Up @@ -524,7 +524,7 @@ merge_rev_trees(Limit, MergeConflicts, [NewDocs|RestDocsList],
NewDoc#doc{revs={OldPos, [OldRev]}}),
NewDoc2 = NewDoc#doc{revs={OldPos + 1, [NewRevId, OldRev]}},
{NewTree2, _} = couch_key_tree:merge(AccTree,
couch_db:doc_to_tree(NewDoc2)),
couch_doc:to_path(NewDoc2)),
% we changed the rev id, this tells the caller we did
send_result(Client, Id, {Pos-1,PrevRevs},
{ok, {OldPos + 1, NewRevId}}),
Expand All @@ -538,7 +538,7 @@ merge_rev_trees(Limit, MergeConflicts, [NewDocs|RestDocsList],
end;
true ->
{NewTree, _} = couch_key_tree:merge(AccTree,
couch_db:doc_to_tree(NewDoc)),
couch_doc:to_path(NewDoc)),
NewTree
end
end,
Expand Down
12 changes: 12 additions & 0 deletions src/couchdb/couch_doc.erl
Expand Up @@ -18,9 +18,21 @@
-export([validate_docid/1]).
-export([doc_from_multi_part_stream/2]).
-export([doc_to_multi_part_stream/5, len_doc_to_multi_part_stream/4]).
-export([to_path/1]).

-include("couch_db.hrl").

-spec to_path(#doc{}) -> path().
to_path(#doc{revs={Start, RevIds}}=Doc) ->
[Branch] = to_branch(Doc, lists:reverse(RevIds)),
{Start - length(RevIds) + 1, Branch}.

-spec to_branch(#doc{}, [RevId::binary()]) -> [branch()].
to_branch(Doc, [RevId]) ->
[{RevId, Doc, []}];
to_branch(Doc, [RevId | Rest]) ->
[{RevId, ?REV_MISSING, to_branch(Doc, Rest)}].

% helpers used by to_json_obj
to_json_rev(0, []) ->
[];
Expand Down
7 changes: 1 addition & 6 deletions src/couchdb/couch_key_tree.erl
Expand Up @@ -16,12 +16,7 @@
-export([map/2, get_all_leafs/1, count_leafs/1, remove_leafs/2,
get_all_leafs_full/1,stem/2,map_leafs/2]).

% Tree::term() is really a tree(), but we don't want to require R13B04 yet
-type branch() :: {Key::term(), Value::term(), Tree::term()}.
-type path() :: {Start::pos_integer(), branch()}.
-type tree() :: [branch()]. % sorted by key

% partial trees arranged by how much they are cut off.
-include("couch_db.hrl").

-spec merge([path()], path()) -> {[path()], conflicts | no_conflicts}.
merge(Paths, Path) ->
Expand Down

0 comments on commit 4169123

Please sign in to comment.