You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/01/17 23:06:38 UTC
[04/50] git commit: Add mp_parse to _utils instead of importing from
couch
Add mp_parse to _utils instead of importing from couch
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/commit/b4b3dd1e
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/tree/b4b3dd1e
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/diff/b4b3dd1e
Branch: refs/heads/import
Commit: b4b3dd1e121c3756810a1a3cb0a6e16aef6a4688
Parents: 72fec79
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Wed Jun 13 15:40:41 2012 -0400
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Mar 20 06:02:36 2013 -0500
----------------------------------------------------------------------
src/couch_replicator_api_wrap.erl | 2 +-
src/couch_replicator_utils.erl | 30 ++++++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/b4b3dd1e/src/couch_replicator_api_wrap.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_api_wrap.erl b/src/couch_replicator_api_wrap.erl
index ecf3b8d..5e014b2 100644
--- a/src/couch_replicator_api_wrap.erl
+++ b/src/couch_replicator_api_wrap.erl
@@ -619,7 +619,7 @@ doc_from_multi_part_stream(ContentType, DataFun, Ref) ->
Parser = spawn_link(fun() ->
{<<"--">>, _, _} = couch_httpd:parse_multipart_request(
ContentType, DataFun,
- fun(Next) -> couch_doc:mp_parse_doc1(Next, []) end),
+ fun(Next) -> couch_replicator_utils:mp_parse_doc(Next, []) end),
unlink(Self)
end),
Parser ! {get_doc_bytes, Ref, self()},
http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/b4b3dd1e/src/couch_replicator_utils.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_utils.erl b/src/couch_replicator_utils.erl
index f0f6d41..dfc0244 100644
--- a/src/couch_replicator_utils.erl
+++ b/src/couch_replicator_utils.erl
@@ -17,6 +17,7 @@
-export([start_db_compaction_notifier/2, stop_db_compaction_notifier/1]).
-export([replication_id/2]).
-export([sum_stats/2]).
+-export([mp_parse_doc/2]).
-include_lib("couch/include/couch_db.hrl").
-include_lib("ibrowse/include/ibrowse.hrl").
@@ -387,3 +388,32 @@ sum_stats(#rep_stats{} = S1, #rep_stats{} = S2) ->
doc_write_failures =
S1#rep_stats.doc_write_failures + S2#rep_stats.doc_write_failures
}.
+
+mp_parse_doc({headers, H}, []) ->
+ case couch_util:get_value("content-type", H) of
+ {"application/json", _} ->
+ fun (Next) ->
+ mp_parse_doc(Next, [])
+ end
+ end;
+mp_parse_doc({body, Bytes}, AccBytes) ->
+ fun (Next) ->
+ mp_parse_doc(Next, [Bytes | AccBytes])
+ end;
+mp_parse_doc(body_end, AccBytes) ->
+ receive {get_doc_bytes, Ref, From} ->
+ From ! {doc_bytes, Ref, lists:reverse(AccBytes)}
+ end,
+ fun mp_parse_atts/1.
+
+mp_parse_atts(eof) ->
+ ok;
+mp_parse_atts({headers, _H}) ->
+ fun mp_parse_atts/1;
+mp_parse_atts({body, Bytes}) ->
+ receive {get_bytes, Ref, From} ->
+ From ! {bytes, Ref, Bytes}
+ end,
+ fun mp_parse_atts/1;
+mp_parse_atts(body_end) ->
+ fun mp_parse_atts/1.