anchor.diff:      end.
   
   
  -start_replication(Server, #rep{id = RepId, doc_id = DocId} = Rep, Wait) ->
  +start_replication(Server, #rep{id = RepId} = Rep, Wait) ->
       ok = timer:sleep(Wait * 1000),
       case (catch couch_replicator:async_replicate(Rep)) of
       {ok, _} ->
  -        ok = gen_server:call(Server, {rep_started, RepId}, infinity),
  -        ?LOG_INFO("Document `~s` triggered replication `~s`",
  -            [DocId, pp_rep_id(RepId)]);
  +        ok = gen_server:call(Server, {rep_started, RepId}, infinity);
       Error ->
           ok = gen_server:call(Server, {rep_error, RepId, Error}, infinity)
  +    end.
  +
  +
  +replication_complete(DocId) ->
  +    case ets:lookup(?DOC_TO_REP, DocId) of
  +    [{DocId, RepId}] ->
  +        couch_replicator:cancel_replication(RepId),
  +        true = ets:delete(?REP_TO_STATE, RepId),
  +        true = ets:delete(?DOC_TO_REP, DocId),
  +        ?LOG_INFO("Replication `~s` finished (triggered by document `~s`)",
  +            [pp_rep_id(RepId), DocId]);
  +    _ ->
  +        ok
       end.
   
   
  
positive.code:         [Loop | StartPids]),
      true = ets:delete(?REP_TO_STATE),
      true = ets:delete(?DOC_TO_REP),
      couch_db_update_notifier:stop(Notifier).
  
  
  code_change(_OldVsn, State, _Extra) ->
  
negative.code: update_rep_doc(RepDocId, KVs) ->
      {ok, RepDb} = ensure_rep_db_exists(),
      try
          case couch_db:open_doc(RepDb, RepDocId, []) of
          {ok, LatestRepDoc} ->
              update_rep_doc(RepDb, LatestRepDoc, KVs);
          _ ->
              ok
          end
      catch throw:conflict ->
          % Shouldn't happen, as by default only the role _replicator can
          % update replication documents.
  