anchor.diff:  
   flush_trees(_Db, [], AccFlushedTrees) ->
       {ok, lists:reverse(AccFlushedTrees)};
  -flush_trees(#db{fd=Fd}=Db, [Unflushed | RestUnflushed], AccFlushed) ->
  -       Flushed = couch_key_tree:map(
  +flush_trees(#db{fd=Fd}=Db, [InfoUnflushed | RestUnflushed], AccFlushed) ->
  +        #full_doc_info{rev_tree=Unflushed} = InfoUnflushed,
  +        Flushed = couch_key_tree:map(
           fun(_Rev, Value) ->
               case Value of
               #doc{attachments=Atts,deleted=IsDeleted}=Doc ->
  
positive.code:             #doc_info{deleted=false} ->
                  {OldCountAcc + 1, OldDelCountAcc};
              _ ->
                  {OldCountAcc , OldDelCountAcc + 1}
              end;
          (not_found, Acc) ->
              Acc
  
negative.code:                 Value
              end
          end, Unflushed),
      flush_trees(Db, RestUnflushed, [InfoUnflushed#full_doc_info{rev_tree=Flushed} | AccFlushed]).
  
  merge_rev_trees(_NoConflicts, [], [], AccNewInfos, AccSeq) ->
      {ok, lists:reverse(AccNewInfos), AccSeq};
  merge_rev_trees(NoConflicts, [NewDocs|RestDocsList],
          [OldDocInfo|RestOldInfo], AccNewInfos, AccSeq) ->
      #full_doc_info{id=Id,rev_tree=OldTree}=OldDocInfo,
      UpdatesRevTree = lists:foldl(
          fun(NewDoc, AccTree) ->
              couch_key_tree:merge(AccTree, doc_to_tree(NewDoc))
          end,
          [], NewDocs),
      NewRevTree = couch_key_tree:merge(OldTree, UpdatesRevTree),
      if NewRevTree == OldTree ->
          % nothing changed
          merge_rev_trees(NoConflicts, RestDocsList, RestOldInfo, AccNewInfos, AccSeq);
      true ->
          if NoConflicts andalso OldTree /= [] ->
              OldConflicts = couch_key_tree:count_leafs(OldTree),
              NewConflicts = couch_key_tree:count_leafs(NewRevTree),
              if NewConflicts > OldConflicts ->
                  throw(conflict);
              true -> ok
              end;
          true -> ok
          end,
          NewInfo = #full_doc_info{id=Id,update_seq=AccSeq+1,rev_tree=NewRevTree},
          merge_rev_trees(NoConflicts, RestDocsList,RestOldInfo, 
                  [NewInfo|AccNewInfos],AccSeq+1)
      end.
  
  new_index_entries([], DocCount, DelCount, AccById, AccBySeq) ->
      {ok, DocCount, DelCount, AccById, AccBySeq};
  new_index_entries([FullDocInfo|RestInfos], DocCount, DelCount, AccById, AccBySeq) ->
      #doc_info{deleted=Deleted} = DocInfo = couch_doc:to_doc_info(FullDocInfo),
      {DocCount2, DelCount2} =
      if Deleted -> {DocCount, DelCount + 1};
      true -> {DocCount + 1, DelCount} 
      end,
      new_index_entries(RestInfos, DocCount2, DelCount2, [FullDocInfo|AccById], [DocInfo|AccBySeq]).
  
  update_docs_int(Db, DocsList, Options) ->
      #db{
  