anchor.diff:          0
       end.
   
  +open_doc_revs(Db, #full_doc_info{id=Id, rev_tree=RevTree}, Revs) ->
  +    {FoundRevs, _} = couch_key_tree:get_key_leafs(RevTree, Revs),
  +    lists:map(fun({{IsDel, SummaryPtr, _Seq}, FoundRevPath}) ->
  +        couch_db:make_doc(Db, Id, IsDel, SummaryPtr, FoundRevPath)
  +    end, FoundRevs).
  +
   iso8601_timestamp() ->
       {_,_,Micro} = Now = os:timestamp(),
       {{Year,Month,Date},{Hour,Minute,Second}} = calendar:now_to_datetime(Now),
  
positive.code:         {error, missing_source}
      end.
  
  go(#db{name=DbName} = Db, #shard{} = Target, LocalId) ->
      erlang:put(io_priority, {internal_repl, DbName}),
      Seq = calculate_start_seq(Db, Target, LocalId),
      Acc0 = #acc{source=Db, target=Target, seq=Seq, localid=LocalId},
      Fun = fun ?MODULE:changes_enumerator/2,
      {ok, AccOut} = couch_db:changes_since(Db, all_docs, Seq, Fun, [], Acc0),
      {ok, _} = replicate_batch(AccOut).
  
  make_local_id(#shard{node=SourceNode}, #shard{node=TargetNode}) ->
  
negative.code:     T = couch_util:encodeBase64Url(couch_util:md5(term_to_binary(TargetNode))),
      <<"_local/shard-sync-", S/binary, "-", T/binary>>.
  
  changes_enumerator(FullDocInfo, _, #acc{revcount = C} = Acc) when C >= 99 ->
      #doc_info{high_seq = Seq} = couch_doc:to_doc_info(FullDocInfo),
      replicate_batch(Acc#acc{seq = Seq, infos = [FullDocInfo | Acc#acc.infos]});
  
  changes_enumerator(FullDocInfo, _, #acc{revcount = C, infos = Infos} = Acc) ->
      #doc_info{high_seq = Seq, revs = Revs} = couch_doc:to_doc_info(FullDocInfo),
      Count = C + length(Revs),
      {ok, Acc#acc{seq = Seq, revcount = Count, infos = [FullDocInfo | Infos]}}.
  
  replicate_batch(#acc{target = #shard{node=Node, name=Name}} = Acc) ->
      case find_missing_revs(Acc) of
      [] ->
          ok;
      Missing ->
          ok = save_on_target(Node, Name, open_docs(Acc, Missing))
      end,
      update_locals(Acc),
      {ok, Acc#acc{revcount=0, infos=[]}}.
  
  find_missing_revs(Acc) ->
      #acc{target = #shard{node=Node, name=Name}, infos = Infos} = Acc,
      IdsRevs = lists:map(fun(FDI) ->
          #doc_info{id=Id, revs=RevInfos} = couch_doc:to_doc_info(FDI),
          {Id, [R || #rev_info{rev=R} <- RevInfos]}
      end, Infos),
      Options = [{io_priority, {internal_repl, Name}}],
      rexi_call(Node, {fabric_rpc, get_missing_revs, [Name, IdsRevs, Options]}).
  
  open_docs(#acc{source=Source, infos=Infos}, Missing) ->
      lists:flatmap(fun({Id, Revs, _}) ->
          FDI = lists:keyfind(Id, #full_doc_info.id, Infos),
          open_doc_revs(Source, FDI, Revs)
      end, Missing).
  
  save_on_target(Node, Name, Docs) ->
  