anchor.diff:              <<>>
       end,
       <<"_local/shard-sync-", S/binary, "-", T/binary, F/binary>>.
  +
  +
  +repl(#db{name=DbName, seq_tree=Bt}=Db, #acc{localid=LocalId}=Acc0) ->
  +    erlang:put(io_priority, {internal_repl, DbName}),
  +    Seq = calculate_start_seq(Db, Acc0#acc.target, LocalId),
  +    Acc1 = Acc0#acc{source=Db, seq=Seq},
  +    Fun = fun ?MODULE:changes_enumerator/3,
  +    {ok, _, Acc2} = couch_btree:fold(Bt, Fun, Acc1, [{start_key, Seq + 1}]),
  +    {ok, #acc{seq = LastSeq}} = replicate_batch(Acc2),
  +    {ok, couch_db:count_changes_since(Db, LastSeq)}.
  +
  +
  +calculate_start_seq(Db, #shard{node=Node, name=Name}, LocalId) ->
  +    case couch_db:open_doc(Db, LocalId, [ejson_body]) of
  +    {ok, #doc{body = {SProps}}} ->
  +        Opts = [{user_ctx, ?CTX}, {io_priority, {internal_repl, Name}}],
  +        try rexi_call(Node, {fabric_rpc, open_doc, [Name, LocalId, Opts]}) of
  +        #doc{body = {TProps}} ->
  +            SourceSeq = couch_util:get_value(<<"seq">>, SProps, 0),
  +            TargetSeq = couch_util:get_value(<<"seq">>, TProps, 0),
  +            erlang:min(SourceSeq, TargetSeq)
  +        catch error:{not_found, _} ->
  +            0
  +        end;
  +    {not_found, _} ->
  +        0
  +    end.
   
   
   changes_enumerator(#doc_info{id=DocId}, Reds, #acc{db=Db}=Acc) ->
  
positive.code:     end.
  
  
  repl(#db{name=DbName, seq_tree=Bt}=Db, #acc{localid=LocalId}=Acc0) ->
      erlang:put(io_priority, {internal_repl, DbName}),
      Seq = calculate_start_seq(Db, Acc0#acc.target, LocalId),
      Acc1 = Acc0#acc{source=Db, seq=Seq},
      Fun = fun ?MODULE:changes_enumerator/3,
      {ok, _, Acc2} = couch_btree:fold(Bt, Fun, Acc1, [{start_key, Seq + 1}]),
      {ok, #acc{seq = LastSeq}} = replicate_batch(Acc2),
      {ok, couch_db:count_changes_since(Db, LastSeq)}.
  
  
  make_local_id(#shard{}=Source, #shard{}=Target) ->
      make_local_id(Source, Target, undefined).
  
  
negative.code:     end, Missing).
  
  
  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({#leaf{deleted=IsDel, ptr=SummaryPtr}, FoundRevPath}) ->
                    couch_db:make_doc(Db, Id, IsDel, SummaryPtr, FoundRevPath)
      end, FoundRevs).
  
  
  update_locals(Acc) ->
  