couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cml...@apache.org
Subject svn commit: r660337 - in /incubator/couchdb/branches/mochijson/src/couchdb: couch_db_update_notifier.erl couch_doc.erl couch_httpd.erl couch_query_servers.erl couch_rep.erl
Date Mon, 26 May 2008 23:41:49 GMT
Author: cmlenz
Date: Mon May 26 16:41:45 2008
New Revision: 660337

URL: http://svn.apache.org/viewvc?rev=660337&view=rev
Log:
mochijson branch: Restart work based on mochijson instead of mochijson2, which seems easier
for now. Still lots of stuff broken, though.

Modified:
    incubator/couchdb/branches/mochijson/src/couchdb/couch_db_update_notifier.erl
    incubator/couchdb/branches/mochijson/src/couchdb/couch_doc.erl
    incubator/couchdb/branches/mochijson/src/couchdb/couch_httpd.erl
    incubator/couchdb/branches/mochijson/src/couchdb/couch_query_servers.erl
    incubator/couchdb/branches/mochijson/src/couchdb/couch_rep.erl

Modified: incubator/couchdb/branches/mochijson/src/couchdb/couch_db_update_notifier.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/mochijson/src/couchdb/couch_db_update_notifier.erl?rev=660337&r1=660336&r2=660337&view=diff
==============================================================================
--- incubator/couchdb/branches/mochijson/src/couchdb/couch_db_update_notifier.erl (original)
+++ incubator/couchdb/branches/mochijson/src/couchdb/couch_db_update_notifier.erl Mon May
26 16:41:45 2008
@@ -52,8 +52,8 @@
     FunAcc2 = Fun(Event, FunAcc),
     {ok, {Fun, FunAcc2}};
 handle_event({EventAtom, DbName}, Port) ->
-    Obj = {struct, [{type, atom_to_list(EventAtom)}, {db, DbName}]},
-    true = port_command(Port, mochijson2:encode(Obj) ++ "\n"),
+    Obj = {struct, [{type, EventAtom}, {db, DbName}]},
+    true = port_command(Port, mochijson:encode(Obj) ++ "\n"),
     {ok, Port}.
 
 handle_call(_Request, State) ->

Modified: incubator/couchdb/branches/mochijson/src/couchdb/couch_doc.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/mochijson/src/couchdb/couch_doc.erl?rev=660337&r1=660336&r2=660337&view=diff
==============================================================================
--- incubator/couchdb/branches/mochijson/src/couchdb/couch_doc.erl (original)
+++ incubator/couchdb/branches/mochijson/src/couchdb/couch_doc.erl Mon May 26 16:41:45 2008
@@ -34,18 +34,18 @@
         case lists:member(revs, Options) of
         false -> [];
         true ->
-            [{"_revs", list_to_tuple(Revs)}]
+            [{"_revs", {array, Revs}}]
         end ++
         lists:map(
             fun({revs_info, RevsInfo}) ->
                 JsonRevsInfo =
                 [{struct, [{rev, Rev}, {status, atom_to_list(Status)}]} ||
                     {Rev, Status} <- RevsInfo],
-                {"_revs_info", list_to_tuple(JsonRevsInfo)};
+                {"_revs_info", {array, JsonRevsInfo}};
             ({conflicts, Conflicts}) ->
-                {"_conflicts", list_to_tuple(Conflicts)};
+                {"_conflicts", {array, Conflicts}};
             ({deleted_conflicts, Conflicts}) ->
-                {"_deleted_conflicts", list_to_tuple(Conflicts)}
+                {"_deleted_conflicts", {array, Conflicts}}
             end, Meta) ++
         case lists:member(attachments, Options) of
         true -> % return the full rev list and the binaries as strings.
@@ -76,10 +76,10 @@
                 _ -> [{"_attachments", {struct, BinProps}}]
             end
         end
-    }.
+        }.
 
 from_json_obj({struct, Props}) ->
-    {struct, JsonBins} = proplists:get_value("_attachments", Props, {struct, []}),
+    {struct,JsonBins} = proplists:get_value("_attachments", Props, {struct, []}),
     Bins = lists:flatmap(fun({Name, {struct, BinProps}}) ->
         case proplists:get_value("stub", BinProps) of
         true ->

Modified: incubator/couchdb/branches/mochijson/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/mochijson/src/couchdb/couch_httpd.erl?rev=660337&r1=660336&r2=660337&view=diff
==============================================================================
--- incubator/couchdb/branches/mochijson/src/couchdb/couch_httpd.erl (original)
+++ incubator/couchdb/branches/mochijson/src/couchdb/couch_httpd.erl Mon May 26 16:41:45 2008
@@ -112,8 +112,8 @@
 
 handle_welcome_request(Req, 'GET') ->
     send_json(Req, {struct, [
-        {"couchdb", <<"Welcome">>},
-        {"version", iolist_to_binary(couch_server:get_version())}
+        {"couchdb", "Welcome"},
+        {"version", couch_server:get_version()}
     ]});
 
 handle_welcome_request(_Req, _Method) ->
@@ -121,13 +121,13 @@
 
 handle_all_dbs_request(Req, 'GET') ->
     {ok, DbNames} = couch_server:all_databases(),
-    send_json(Req, list_to_tuple(DbNames));
+    send_json(Req, {array, DbNames});
 
 handle_all_dbs_request(_Req, _Method) ->
     throw({method_not_allowed, "GET,HEAD"}).
 
 handle_replicate_request(Req, 'POST') ->
-    {struct, Props} = mochijson2:decode(Req:recv_body()),
+    {struct, Props} = mochijson:decode(Req:recv_body()),
     Source = proplists:get_value("source", Props),
     Target = proplists:get_value("target", Props),
     {struct, Options} = proplists:get_value("options", Props, {struct, []}),
@@ -183,7 +183,7 @@
 
 handle_db_request(Req, 'POST', {_DbName, Db, []}) ->
     % TODO: Etag handling
-    Json = mochijson2:decode(Req:recv_body()),
+    Json = mochijson:decode(Req:recv_body()),
     Doc = couch_doc:from_json_obj(Json),
     DocId = couch_util:new_uuid(),
     {ok, NewRev} = couch_db:update_doc(Db, Doc#doc{id=DocId, revs=[]}, []),
@@ -198,7 +198,7 @@
 
 handle_db_request(Req, 'POST', {_DbName, Db, ["_bulk_docs"]}) ->
     Options = [], % put options here.
-    {struct, JsonProps} = mochijson2:decode(Req:recv_body()),
+    {struct, JsonProps} = mochijson:decode(Req:recv_body()),
     DocsArray = proplists:get_value("docs", JsonProps),
     % convert all the doc elements to native docs
     case proplists:get_value("new_edits", JsonProps, true) of
@@ -227,7 +227,7 @@
             Docs, ResultRevs),
         send_json(Req, 201, {struct, [
             {ok, true},
-            {new_revs, list_to_tuple(DocResults)}
+            {new_revs, {array, DocResults}}
         ]});
 
     false ->
@@ -328,11 +328,11 @@
                 [{"rev", Rev}] ++
                 case ConflictRevs of
                     []  ->  [];
-                    _   ->  [{"conflicts", list_to_tuple(ConflictRevs)}]
+                    _   ->  [{"conflicts", {array, ConflictRevs}}]
                 end ++
                 case DelConflictRevs of
                     []  ->  [];
-                    _   ->  [{"deleted_conflicts", list_to_tuple(DelConflictRevs)}]
+                    _   ->  [{"deleted_conflicts", {array, DelConflictRevs}}]
                 end ++
                 case Deleted of
                     true -> [{"deleted", true}];
@@ -379,10 +379,10 @@
     throw({method_not_allowed, "GET,HEAD"});
 
 handle_db_request(Req, 'POST', {_DbName, Db, ["_missing_revs"]}) ->
-    {struct, JsonDocIdRevs} = mochijson2:decode(Req:recv_body()),
+    {struct, JsonDocIdRevs} = mochijson:decode(Req:recv_body()),
     DocIdRevs = [{Id, tuple_to_list(Revs)} || {Id, Revs} <- JsonDocIdRevs],
     {ok, Results} = couch_db:get_missing_revs(Db, DocIdRevs),
-    JsonResults = [{Id, list_to_tuple(Revs)} || {Id, Revs} <- Results],
+    JsonResults = [{Id, {array, Revs}} || {Id, Revs} <- Results],
     send_json(Req, {struct, [
         {missing_revs, {struct, JsonResults}}
     ]});
@@ -403,7 +403,7 @@
         "application/json" -> ok;
         Else -> throw({incorrect_mime_type, Else})
     end,
-    {struct, Props} = mochijson2:decode(Req:recv_body()),
+    {struct, Props} = mochijson:decode(Req:recv_body()),
     Language = proplists:get_value("language", Props, "javascript"),
     MapSrc = proplists:get_value("map", Props),
     case proplists:get_value("reduce", Props, null) of
@@ -510,11 +510,11 @@
                 case Result of
                 {ok, Doc} ->
                     JsonDoc = couch_doc:to_json_obj(Doc, Options),
-                    Json = lists:flatten(mochijson2:encode({struct, [{ok, JsonDoc}]})),
+                    Json = lists:flatten(mochijson:encode({struct, [{ok, JsonDoc}]})),
                     Resp:write_chunk(AccSeparator ++ Json);
                 {{not_found, missing}, RevId} ->
                     Json = {struct, [{"missing", RevId}]},
-                    Json = lists:flatten(mochijson2:encode(Json)),
+                    Json = lists:flatten(mochijson:encode(Json)),
                     Resp:write_chunk(AccSeparator ++ Json)
                 end,
                 "," % AccSeparator now has a comma
@@ -525,7 +525,7 @@
     end;
 
 handle_doc_request(Req, 'PUT', _DbName, Db, DocId) ->
-    Json = {struct, DocProps} = mochijson2:decode(Req:recv_body(?MAX_DOC_SIZE)),
+    Json = {struct, DocProps} = mochijson:decode(Req:recv_body(?MAX_DOC_SIZE)),
     DocRev = proplists:get_value("_rev", DocProps),
     Etag = case Req:get_header_value("If-Match") of
         undefined ->
@@ -601,14 +601,14 @@
         {"", _} ->
             Args;
         {"key", Value} ->
-            JsonKey = mochijson2:decode(Value),
+            JsonKey = mochijson:decode(Value),
             Args#view_query_args{start_key=JsonKey,end_key=JsonKey};
         {"startkey_docid", DocId} ->
             Args#view_query_args{start_docid=DocId};
         {"startkey", Value} ->
-            Args#view_query_args{start_key=mochijson2:decode(Value)};
+            Args#view_query_args{start_key=mochijson:decode(Value)};
         {"endkey", Value} ->
-            Args#view_query_args{end_key=mochijson2:decode(Value)};
+            Args#view_query_args{end_key=mochijson:decode(Value)};
         {"count", Value} ->
             case (catch list_to_integer(Value)) of
             Count when is_integer(Count) ->
@@ -706,10 +706,10 @@
                     [TotalViewCount, Offset2]),
             Resp2:write_chunk(lists:flatten(JsonBegin)),
             JsonObj = {struct, [{id, DocId}, {key, Key}, {value, Value}]},
-            {ok, {AccCount + 1, 0, Resp2, [mochijson2:encode(JsonObj) | AccRevRows]}};
+            {ok, {AccCount + 1, 0, Resp2, [mochijson:encode(JsonObj) | AccRevRows]}};
         {_, AccCount, _, Resp} ->
             JsonObj = {struct, [{id, DocId}, {key, Key}, {value, Value}]},
-            {ok, {AccCount + 1, 0, Resp, [mochijson2:encode(JsonObj), "," | AccRevRows]}}
+            {ok, {AccCount + 1, 0, Resp, [mochijson:encode(JsonObj), "," | AccRevRows]}}
         end
     end,
 
@@ -731,11 +731,11 @@
             JsonBegin = io_lib:format("{\"total_rows\":~w,\"offset\":~w,\"rows\":[\r\n",
                     [TotalViewCount, Offset]),
             JsonObj = {struct, [{id, DocId}, {key, Key}, {value, Value}]},
-            Resp2:write_chunk(lists:flatten(JsonBegin ++ mochijson2:encode(JsonObj))),
+            Resp2:write_chunk(lists:flatten(JsonBegin ++ mochijson:encode(JsonObj))),
             {ok, {AccCount - 1, 0, Resp2, AccRevRows}};
         {_, AccCount, _, Resp} when (AccCount > 0) ->
             JsonObj = {struct, [{"id", DocId}, {"key", Key}, {"value", Value}]},
-            Resp:write_chunk(",\r\n" ++  lists:flatten(mochijson2:encode(JsonObj))),
+            Resp:write_chunk(",\r\n" ++  lists:flatten(mochijson:encode(JsonObj))),
             {ok, {AccCount - 1, 0, Resp, AccRevRows}}
         end
     end,
@@ -751,7 +751,7 @@
         % send empty view
         send_json(Req, 200, {struct, [
             {total_rows, TotalRows},
-            {rows, {}}
+            {rows, {array, []}}
         ]});
     {ok, {_, _, Resp, AccRevRows}} ->
         % end the view
@@ -789,7 +789,7 @@
         {"open_revs", "all"} ->
             Args#doc_query_args{open_revs=all};
         {"open_revs", RevsJsonStr} ->
-            JsonArray = mochijson2:decode(RevsJsonStr),
+            JsonArray = mochijson:decode(RevsJsonStr),
             Args#doc_query_args{open_revs=tuple_to_list(JsonArray)};
         _Else -> % unknown key value pair, ignore.
             Args
@@ -871,7 +871,7 @@
 
 send_json(Req, Code, Headers, Value) ->
     ContentType = negotiate_content_type(Req),
-    Body = mochijson2:encode(Value),
+    Body = mochijson:encode(Value),
     Resp = Req:respond({Code, [{"Content-Type", ContentType}] ++ Headers,
                         Body}),
     {ok, Resp}.

Modified: incubator/couchdb/branches/mochijson/src/couchdb/couch_query_servers.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/mochijson/src/couchdb/couch_query_servers.erl?rev=660337&r1=660336&r2=660337&view=diff
==============================================================================
--- incubator/couchdb/branches/mochijson/src/couchdb/couch_query_servers.erl (original)
+++ incubator/couchdb/branches/mochijson/src/couchdb/couch_query_servers.erl Mon May 26 16:41:45
2008
@@ -50,7 +50,7 @@
     end.
 
 read_json(Port) ->
-    case mochijson2:decode(readline(Port)) of
+    case mochijson:decode(readline(Port)) of
     {struct, [{"log", Msg}]} when is_list(Msg) ->
         % we got a message to log. Log it and continue
         ?LOG_INFO("Query Server Log Message: ~s", [Msg]),
@@ -64,7 +64,7 @@
 
 % send command and get a response.
 prompt(Port, Json) ->
-    writeline(Port, mochijson2:encode(Json)),
+    writeline(Port, mochijson:encode(Json)),
     case read_json(Port) of
     {struct, [{"error", Id}, {"reason", Reason}]} ->
         throw({list_to_atom(Id),Reason});
@@ -79,7 +79,7 @@
     Port = get_linked_port(Lang),
     % send the functions as json strings
     lists:foreach(fun(FunctionSource) ->
-            true = prompt(Port, {"add_fun", FunctionSource})
+            true = prompt(Port, {array, ["add_fun", FunctionSource]})
         end,
         Functions),
     {ok, {Lang, Port}}.
@@ -89,13 +89,13 @@
     Results = lists:map(
         fun(Doc) ->
             Json = couch_doc:to_json_obj(Doc, []),
-            Results = prompt(Port, {"map_doc", Json}),
+            {array, Results} = prompt(Port, {array, ["map_doc", Json]}),
             % the results are a json array of function map yields like this:
             % {FunResults1, FunResults2 ...}
             % where funresults is are json arrays of key value pairs:
             % {{Key1, Value1}, {Key2, Value2}}
             % Convert to real lists, execept the key, value pairs
-            [tuple_to_list(FunResult) || FunResult <- tuple_to_list(Results)]
+            [FunResult || FunResult <- Results]
         end,
         Docs),
     {ok, Results}.
@@ -110,7 +110,7 @@
     case gen_server:call(couch_query_servers, {get_port, Lang}) of
     {ok, Port0} ->
         link(Port0),
-        true = prompt(Port0, {"reset"}),
+        true = prompt(Port0, {array, ["reset"]}),
         Port0;
     {empty, Cmd} ->
         ?LOG_INFO("Spawning new ~s instance.", [Lang]),
@@ -149,7 +149,7 @@
     Results = lists:zipwith(
         fun(FunSrc, Values) ->
             {true, {Result}} = 
-                prompt(Port, {"combine", {FunSrc}, list_to_tuple(Values)}),
+                prompt(Port, {array, ["combine", {array, FunSrc}, {array, Values}]}),
             Result
         end, RedSrcs, Grouped),
         
@@ -160,10 +160,11 @@
     {ok, []};
 reduce(Lang, RedSrcs, KVs) ->
     Port = get_linked_port(Lang),
-    {true, Results} = prompt(Port, 
-            {"reduce", list_to_tuple(RedSrcs), list_to_tuple(KVs)}),
+    {true, {array, Results}} = prompt(Port, {array, [
+        "reduce", {array, RedSrcs}, {array, KVs}
+    ]}),
     return_linked_port(Lang, Port),
-    {ok, tuple_to_list(Results)}.
+    {ok, Results}.
 
 
 init(QueryServerList) ->

Modified: incubator/couchdb/branches/mochijson/src/couchdb/couch_rep.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/mochijson/src/couchdb/couch_rep.erl?rev=660337&r1=660336&r2=660337&view=diff
==============================================================================
--- incubator/couchdb/branches/mochijson/src/couchdb/couch_rep.erl (original)
+++ incubator/couchdb/branches/mochijson/src/couchdb/couch_rep.erl Mon May 26 16:41:45 2008
@@ -71,8 +71,8 @@
         end
     end,
 
-    #doc{body={struct, OldRepHistoryProps}} = RepRecSrc,
-    #doc{body={struct, OldRepHistoryPropsTrg}} = RepRecTgt,
+    #doc{body={struct,OldRepHistoryProps}} = RepRecSrc,
+    #doc{body={struct,OldRepHistoryPropsTrg}} = RepRecTgt,
 
     SeqNum =
     case OldRepHistoryProps == OldRepHistoryPropsTrg of
@@ -105,7 +105,7 @@
             {struct,
                 [{"session_id", couch_util:new_uuid()},
                 {"source_last_seq", NewSeqNum},
-                {"history", list_to_tuple(lists:sublist(HistEntries, 50))}]},
+                {"history", {array, lists:sublist(HistEntries, 50)}}]},
 
         {ok, _} = update_doc(DbSrc, RepRecSrc#doc{body=NewRepHistory}, []),
         {ok, _} = update_doc(DbTgt, RepRecTgt#doc{body=NewRepHistory}, []),
@@ -211,12 +211,12 @@
     [] ->
         {Url, []};
     _ ->
-        {Url, [], "application/json; charset=utf-8", lists:flatten(mochijson2:encode(JsonBody))}
+        {Url, [], "application/json; charset=utf-8", lists:flatten(mochijson:encode(JsonBody))}
     end,
     {ok, {{_, ResponseCode,_},_Headers, ResponseBody}} = http:request(Action, Request, [],
[]),
     if
     ResponseCode >= 200, ResponseCode < 500 ->
-        mochijson2:decode(ResponseBody)
+        mochijson:decode(ResponseBody)
     end.
 
 enum_docs0(_InFun, [], Acc) ->
@@ -260,7 +260,7 @@
 
 get_missing_revs(DbUrl, DocIdRevsList) when is_list(DbUrl) ->
     JsonDocIdRevsList = {struct,
-        [{Id, list_to_tuple(RevList)} || {Id, RevList} <- DocIdRevsList]},
+        [{Id, {array, RevList}} || {Id, RevList} <- DocIdRevsList]},
     {struct, ResponseMembers} =
     do_http_request(DbUrl ++ "_missing_revs",
         post, JsonDocIdRevsList),
@@ -284,7 +284,7 @@
 save_docs(DbUrl, Docs, []) when is_list(DbUrl) ->
     JsonDocs = [couch_doc:to_json_obj(Doc, [revs,attachments]) || Doc <- Docs],
     {struct, Returned} =
-        do_http_request(DbUrl ++ "_bulk_docs", post, {struct, [{new_edits, false}, {docs,
list_to_tuple(JsonDocs)}]}),
+        do_http_request(DbUrl ++ "_bulk_docs", post, {struct, [{new_edits, false}, {docs,
{array, JsonDocs}}]}),
     true = proplists:get_value("ok", Returned),
     ok;
 save_docs(Db, Docs, Options) ->
@@ -308,7 +308,7 @@
             % latest is only option right now
             "latest=true"
         end, Options),
-    RevsQueryStrs = lists:flatten(mochijson2:encode(list_to_tuple(Revs))),
+    RevsQueryStrs = lists:flatten(mochijson:encode({array, Revs})),
     Url = DbUrl ++ DocId ++ "?" ++ couch_util:implode(["revs=true", "attachments=true", "open_revs="
++ RevsQueryStrs ] ++ QueryOptionStrs, "&"),
     JsonResults = do_http_request(Url, get, []),
     Results =



Mime
View raw message