You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by fd...@apache.org on 2010/09/22 21:19:43 UTC

svn commit: r1000148 - in /couchdb/branches/new_replicator/src/couchdb: couch_api_wrap.erl couch_rep.erl couch_rep_reader.erl couch_rep_writer.erl couch_util.erl

Author: fdmanana
Date: Wed Sep 22 19:19:42 2010
New Revision: 1000148

URL: http://svn.apache.org/viewvc?rev=1000148&view=rev
Log:
Merged revision 1000140 from trunk and also dropped couch_api_wrap:encode_doc_id/1 (now in couch_util).

Modified:
    couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl
    couchdb/branches/new_replicator/src/couchdb/couch_rep.erl
    couchdb/branches/new_replicator/src/couchdb/couch_rep_reader.erl
    couchdb/branches/new_replicator/src/couchdb/couch_rep_writer.erl
    couchdb/branches/new_replicator/src/couchdb/couch_util.erl

Modified: couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl?rev=1000148&r1=1000147&r2=1000148&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl Wed Sep 22 19:19:42 2010
@@ -55,7 +55,7 @@
     ]).
 
 -import(couch_util, [
-    url_encode/1,
+    encode_doc_id/1,
     get_value/2,
     get_value/3
     ]).
@@ -259,7 +259,7 @@ update_doc(#httpdb{} = HttpDb, #doc{id =
     end,
     send_req(
         HttpDb,
-        [{method, put}, {path, url_encode(DocId)},
+        [{method, put}, {path, encode_doc_id(DocId)},
             {qs, QArgs}, {headers, Headers}, {body, {SendFun, Len}}],
         fun(Code, _, {Props}) when Code =:= 200 orelse Code =:= 201 ->
                 {ok, couch_doc:parse_rev(get_value(<<"rev">>, Props))};
@@ -533,13 +533,6 @@ json_to_doc_info({Props}) ->
         revs = RevsInfo
     }.
 
-encode_doc_id(<<"_design/", RestId/binary>>) ->
-    "_design/" ++ url_encode(RestId);
-encode_doc_id(<<"_local/", RestId/binary>>) ->
-    "_local/" ++ url_encode(RestId);
-encode_doc_id(DocId) ->
-    url_encode(DocId).
-
 
 bulk_results_to_errors(Docs, {ok, Results}, interactive_edit) ->
     lists:reverse(lists:foldl(

Modified: couchdb/branches/new_replicator/src/couchdb/couch_rep.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_rep.erl?rev=1000148&r1=1000147&r2=1000148&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_rep.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_rep.erl Wed Sep 22 19:19:42 2010
@@ -495,7 +495,7 @@ get_rep_endpoint(UserCtx, <<DbName/binar
 
 open_replication_log(#http_db{}=Db, RepId) ->
     DocId = ?LOCAL_DOC_PREFIX ++ RepId,
-    Req = Db#http_db{resource=couch_util:url_encode(DocId)},
+    Req = Db#http_db{resource=couch_util:encode_doc_id(DocId)},
     case couch_rep_httpc:request(Req) of
     {[{<<"error">>, _}, {<<"reason">>, _}]} ->
         ?LOG_DEBUG("didn't find a replication log for ~s", [Db#http_db.url]),
@@ -703,9 +703,9 @@ ensure_full_commit(Source, RequiredSeq) 
         InstanceStartTime
     end.
 
-update_local_doc(#http_db{} = Db, #doc{id=DocId} = Doc) ->
+update_local_doc(#http_db{} = Db, Doc) ->
     Req = Db#http_db{
-        resource = couch_util:url_encode(DocId),
+        resource = couch_util:encode_doc_id(Doc),
         method = put,
         body = couch_doc:to_json_obj(Doc, [attachments]),
         headers = [{"x-couch-full-commit", "false"} | Db#http_db.headers]

Modified: couchdb/branches/new_replicator/src/couchdb/couch_rep_reader.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_rep_reader.erl?rev=1000148&r1=1000147&r2=1000148&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_rep_reader.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_rep_reader.erl Wed Sep 22 19:19:42 2010
@@ -17,7 +17,7 @@
 
 -export([start_link/4, next/1]).
 
--import(couch_util, [url_encode/1]).
+-import(couch_util, [encode_doc_id/1]).
 
 -define (BUFFER_SIZE, 1000).
 -define (MAX_CONCURRENT_REQUESTS, 100).
@@ -228,7 +228,7 @@ open_doc_revs(#http_db{} = DbS, DocId, R
     %% all this logic just splits up revision lists that are too long for
     %% MochiWeb into multiple requests
     BaseQS = [{revs,true}, {latest,true}, {att_encoding_info,true}],
-    BaseReq = DbS#http_db{resource=url_encode(DocId), qs=BaseQS},
+    BaseReq = DbS#http_db{resource=encode_doc_id(DocId), qs=BaseQS},
     BaseLength = length(couch_rep_httpc:full_url(BaseReq)) + 11, % &open_revs=
 
     {RevLists, _, _} = lists:foldl(fun split_revlist/2,
@@ -251,7 +251,7 @@ open_doc_revs(#http_db{} = DbS, DocId, R
 open_doc(#http_db{} = DbS, DocId) ->
     % get latest rev of the doc
     Req = DbS#http_db{
-        resource=url_encode(DocId),
+        resource=encode_doc_id(DocId),
         qs=[{att_encoding_info, true}]
     },
     case couch_rep_httpc:request(Req) of

Modified: couchdb/branches/new_replicator/src/couchdb/couch_rep_writer.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_rep_writer.erl?rev=1000148&r1=1000147&r2=1000148&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_rep_writer.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_rep_writer.erl Wed Sep 22 19:19:42 2010
@@ -120,7 +120,7 @@ write_multi_part_doc(#http_db{headers=He
         end
     end,
     Request = Db#http_db{
-        resource = couch_util:url_encode(Doc#doc.id),
+        resource = couch_util:encode_doc_id(Doc),
         method = put,
         qs = [{new_edits, false}],
         body = {BodyFun, ok},

Modified: couchdb/branches/new_replicator/src/couchdb/couch_util.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_util.erl?rev=1000148&r1=1000147&r2=1000148&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_util.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_util.erl Wed Sep 22 19:19:42 2010
@@ -26,6 +26,7 @@
 -export([get_value/2, get_value/3]).
 -export([md5/1, md5_init/0, md5_update/2, md5_final/1]).
 -export([url_strip_password/1]).
+-export([encode_doc_id/1]).
 
 -include("couch_db.hrl").
 -include_lib("kernel/include/file.hrl").
@@ -436,3 +437,14 @@ url_strip_password(Url) ->
         "http(s)?://([^:]+):[^@]+@(.*)$",
         "http\\1://\\2:*****@\\3",
         [{return, list}]).
+
+encode_doc_id(#doc{id = Id}) ->
+    encode_doc_id(Id);
+encode_doc_id(Id) when is_list(Id) ->
+    encode_doc_id(?l2b(Id));
+encode_doc_id(<<"_design/", Rest/binary>>) ->
+    "_design/" ++ url_encode(Rest);
+encode_doc_id(<<"_local/", Rest/binary>>) ->
+    "_local/" ++ url_encode(Rest);
+encode_doc_id(Id) ->
+    url_encode(Id).