anchor.diff:          end, Unflushed),
       flush_trees(Db, RestUnflushed, [InfoUnflushed#full_doc_info{rev_tree=Flushed} | AccFlushed]).
   
  -merge_rev_trees(_MergeConflicts, [], [], AccNewInfos, AccConflicts, AccSeq) ->
  -    {ok, lists:reverse(AccNewInfos), AccConflicts, AccSeq};
  +merge_rev_trees(_MergeConflicts, [], [], AccNewInfos, AccRemoveSeqs, AccConflicts, AccSeq) ->
  +    {ok, lists:reverse(AccNewInfos), AccRemoveSeqs, AccConflicts, AccSeq};
   merge_rev_trees(MergeConflicts, [NewDocs|RestDocsList],
  -        [OldDocInfo|RestOldInfo], AccNewInfos, AccConflicts, AccSeq) ->
  -    #full_doc_info{id=Id,rev_tree=OldTree,deleted=OldDeleted}=OldDocInfo,
  +        [OldDocInfo|RestOldInfo], AccNewInfos, AccRemoveSeqs, AccConflicts, AccSeq) ->
  +    #full_doc_info{id=Id,rev_tree=OldTree,deleted=OldDeleted,update_seq=OldSeq}
  +            = OldDocInfo,
       {NewRevTree, NewConflicts} = lists:foldl(
           fun(#doc{revs={Pos,[Rev|_]}}=NewDoc, {AccTree, AccConflicts2}) ->
               case couch_key_tree:merge(AccTree, [couch_db:doc_to_tree(NewDoc)]) of
  
positive.code:     if NewRevTree == OldTree ->
          % nothing changed
          merge_rev_trees(MergeConflicts, RestDocsList, RestOldInfo, AccNewInfos,
                  NewConflicts, AccSeq);
      true ->
          % we have updated the document, give it a new seq #
          NewInfo = #full_doc_info{id=Id,update_seq=AccSeq+1,rev_tree=NewRevTree},
          merge_rev_trees(MergeConflicts, RestDocsList,RestOldInfo, 
                  [NewInfo|AccNewInfos], NewConflicts, AccSeq+1)
      end.
  
  new_index_entries([], AccById, AccBySeq) ->
  
negative.code:         Ids, OldDocLookups),
      
      % Merge the new docs into the revision trees.
      {ok, NewDocInfos0, RemoveSeqs, Conflicts, NewSeq} = merge_rev_trees(
              lists:member(merge_conflicts, Options),
              DocsList2, OldDocInfos, [], [], [], LastSeq),
      
      NewDocInfos = stem_full_doc_infos(Db, NewDocInfos0),
      
      % All documents are now ready to write.
      
  