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/30 14:31:04 UTC
svn commit: r1003040 - /couchdb/branches/new_replicator/src/couchdb/
Author: fdmanana
Date: Thu Sep 30 12:31:03 2010
New Revision: 1003040
URL: http://svn.apache.org/viewvc?rev=1003040&view=rev
Log:
Removing ?getv macros.
With OTP releases up to R13B03 it's not possible to define macro functions with the same name and different arities.
(Only allowed in R13B04 and R14).
Modified:
couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl
couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl
couchdb/branches/new_replicator/src/couchdb/couch_btree.erl
couchdb/branches/new_replicator/src/couchdb/couch_db.erl
couchdb/branches/new_replicator/src/couchdb/couch_db.hrl
couchdb/branches/new_replicator/src/couchdb/couch_doc.erl
couchdb/branches/new_replicator/src/couchdb/couch_httpd.erl
couchdb/branches/new_replicator/src/couchdb/couch_httpd_auth.erl
couchdb/branches/new_replicator/src/couchdb/couch_httpd_db.erl
couchdb/branches/new_replicator/src/couchdb/couch_httpd_oauth.erl
couchdb/branches/new_replicator/src/couchdb/couch_httpd_rewrite.erl
couchdb/branches/new_replicator/src/couchdb/couch_httpd_show.erl
couchdb/branches/new_replicator/src/couchdb/couch_httpd_stats_handlers.erl
couchdb/branches/new_replicator/src/couchdb/couch_httpd_view.erl
couchdb/branches/new_replicator/src/couchdb/couch_native_process.erl
couchdb/branches/new_replicator/src/couchdb/couch_query_servers.erl
couchdb/branches/new_replicator/src/couchdb/couch_rep.erl
couchdb/branches/new_replicator/src/couchdb/couch_rep_changes_feed.erl
couchdb/branches/new_replicator/src/couchdb/couch_rep_httpc.erl
couchdb/branches/new_replicator/src/couchdb/couch_rep_missing_revs.erl
couchdb/branches/new_replicator/src/couchdb/couch_rep_writer.erl
couchdb/branches/new_replicator/src/couchdb/couch_replicate.erl
couchdb/branches/new_replicator/src/couchdb/couch_replicator_utils.erl
couchdb/branches/new_replicator/src/couchdb/couch_server.erl
couchdb/branches/new_replicator/src/couchdb/couch_stream.erl
couchdb/branches/new_replicator/src/couchdb/couch_view.erl
couchdb/branches/new_replicator/src/couchdb/couch_view_group.erl
couchdb/branches/new_replicator/src/couchdb/couch_view_updater.erl
couchdb/branches/new_replicator/src/couchdb/couch_work_queue.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=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl Thu Sep 30 12:31:03 2010
@@ -55,7 +55,9 @@
]).
-import(couch_util, [
- encode_doc_id/1
+ encode_doc_id/1,
+ get_value/2,
+ get_value/3
]).
@@ -128,7 +130,7 @@ ensure_full_commit(#httpdb{} = Db) ->
[{method, post}, {path, "_ensure_full_commit"},
{headers, [{"Content-Type", "application/json"}]}],
fun(201, _, {Props}) ->
- {ok, ?getv(<<"instance_start_time">>, Props)}
+ {ok, get_value(<<"instance_start_time">>, Props)}
end);
ensure_full_commit(Db) ->
couch_db:ensure_full_commit(Db).
@@ -142,10 +144,10 @@ get_missing_revs(#httpdb{} = Db, IdRevs)
fun(200, _, {Props}) ->
ConvertToNativeFun = fun({Id, {Result}}) ->
MissingRevs = couch_doc:parse_revs(
- ?getv(<<"missing">>, Result)
+ get_value(<<"missing">>, Result)
),
PossibleAncestors = couch_doc:parse_revs(
- ?getv(<<"possible_ancestors">>, Result, [])
+ get_value(<<"possible_ancestors">>, Result, [])
),
{Id, MissingRevs, PossibleAncestors}
end,
@@ -176,7 +178,7 @@ open_doc_revs(#httpdb{} = HttpDb, Id, Re
{headers, [{"accept", "multipart/mixed"}]}],
fun(200, Headers, StreamDataFun) ->
couch_httpd:parse_multipart_request(
- ?getv("Content-Type", Headers),
+ get_value("Content-Type", Headers),
StreamDataFun,
fun(Ev) -> mp_parse_mixed(Ev) end)
end),
@@ -195,7 +197,7 @@ open_doc(#httpdb{} = Db, Id, Options) ->
fun(200, _, Body) ->
{ok, couch_doc:from_json_obj(Body)};
(_, _, {Props}) ->
- {error, ?getv(<<"error">>, Props)}
+ {error, get_value(<<"error">>, Props)}
end);
open_doc(Db, Id, Options) ->
couch_db:open_doc(Db, Id, Options).
@@ -260,9 +262,9 @@ update_doc(#httpdb{} = HttpDb, #doc{id =
[{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(?getv(<<"rev">>, Props))};
+ {ok, couch_doc:parse_rev(get_value(<<"rev">>, Props))};
(_, _, {Props}) ->
- {error, ?getv(<<"error">>, Props)}
+ {error, get_value(<<"error">>, Props)}
end);
update_doc(Db, Doc, Options, Type) ->
try
@@ -310,7 +312,7 @@ changes_since(#httpdb{} = HttpDb, Style,
[{path, "_changes"}, {qs, QArgs},
{ibrowse_options, [{stream_to, {self(), once}}]}],
fun(200, _, DataStreamFun) ->
- case ?getv(continuous, Options, false) of
+ case couch_util:get_value(continuous, Options, false) of
true ->
continuous_changes(DataStreamFun, UserFun);
false ->
@@ -324,8 +326,8 @@ changes_since(Db, Style, StartSeq, UserF
Args = #changes_args{
style = Style,
since = StartSeq,
- filter = ?b2l(?getv(filter, Options, <<>>)),
- feed = case ?getv(continuous, Options, false) of
+ filter = ?b2l(get_value(filter, Options, <<>>)),
+ feed = case get_value(continuous, Options, false) of
true ->
"continuous";
false ->
@@ -333,7 +335,7 @@ changes_since(Db, Style, StartSeq, UserF
end,
timeout = infinity
},
- QueryParams = ?getv(query_params, Options, {[]}),
+ QueryParams = get_value(query_params, Options, {[]}),
Req = changes_json_req(Db, Args#changes_args.filter, QueryParams),
ChangesFeedFun = couch_changes:handle_changes(Args, {json_req, Req}, Db),
ChangesFeedFun(fun({change, Change, _}, _) ->
@@ -346,11 +348,11 @@ changes_since(Db, Style, StartSeq, UserF
% internal functions
changes_q_args(BaseQS, Options) ->
- case ?getv(filter, Options) of
+ case get_value(filter, Options) of
undefined ->
BaseQS;
FilterName ->
- {Params} = ?getv(query_params, Options, {[]}),
+ {Params} = get_value(query_params, Options, {[]}),
[{"filter", ?b2l(FilterName)} | lists:foldl(
fun({K, V}, QSAcc) ->
Ks = couch_util:to_list(K),
@@ -363,7 +365,7 @@ changes_q_args(BaseQS, Options) ->
end,
BaseQS, Params)]
end ++
- case ?getv(continuous, Options, false) of
+ case get_value(continuous, Options, false) of
false ->
[{"feed", "normal"}];
true ->
@@ -408,7 +410,7 @@ receive_docs(Streamer, UserFun, UserAcc)
Streamer ! {get_headers, self()},
receive
{headers, Headers} ->
- case ?getv("content-type", Headers) of
+ case get_value("content-type", Headers) of
{"multipart/related", _} = ContentType ->
case couch_doc:doc_from_multi_part_stream(ContentType,
fun() -> receive_doc_data(Streamer) end) of
@@ -423,7 +425,7 @@ receive_docs(Streamer, UserFun, UserAcc)
receive_docs(Streamer, UserFun, UserAcc2);
{"application/json", [{"error","true"}]} ->
{ErrorProps} = ?JSON_DECODE(receive_all(Streamer, [])),
- Rev = ?getv(<<"missing">>, ErrorProps),
+ Rev = get_value(<<"missing">>, ErrorProps),
Result = {{not_found, missing}, couch_doc:parse_rev(Rev)},
UserAcc2 = UserFun(Result, UserAcc),
receive_docs(Streamer, UserFun, UserAcc2)
@@ -521,13 +523,13 @@ parse_changes_line(object_start, UserFun
json_to_doc_info({Props}) ->
RevsInfo = lists:map(
fun({Change}) ->
- Rev = couch_doc:parse_rev(?getv(<<"rev">>, Change)),
- Del = (true =:= ?getv(<<"deleted">>, Change)),
+ Rev = couch_doc:parse_rev(get_value(<<"rev">>, Change)),
+ Del = (true =:= get_value(<<"deleted">>, Change)),
#rev_info{rev=Rev, deleted=Del}
- end, ?getv(<<"changes">>, Props)),
+ end, get_value(<<"changes">>, Props)),
#doc_info{
- id = ?getv(<<"id">>, Props),
- high_seq = ?getv(<<"seq">>, Props),
+ id = get_value(<<"id">>, Props),
+ high_seq = get_value(<<"seq">>, Props),
revs = RevsInfo
}.
@@ -556,11 +558,11 @@ bulk_results_to_errors(_Docs, {aborted,
bulk_results_to_errors(_Docs, Results, remote) ->
lists:reverse(lists:foldl(
fun({Props}, Acc) ->
- case ?getv(<<"error">>, Props, ?getv(error, Props)) of
+ case get_value(<<"error">>, Props, get_value(error, Props)) of
undefined ->
Acc;
Error ->
- Id = ?getv(<<"id">>, Props, ?getv(id, Props)),
+ Id = get_value(<<"id">>, Props, get_value(id, Props)),
[ {[{<<"id">>, Id}, {<<"error">>, Error}]} | Acc ]
end
end,
Modified: couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl Thu Sep 30 12:31:03 2010
@@ -19,6 +19,11 @@
-export([httpdb_setup/1]).
-export([send_req/3]).
+-import(couch_util, [
+ get_value/2,
+ get_value/3
+ ]).
+
httpdb_setup(#httpdb{} = Db) ->
% TODO: setup Ibrowse proxy options
@@ -26,12 +31,12 @@ httpdb_setup(#httpdb{} = Db) ->
send_req(#httpdb{headers = BaseHeaders} = HttpDb, Params, Callback) ->
- Method = ?getv(method, Params, get),
- Headers = ?getv(headers, Params, []),
- Body = ?getv(body, Params, []),
+ Method = get_value(method, Params, get),
+ Headers = get_value(headers, Params, []),
+ Body = get_value(body, Params, []),
IbrowseOptions = [
{response_format, binary}, {inactivity_timeout, HttpDb#httpdb.timeout}
- | ?getv(ibrowse_options, Params, []) ++ HttpDb#httpdb.proxy_options
+ | get_value(ibrowse_options, Params, []) ++ HttpDb#httpdb.proxy_options
],
Headers2 = oauth_header(HttpDb, Params) ++ BaseHeaders ++ Headers,
Url = full_url(HttpDb, Params),
@@ -102,7 +107,7 @@ report_error(Worker, #httpdb{timeout = T
report_error(Worker, HttpDb, Params, {timeout, Timeout});
report_error(Worker, HttpDb, Params, Error) ->
- Method = string:to_upper(atom_to_list(?getv(method, Params, get))),
+ Method = string:to_upper(atom_to_list(get_value(method, Params, get))),
Url = couch_util:url_strip_password(full_url(HttpDb, Params)),
do_report_error(Url, Method, Error),
stop_worker(Worker),
@@ -137,8 +142,8 @@ stream_data_self(HttpDb, Params, Worker,
full_url(#httpdb{url = BaseUrl}, Params) ->
- Path = ?getv(path, Params, []),
- QueryArgs = ?getv(qs, Params, []),
+ Path = get_value(path, Params, []),
+ QueryArgs = get_value(qs, Params, []),
BaseUrl ++ Path ++ query_args_to_string(QueryArgs, []).
@@ -158,15 +163,15 @@ oauth_header(#httpdb{url = BaseUrl, oaut
OAuth#oauth.consumer_secret,
OAuth#oauth.signature_method
},
- Method = case ?getv(method, ConnParams, get) of
+ Method = case get_value(method, ConnParams, get) of
get -> "GET";
post -> "POST";
put -> "PUT";
head -> "HEAD"
end,
OAuthParams = oauth:signed_params(Method,
- BaseUrl ++ ?getv(path, ConnParams, []),
- ?getv(qs, ConnParams, []),
+ BaseUrl ++ get_value(path, ConnParams, []),
+ get_value(qs, ConnParams, []),
Consumer, OAuth#oauth.token, OAuth#oauth.token_secret),
[{"Authorization",
"OAuth " ++ oauth_uri:params_to_header_string(OAuthParams)}].
Modified: couchdb/branches/new_replicator/src/couchdb/couch_btree.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_btree.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_btree.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_btree.erl Thu Sep 30 12:31:03 2010
@@ -16,7 +16,6 @@
-export([fold/4, full_reduce/1, final_reduce/2,foldl/3,foldl/4]).
-export([fold_reduce/4, lookup/2, get_state/1, set_options/2]).
--include("couch_db.hrl").
-define(CHUNK_THRESHOLD, 16#4ff).
-record(btree,
@@ -71,10 +70,10 @@ final_reduce(Reduce, {KVs, Reductions})
final_reduce(Reduce, {[], [Red | Reductions]}).
fold_reduce(#btree{root=Root}=Bt, Fun, Acc, Options) ->
- Dir = ?getv(dir, Options, fwd),
- StartKey = ?getv(start_key, Options),
- EndKey = ?getv(end_key, Options),
- KeyGroupFun = ?getv(key_group_fun, Options, fun(_,_) -> true end),
+ Dir = couch_util:get_value(dir, Options, fwd),
+ StartKey = couch_util:get_value(start_key, Options),
+ EndKey = couch_util:get_value(end_key, Options),
+ KeyGroupFun = couch_util:get_value(key_group_fun, Options, fun(_,_) -> true end),
{StartKey2, EndKey2} =
case Dir of
rev -> {EndKey, StartKey};
@@ -108,9 +107,9 @@ convert_fun_arity(Fun) when is_function(
Fun. % Already arity 3
make_key_in_end_range_function(#btree{less=Less}, fwd, Options) ->
- case ?getv(end_key_gt, Options) of
+ case couch_util:get_value(end_key_gt, Options) of
undefined ->
- case ?getv(end_key, Options) of
+ case couch_util:get_value(end_key, Options) of
undefined ->
fun(_Key) -> true end;
LastKey ->
@@ -120,9 +119,9 @@ make_key_in_end_range_function(#btree{le
fun(Key) -> Less(Key, EndKey) end
end;
make_key_in_end_range_function(#btree{less=Less}, rev, Options) ->
- case ?getv(end_key_gt, Options) of
+ case couch_util:get_value(end_key_gt, Options) of
undefined ->
- case ?getv(end_key, Options) of
+ case couch_util:get_value(end_key, Options) of
undefined ->
fun(_Key) -> true end;
LastKey ->
@@ -143,10 +142,10 @@ foldl(Bt, Fun, Acc, Options) ->
fold(#btree{root=nil}, _Fun, Acc, _Options) ->
{ok, {[], []}, Acc};
fold(#btree{root=Root}=Bt, Fun, Acc, Options) ->
- Dir = ?getv(dir, Options, fwd),
+ Dir = couch_util:get_value(dir, Options, fwd),
InRange = make_key_in_end_range_function(Bt, Dir, Options),
Result =
- case ?getv(start_key, Options) of
+ case couch_util:get_value(start_key, Options) of
undefined ->
stream_node(Bt, [], Bt#btree.root, InRange, Dir,
convert_fun_arity(Fun), Acc);
Modified: couchdb/branches/new_replicator/src/couchdb/couch_db.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_db.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_db.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_db.erl Thu Sep 30 12:31:03 2010
@@ -270,8 +270,8 @@ get_design_docs(#db{fulldocinfo_by_id_bt
check_is_admin(#db{user_ctx=#user_ctx{name=Name,roles=Roles}}=Db) ->
{Admins} = get_admins(Db),
- AdminRoles = [<<"_admin">> | ?getv(<<"roles">>, Admins, [])],
- AdminNames = ?getv(<<"names">>, Admins,[]),
+ AdminRoles = [<<"_admin">> | couch_util:get_value(<<"roles">>, Admins, [])],
+ AdminNames = couch_util:get_value(<<"names">>, Admins,[]),
case AdminRoles -- Roles of
AdminRoles -> % same list, not an admin role
case AdminNames -- [Name] of
@@ -289,9 +289,9 @@ check_is_reader(#db{user_ctx=#user_ctx{n
ok -> ok;
_ ->
{Readers} = get_readers(Db),
- ReaderRoles = ?getv(<<"roles">>, Readers,[]),
+ ReaderRoles = couch_util:get_value(<<"roles">>, Readers,[]),
WithAdminRoles = [<<"_admin">> | ReaderRoles],
- ReaderNames = ?getv(<<"names">>, Readers,[]),
+ ReaderNames = couch_util:get_value(<<"names">>, Readers,[]),
case ReaderRoles ++ ReaderNames of
[] -> ok; % no readers == public access
_Else ->
@@ -311,10 +311,10 @@ check_is_reader(#db{user_ctx=#user_ctx{n
end.
get_admins(#db{security=SecProps}) ->
- ?getv(<<"admins">>, SecProps, {[]}).
+ couch_util:get_value(<<"admins">>, SecProps, {[]}).
get_readers(#db{security=SecProps}) ->
- ?getv(<<"readers">>, SecProps, {[]}).
+ couch_util:get_value(<<"readers">>, SecProps, {[]}).
get_security(#db{security=SecProps}) ->
{SecProps}.
@@ -329,21 +329,21 @@ set_security(_, _) ->
throw(bad_request).
validate_security_object(SecProps) ->
- Admins = ?getv(<<"admins">>, SecProps, {[]}),
- Readers = ?getv(<<"readers">>, SecProps, {[]}),
+ Admins = couch_util:get_value(<<"admins">>, SecProps, {[]}),
+ Readers = couch_util:get_value(<<"readers">>, SecProps, {[]}),
ok = validate_names_and_roles(Admins),
ok = validate_names_and_roles(Readers),
ok.
% validate user input
validate_names_and_roles({Props}) when is_list(Props) ->
- case ?getv(<<"names">>,Props,[]) of
+ case couch_util:get_value(<<"names">>,Props,[]) of
Ns when is_list(Ns) ->
[throw("names must be a JSON list of strings") ||N <- Ns, not is_binary(N)],
Ns;
_ -> throw("names must be a JSON list of strings")
end,
- case ?getv(<<"roles">>,Props,[]) of
+ case couch_util:get_value(<<"roles">>,Props,[]) of
Rs when is_list(Rs) ->
[throw("roles must be a JSON list of strings") ||R <- Rs, not is_binary(R)],
Rs;
Modified: couchdb/branches/new_replicator/src/couchdb/couch_db.hrl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_db.hrl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_db.hrl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_db.hrl Thu Sep 30 12:31:03 2010
@@ -25,9 +25,6 @@
-define(l2b(V), list_to_binary(V)).
-define(l2i(V), list_to_integer(V)).
--define(getv(Key, List), couch_util:get_value(Key, List)).
--define(getv(Key, List, Default), couch_util:get_value(Key, List, Default)).
-
-define(DEFAULT_ATTACHMENT_CONTENT_TYPE, <<"application/octet-stream">>).
-define(LOG_DEBUG(Format, Args),
Modified: couchdb/branches/new_replicator/src/couchdb/couch_doc.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_doc.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_doc.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_doc.erl Thu Sep 30 12:31:03 2010
@@ -195,26 +195,26 @@ transfer_fields([{<<"_rev">>, _Rev} | Re
transfer_fields([{<<"_attachments">>, {JsonBins}} | Rest], Doc) ->
Atts = lists:map(fun({Name, {BinProps}}) ->
- case ?getv(<<"stub">>, BinProps) of
+ case couch_util:get_value(<<"stub">>, BinProps) of
true ->
- Type = ?getv(<<"content_type">>, BinProps),
- RevPos = ?getv(<<"revpos">>, BinProps, 0),
- DiskLen = ?getv(<<"length">>, BinProps),
+ Type = couch_util:get_value(<<"content_type">>, BinProps),
+ RevPos = couch_util:get_value(<<"revpos">>, BinProps, 0),
+ DiskLen = couch_util:get_value(<<"length">>, BinProps),
{Enc, EncLen} = att_encoding_info(BinProps),
#att{name=Name, data=stub, type=Type, att_len=EncLen,
disk_len=DiskLen, encoding=Enc, revpos=RevPos};
_ ->
- Type = ?getv(<<"content_type">>, BinProps,
+ Type = couch_util:get_value(<<"content_type">>, BinProps,
?DEFAULT_ATTACHMENT_CONTENT_TYPE),
- RevPos = ?getv(<<"revpos">>, BinProps, 0),
- case ?getv(<<"follows">>, BinProps) of
+ RevPos = couch_util:get_value(<<"revpos">>, BinProps, 0),
+ case couch_util:get_value(<<"follows">>, BinProps) of
true ->
- DiskLen = ?getv(<<"length">>, BinProps),
+ DiskLen = couch_util:get_value(<<"length">>, BinProps),
{Enc, EncLen} = att_encoding_info(BinProps),
#att{name=Name, data=follows, type=Type, encoding=Enc,
att_len=EncLen, disk_len=DiskLen, revpos=RevPos};
_ ->
- Value = ?getv(<<"data">>, BinProps),
+ Value = couch_util:get_value(<<"data">>, BinProps),
Bin = base64:decode(Value),
LenBin = size(Bin),
#att{name=Name, data=Bin, type=Type, att_len=LenBin,
@@ -225,8 +225,8 @@ transfer_fields([{<<"_attachments">>, {J
transfer_fields(Rest, Doc#doc{atts=Atts});
transfer_fields([{<<"_revisions">>, {Props}} | Rest], Doc) ->
- RevIds = ?getv(<<"ids">>, Props),
- Start = ?getv(<<"start">>, Props),
+ RevIds = couch_util:get_value(<<"ids">>, Props),
+ Start = couch_util:get_value(<<"start">>, Props),
if not is_integer(Start) ->
throw({doc_validation, "_revisions.start isn't an integer."});
not is_list(RevIds) ->
@@ -261,12 +261,12 @@ transfer_fields([Field | Rest], #doc{bod
transfer_fields(Rest, Doc#doc{body=[Field|Fields]}).
att_encoding_info(BinProps) ->
- DiskLen = ?getv(<<"length">>, BinProps),
- case ?getv(<<"encoding">>, BinProps) of
+ DiskLen = couch_util:get_value(<<"length">>, BinProps),
+ case couch_util:get_value(<<"encoding">>, BinProps) of
undefined ->
{identity, DiskLen};
Enc ->
- EncodedLen = ?getv(<<"encoded_length">>, BinProps, DiskLen),
+ EncodedLen = couch_util:get_value(<<"encoded_length">>, BinProps, DiskLen),
{list_to_atom(?b2l(Enc)), EncodedLen}
end.
@@ -335,7 +335,7 @@ att_to_bin(#att{data=DataFun, att_len=Le
).
get_validate_doc_fun(#doc{body={Props}}=DDoc) ->
- case ?getv(<<"validate_doc_update">>, Props) of
+ case couch_util:get_value(<<"validate_doc_update">>, Props) of
undefined ->
nil;
_Else ->
@@ -468,7 +468,7 @@ doc_from_multi_part_stream(ContentType,
end.
mp_parse_doc({headers, H}, []) ->
- case ?getv("content-type", H) of
+ case couch_util:get_value("content-type", H) of
{"application/json", _} ->
fun (Next) ->
mp_parse_doc(Next, [])
Modified: couchdb/branches/new_replicator/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_httpd.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_httpd.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_httpd.erl Thu Sep 30 12:31:03 2010
@@ -167,7 +167,7 @@ handle_request(MochiReq, DefaultFun,
Vhost = MochiReq:get_header_value("Host"),
% find Vhost in config
- case ?getv(Vhost, VirtualHosts) of
+ case couch_util:get_value(Vhost, VirtualHosts) of
undefined -> % business as usual
handle_request_int(MochiReq, DefaultFun,
UrlHandlers, DbUrlHandlers, DesignUrlHandlers);
@@ -359,7 +359,7 @@ qs_value(Req, Key) ->
qs_value(Req, Key, undefined).
qs_value(Req, Key, Default) ->
- ?getv(Key, qs(Req), Default).
+ couch_util:get_value(Key, qs(Req), Default).
qs(#httpd{mochi_req=MochiReq}) ->
MochiReq:parse_qs().
@@ -774,7 +774,7 @@ nil_callback(_Data)->
fun(Next) -> nil_callback(Next) end.
get_boundary({"multipart/" ++ _, Opts}) ->
- case ?getv("boundary", Opts) of
+ case couch_util:get_value("boundary", Opts) of
S when is_list(S) ->
S
end;
Modified: couchdb/branches/new_replicator/src/couchdb/couch_httpd_auth.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_httpd_auth.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_httpd_auth.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_httpd_auth.erl Thu Sep 30 12:31:03 2010
@@ -70,14 +70,14 @@ default_authentication_handler(Req) ->
nil ->
throw({unauthorized, <<"Name or password is incorrect.">>});
UserProps ->
- UserSalt = ?getv(<<"salt">>, UserProps, <<>>),
+ UserSalt = couch_util:get_value(<<"salt">>, UserProps, <<>>),
PasswordHash = hash_password(?l2b(Pass), UserSalt),
- ExpectedHash = ?getv(<<"password_sha">>, UserProps, nil),
+ ExpectedHash = couch_util:get_value(<<"password_sha">>, UserProps, nil),
case couch_util:verify(ExpectedHash, PasswordHash) of
true ->
Req#httpd{user_ctx=#user_ctx{
name=?l2b(User),
- roles=?getv(<<"roles">>, UserProps, [])
+ roles=couch_util:get_value(<<"roles">>, UserProps, [])
}};
_Else ->
throw({unauthorized, <<"Name or password is incorrect.">>})
@@ -170,7 +170,7 @@ get_user(UserName) ->
{<<"salt">>, ?l2b(Salt)},
{<<"password_sha">>, ?l2b(HashedPwd)}];
UserProps when is_list(UserProps) ->
- DocRoles = ?getv(<<"roles">>, UserProps),
+ DocRoles = couch_util:get_value(<<"roles">>, UserProps),
[{<<"roles">>, [<<"_admin">> | DocRoles]},
{<<"salt">>, ?l2b(Salt)},
{<<"password_sha">>, ?l2b(HashedPwd)}]
@@ -186,10 +186,10 @@ get_user_props_from_db(UserName) ->
try couch_httpd_db:couch_doc_open(Db, DocId, nil, [conflicts]) of
#doc{meta=Meta}=Doc ->
% check here for conflict state and throw error if conflicted
- case ?getv(conflicts,Meta,[]) of
+ case couch_util:get_value(conflicts,Meta,[]) of
[] ->
{DocProps} = couch_query_servers:json_doc(Doc),
- case ?getv(<<"type">>, DocProps) of
+ case couch_util:get_value(<<"type">>, DocProps) of
<<"user">> ->
DocProps;
_Else ->
@@ -324,7 +324,7 @@ cookie_authentication_handler(#httpd{moc
case get_user(?l2b(User)) of
nil -> Req;
UserProps ->
- UserSalt = ?getv(<<"salt">>, UserProps, <<"">>),
+ UserSalt = couch_util:get_value(<<"salt">>, UserProps, <<"">>),
FullSecret = <<Secret/binary, UserSalt/binary>>,
ExpectedHash = crypto:sha_mac(FullSecret, User ++ ":" ++ TimeStr),
Hash = ?l2b(string:join(HashParts, ":")),
@@ -338,7 +338,7 @@ cookie_authentication_handler(#httpd{moc
?LOG_DEBUG("Successful cookie auth as: ~p", [User]),
Req#httpd{user_ctx=#user_ctx{
name=?l2b(User),
- roles=?getv(<<"roles">>, UserProps, [])
+ roles=couch_util:get_value(<<"roles">>, UserProps, [])
}, auth={FullSecret, TimeLeft < Timeout*0.9}};
_Else ->
Req
@@ -359,9 +359,9 @@ cookie_auth_header(#httpd{user_ctx=#user
% or logout handler.
% The login and logout handlers need to set the AuthSession cookie
% themselves.
- CookieHeader = ?getv("Set-Cookie", Headers, ""),
+ CookieHeader = couch_util:get_value("Set-Cookie", Headers, ""),
Cookies = mochiweb_cookies:parse_cookie(CookieHeader),
- AuthSession = ?getv("AuthSession", Cookies),
+ AuthSession = couch_util:get_value("AuthSession", Cookies),
if AuthSession == undefined ->
TimeStamp = make_cookie_time(),
[cookie_auth_cookie(?b2l(User), Secret, TimeStamp)];
@@ -400,16 +400,16 @@ handle_session_req(#httpd{method='POST',
_ ->
[]
end,
- UserName = ?l2b(?getv("name", Form, "")),
- Password = ?l2b(?getv("password", Form, "")),
+ UserName = ?l2b(couch_util:get_value("name", Form, "")),
+ Password = ?l2b(couch_util:get_value("password", Form, "")),
?LOG_DEBUG("Attempt Login: ~s",[UserName]),
User = case get_user(UserName) of
nil -> [];
Result -> Result
end,
- UserSalt = ?getv(<<"salt">>, User, <<>>),
+ UserSalt = couch_util:get_value(<<"salt">>, User, <<>>),
PasswordHash = hash_password(Password, UserSalt),
- ExpectedHash = ?getv(<<"password_sha">>, User, nil),
+ ExpectedHash = couch_util:get_value(<<"password_sha">>, User, nil),
case couch_util:verify(ExpectedHash, PasswordHash) of
true ->
% setup the session cookie
@@ -426,8 +426,8 @@ handle_session_req(#httpd{method='POST',
send_json(Req#httpd{req_body=ReqBody}, Code, Headers,
{[
{ok, true},
- {name, ?getv(<<"name">>, User, null)},
- {roles, ?getv(<<"roles">>, User, [])}
+ {name, couch_util:get_value(<<"name">>, User, null)},
+ {roles, couch_util:get_value(<<"roles">>, User, [])}
]});
_Else ->
% clear the session
Modified: couchdb/branches/new_replicator/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_httpd_db.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_httpd_db.erl Thu Sep 30 12:31:03 2010
@@ -282,7 +282,7 @@ db_req(#httpd{path_parts=[_,<<"_ensure_f
db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>]}=Req, Db) ->
couch_stats_collector:increment({httpd, bulk_requests}),
{JsonProps} = couch_httpd:json_body_obj(Req),
- DocsArray = ?getv(<<"docs">>, JsonProps),
+ DocsArray = couch_util:get_value(<<"docs">>, JsonProps),
case couch_httpd:header_value(Req, "X-Couch-Full-Commit") of
"true" ->
Options = [full_commit];
@@ -291,7 +291,7 @@ db_req(#httpd{method='POST',path_parts=[
_ ->
Options = []
end,
- case ?getv(<<"new_edits">>, JsonProps, true) of
+ case couch_util:get_value(<<"new_edits">>, JsonProps, true) of
true ->
Docs = lists:map(
fun({ObjProps} = JsonObj) ->
@@ -301,7 +301,7 @@ db_req(#httpd{method='POST',path_parts=[
<<>> -> couch_uuids:new();
Id0 -> Id0
end,
- case ?getv(<<"_rev">>, ObjProps) of
+ case couch_util:get_value(<<"_rev">>, ObjProps) of
undefined ->
Revs = {0, []};
Rev ->
@@ -312,7 +312,7 @@ db_req(#httpd{method='POST',path_parts=[
end,
DocsArray),
Options2 =
- case ?getv(<<"all_or_nothing">>, JsonProps) of
+ case couch_util:get_value(<<"all_or_nothing">>, JsonProps) of
true -> [all_or_nothing|Options];
_ -> Options
end,
@@ -361,7 +361,7 @@ db_req(#httpd{method='GET',path_parts=[_
db_req(#httpd{method='POST',path_parts=[_,<<"_all_docs">>]}=Req, Db) ->
{Fields} = couch_httpd:json_body_obj(Req),
- case ?getv(<<"keys">>, Fields, nil) of
+ case couch_util:get_value(<<"keys">>, Fields, nil) of
nil ->
?LOG_DEBUG("POST to _all_docs with no keys member.", []),
all_docs_view(Req, Db, nil);
@@ -483,7 +483,7 @@ all_docs_view(Req, Db, Keys) ->
CurrentEtag = couch_httpd:make_etag(Info),
couch_httpd:etag_respond(Req, CurrentEtag, fun() ->
- TotalRowCount = ?getv(doc_count, Info),
+ TotalRowCount = couch_util:get_value(doc_count, Info),
StartId = if is_binary(StartKey) -> StartKey;
true -> StartDocId
end,
@@ -616,10 +616,10 @@ db_doc_req(#httpd{method='POST'}=Req, Db
Form = couch_httpd:parse_form(Req),
case proplists:is_defined("_doc", Form) of
true ->
- Json = ?JSON_DECODE(?getv("_doc", Form)),
+ Json = ?JSON_DECODE(couch_util:get_value("_doc", Form)),
Doc = couch_doc_from_req(Req, DocId, Json);
false ->
- Rev = couch_doc:parse_rev(list_to_binary(?getv("_rev", Form))),
+ Rev = couch_doc:parse_rev(list_to_binary(couch_util:get_value("_rev", Form))),
{ok, [{ok, Doc}]} = couch_db:open_doc_revs(Db, DocId, [Rev], [])
end,
UpdatedAtts = [
Modified: couchdb/branches/new_replicator/src/couchdb/couch_httpd_oauth.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_httpd_oauth.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_httpd_oauth.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_httpd_oauth.erl Thu Sep 30 12:31:03 2010
@@ -18,7 +18,7 @@
% OAuth auth handler using per-node user db
oauth_authentication_handler(#httpd{mochi_req=MochiReq}=Req) ->
serve_oauth(Req, fun(URL, Params, Consumer, Signature) ->
- AccessToken = ?getv("oauth_token", Params),
+ AccessToken = couch_util:get_value("oauth_token", Params),
case couch_config:get("oauth_token_secrets", AccessToken) of
undefined ->
couch_httpd:send_error(Req, 400, <<"invalid_token">>,
@@ -44,14 +44,14 @@ set_user_ctx(Req, AccessToken) ->
case couch_httpd_auth:get_user(Name) of
nil -> Req;
User ->
- Roles = ?getv(<<"roles">>, User, []),
+ Roles = couch_util:get_value(<<"roles">>, User, []),
Req#httpd{user_ctx=#user_ctx{name=Name, roles=Roles}}
end.
% OAuth request_token
handle_oauth_req(#httpd{path_parts=[_OAuth, <<"request_token">>], method=Method}=Req) ->
serve_oauth(Req, fun(URL, Params, Consumer, Signature) ->
- AccessToken = ?getv("oauth_token", Params),
+ AccessToken = couch_util:get_value("oauth_token", Params),
TokenSecret = couch_config:get("oauth_token_secrets", AccessToken),
case oauth:verify(Signature, atom_to_list(Method), URL, Params, Consumer, TokenSecret) of
true ->
@@ -88,7 +88,7 @@ serve_oauth_authorize(#httpd{method=Meth
'GET' ->
% Confirm with the User that they want to authenticate the Consumer
serve_oauth(Req, fun(URL, Params, Consumer, Signature) ->
- AccessToken = ?getv("oauth_token", Params),
+ AccessToken = couch_util:get_value("oauth_token", Params),
TokenSecret = couch_config:get("oauth_token_secrets", AccessToken),
case oauth:verify(Signature, "GET", URL, Params, Consumer, TokenSecret) of
true ->
@@ -100,7 +100,7 @@ serve_oauth_authorize(#httpd{method=Meth
'POST' ->
% If the User has confirmed, we direct the User back to the Consumer with a verification code
serve_oauth(Req, fun(URL, Params, Consumer, Signature) ->
- AccessToken = ?getv("oauth_token", Params),
+ AccessToken = couch_util:get_value("oauth_token", Params),
TokenSecret = couch_config:get("oauth_token_secrets", AccessToken),
case oauth:verify(Signature, "POST", URL, Params, Consumer, TokenSecret) of
true ->
@@ -129,24 +129,24 @@ serve_oauth(#httpd{mochi_req=MochiReq}=R
end
end,
HeaderParams = oauth_uri:params_from_header_string(AuthHeader),
- %Realm = ?getv("realm", HeaderParams),
+ %Realm = couch_util:get_value("realm", HeaderParams),
Params = proplists:delete("realm", HeaderParams) ++ MochiReq:parse_qs(),
?LOG_DEBUG("OAuth Params: ~p", [Params]),
- case ?getv("oauth_version", Params, "1.0") of
+ case couch_util:get_value("oauth_version", Params, "1.0") of
"1.0" ->
- case ?getv("oauth_consumer_key", Params, undefined) of
+ case couch_util:get_value("oauth_consumer_key", Params, undefined) of
undefined ->
case FailSilently of
true -> Req;
false -> couch_httpd:send_error(Req, 400, <<"invalid_consumer">>, <<"Invalid consumer.">>)
end;
ConsumerKey ->
- SigMethod = ?getv("oauth_signature_method", Params),
+ SigMethod = couch_util:get_value("oauth_signature_method", Params),
case consumer_lookup(ConsumerKey, SigMethod) of
none ->
couch_httpd:send_error(Req, 400, <<"invalid_consumer">>, <<"Invalid consumer (key or signature method).">>);
Consumer ->
- Signature = ?getv("oauth_signature", Params),
+ Signature = couch_util:get_value("oauth_signature", Params),
URL = couch_httpd:absolute_uri(Req, MochiReq:get(raw_path)),
Fun(URL, proplists:delete("oauth_signature", Params),
Consumer, Signature)
Modified: couchdb/branches/new_replicator/src/couchdb/couch_httpd_rewrite.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_httpd_rewrite.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_httpd_rewrite.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_httpd_rewrite.erl Thu Sep 30 12:31:03 2010
@@ -123,7 +123,7 @@ handle_rewrite_req(#httpd{
#doc{body={Props}} = DDoc,
% get rules from ddoc
- case ?getv(<<"rewrites">>, Props) of
+ case couch_util:get_value(<<"rewrites">>, Props) of
undefined ->
couch_httpd:send_error(Req, 404, <<"rewrite_error">>,
<<"Invalid path.">>);
@@ -205,7 +205,7 @@ try_bind_path([Dispatch|Rest], Method, P
% QueryArgs1
Bindings2 = lists:foldl(fun({K, V}, Acc) ->
K1 = to_atom(K),
- KV = case ?getv(K1, QueryArgs1) of
+ KV = case couch_util:get_value(K1, QueryArgs1) of
undefined -> [{K1, V}];
_V1 -> []
end,
@@ -275,7 +275,7 @@ replace_var(Key, Value, Bindings) ->
get_var(VarName, Props, Default) ->
VarName1 = list_to_atom(binary_to_list(VarName)),
- ?getv(VarName1, Props, Default).
+ couch_util:get_value(VarName1, Props, Default).
%% doc: build new patch from bindings. bindings are query args
%% (+ dynamic query rewritten if needed) and bindings found in
@@ -289,7 +289,7 @@ make_new_path([?MATCH_ALL|_Rest], _Bindi
Acc1 = lists:reverse(Acc) ++ Remaining,
Acc1;
make_new_path([P|Rest], Bindings, Remaining, Acc) when is_atom(P) ->
- P2 = case ?getv(P, Bindings) of
+ P2 = case couch_util:get_value(P, Bindings) of
undefined -> << "undefined">>;
P1 -> P1
end,
@@ -349,20 +349,20 @@ normalize_path1([Path|Rest], Acc) ->
%% @doc transform json rule in erlang for pattern matching
make_rule(Rule) ->
- Method = case ?getv(<<"method">>, Rule) of
+ Method = case couch_util:get_value(<<"method">>, Rule) of
undefined -> '*';
M -> list_to_atom(?b2l(M))
end,
- QueryArgs = case ?getv(<<"query">>, Rule) of
+ QueryArgs = case couch_util:get_value(<<"query">>, Rule) of
undefined -> [];
{Args} -> Args
end,
- FromParts = case ?getv(<<"from">>, Rule) of
+ FromParts = case couch_util:get_value(<<"from">>, Rule) of
undefined -> ['*'];
From ->
parse_path(From)
end,
- ToParts = case ?getv(<<"to">>, Rule) of
+ ToParts = case couch_util:get_value(<<"to">>, Rule) of
undefined ->
throw({error, invalid_rewrite_target});
To ->
Modified: couchdb/branches/new_replicator/src/couchdb/couch_httpd_show.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_httpd_show.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_httpd_show.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_httpd_show.erl Thu Sep 30 12:31:03 2010
@@ -95,7 +95,7 @@ show_etag(#httpd{user_ctx=UserCtx}=Req,
get_fun_key(DDoc, Type, Name) ->
#doc{body={Props}} = DDoc,
- Lang = ?getv(<<"language">>, Props, <<"javascript">>),
+ Lang = couch_util:get_value(<<"language">>, Props, <<"javascript">>),
Src = couch_util:get_nested_json_value({Props}, [Type, Name]),
{Lang, Src}.
@@ -168,7 +168,7 @@ handle_view_list_req(#httpd{method='POST
% {Props2} = couch_httpd:json_body(Req),
ReqBody = couch_httpd:body(Req),
{Props2} = ?JSON_DECODE(ReqBody),
- Keys = ?getv(<<"keys">>, Props2, nil),
+ Keys = couch_util:get_value(<<"keys">>, Props2, nil),
handle_view_list(Req#httpd{req_body=ReqBody}, Db, DDoc, ListName, {DesignName, ViewName}, Keys);
handle_view_list_req(#httpd{method='POST',
@@ -176,7 +176,7 @@ handle_view_list_req(#httpd{method='POST
% {Props2} = couch_httpd:json_body(Req),
ReqBody = couch_httpd:body(Req),
{Props2} = ?JSON_DECODE(ReqBody),
- Keys = ?getv(<<"keys">>, Props2, nil),
+ Keys = couch_util:get_value(<<"keys">>, Props2, nil),
handle_view_list(Req#httpd{req_body=ReqBody}, Db, DDoc, ListName, {ViewDesignName, ViewName}, Keys);
handle_view_list_req(#httpd{method='POST'}=Req, _Db, _DDoc) ->
@@ -396,7 +396,7 @@ apply_etag({ExternalResponse}, CurrentEt
% headers on the JsonResponse object. We need to control the Etag and
% Vary headers. If the external function controls the Etag, we'd have to
% run it to check for a match, which sort of defeats the purpose.
- case ?getv(<<"headers">>, ExternalResponse, nil) of
+ case couch_util:get_value(<<"headers">>, ExternalResponse, nil) of
nil ->
% no JSON headers
% add our Etag and Vary headers to the response
Modified: couchdb/branches/new_replicator/src/couchdb/couch_httpd_stats_handlers.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_httpd_stats_handlers.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_httpd_stats_handlers.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_httpd_stats_handlers.erl Thu Sep 30 12:31:03 2010
@@ -39,7 +39,7 @@ handle_stats_req(Req) ->
send_method_not_allowed(Req, "GET").
range(Req) ->
- case ?getv("range", couch_httpd:qs(Req)) of
+ case couch_util:get_value("range", couch_httpd:qs(Req)) of
undefined ->
0;
Value ->
@@ -47,7 +47,7 @@ range(Req) ->
end.
flush(Req) ->
- case ?getv("flush", couch_httpd:qs(Req)) of
+ case couch_util:get_value("flush", couch_httpd:qs(Req)) of
"true" ->
couch_stats_aggregator:collect_sample();
_Else ->
Modified: couchdb/branches/new_replicator/src/couchdb/couch_httpd_view.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_httpd_view.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_httpd_view.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_httpd_view.erl Thu Sep 30 12:31:03 2010
@@ -62,7 +62,7 @@ handle_view_req(#httpd{method='GET',
handle_view_req(#httpd{method='POST',
path_parts=[_, _, DName, _, ViewName]}=Req, Db, _DDoc) ->
{Fields} = couch_httpd:json_body_obj(Req),
- case ?getv(<<"keys">>, Fields, nil) of
+ case couch_util:get_value(<<"keys">>, Fields, nil) of
nil ->
Fmt = "POST to view ~p/~p in database ~p with no keys member.",
?LOG_DEBUG(Fmt, [DName, ViewName, Db]),
@@ -80,12 +80,12 @@ handle_temp_view_req(#httpd{method='POST
ok = couch_db:check_is_admin(Db),
couch_stats_collector:increment({httpd, temporary_view_reads}),
{Props} = couch_httpd:json_body_obj(Req),
- Language = ?getv(<<"language">>, Props, <<"javascript">>),
- {DesignOptions} = ?getv(<<"options">>, Props, {[]}),
- MapSrc = ?getv(<<"map">>, Props),
- Keys = ?getv(<<"keys">>, Props, nil),
+ Language = couch_util:get_value(<<"language">>, Props, <<"javascript">>),
+ {DesignOptions} = couch_util:get_value(<<"options">>, Props, {[]}),
+ MapSrc = couch_util:get_value(<<"map">>, Props),
+ Keys = couch_util:get_value(<<"keys">>, Props, nil),
Reduce = get_reduce_type(Req),
- case ?getv(<<"reduce">>, Props, null) of
+ case couch_util:get_value(<<"reduce">>, Props, null) of
null ->
QueryArgs = parse_view_params(Req, Keys, map),
{ok, View, Group} = couch_view:get_temp_map_view(Db, Language,
@@ -600,13 +600,13 @@ view_row_obj(_Db, {{Key, error}, Value},
{[{key, Key}, {error, Value}]};
% include docs in the view output
view_row_obj(Db, {{Key, DocId}, {Props}}, true) ->
- Rev = case ?getv(<<"_rev">>, Props) of
+ Rev = case couch_util:get_value(<<"_rev">>, Props) of
undefined ->
nil;
Rev0 ->
couch_doc:parse_rev(Rev0)
end,
- IncludeId = ?getv(<<"_id">>, Props, DocId),
+ IncludeId = couch_util:get_value(<<"_id">>, Props, DocId),
view_row_with_doc(Db, {{Key, DocId}, {Props}}, {IncludeId, Rev});
view_row_obj(Db, {{Key, DocId}, Value}, true) ->
view_row_with_doc(Db, {{Key, DocId}, Value}, {DocId, nil});
Modified: couchdb/branches/new_replicator/src/couchdb/couch_native_process.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_native_process.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_native_process.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_native_process.erl Thu Sep 30 12:31:03 2010
@@ -25,7 +25,7 @@
%
% fun({Doc}) ->
% % Below, we emit a single record - the _id as key, null as value
-% DocId = ?getv(Doc, <<"_id">>, null),
+% DocId = couch_util:get_value(Doc, <<"_id">>, null),
% Emit(DocId, null)
% end.
%
@@ -173,7 +173,7 @@ ddoc(State, {DDoc}, [FunPath, Args]) ->
% load fun from the FunPath
BFun = lists:foldl(fun
(Key, {Props}) when is_list(Props) ->
- ?getv(Key, Props, nil);
+ couch_util:get_value(Key, Props, nil);
(_Key, Fun) when is_binary(Fun) ->
Fun;
(_Key, nil) ->
Modified: couchdb/branches/new_replicator/src/couchdb/couch_query_servers.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_query_servers.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_query_servers.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_query_servers.erl Thu Sep 30 12:31:03 2010
@@ -271,7 +271,7 @@ terminate(_Reason, {_Langs, PidProcs, _L
handle_call({get_proc, #doc{body={Props}}=DDoc, DDocKey}, _From, {Langs, PidProcs, LangProcs}=Server) ->
% Note to future self. Add max process limit.
- Lang = ?getv(<<"language">>, Props, <<"javascript">>),
+ Lang = couch_util:get_value(<<"language">>, Props, <<"javascript">>),
case ets:lookup(LangProcs, Lang) of
[{Lang, [P|Rest]}] ->
% find a proc in the set that has the DDoc
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=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_rep.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_rep.erl Thu Sep 30 12:31:03 2010
@@ -68,7 +68,7 @@ replicate({Props}=PostBody, UserCtx) ->
[?MODULE]
},
- case ?getv(<<"cancel">>, Props, false) of
+ case couch_util:get_value(<<"cancel">>, Props, false) of
true ->
case supervisor:terminate_child(couch_rep_sup, BaseId ++ Extension) of
{error, not_found} ->
@@ -80,7 +80,7 @@ replicate({Props}=PostBody, UserCtx) ->
false ->
Server = start_replication_server(Replicator),
- case ?getv(<<"continuous">>, Props, false) of
+ case couch_util:get_value(<<"continuous">>, Props, false) of
true ->
{ok, {continuous, ?l2b(BaseId)}};
false ->
@@ -111,12 +111,12 @@ init(InitArgs) ->
do_init([RepId, {PostProps}, UserCtx] = InitArgs) ->
process_flag(trap_exit, true),
- SourceProps = ?getv(<<"source">>, PostProps),
- TargetProps = ?getv(<<"target">>, PostProps),
+ SourceProps = couch_util:get_value(<<"source">>, PostProps),
+ TargetProps = couch_util:get_value(<<"target">>, PostProps),
- DocIds = ?getv(<<"doc_ids">>, PostProps, nil),
- Continuous = ?getv(<<"continuous">>, PostProps, false),
- CreateTarget = ?getv(<<"create_target">>, PostProps, false),
+ DocIds = couch_util:get_value(<<"doc_ids">>, PostProps, nil),
+ Continuous = couch_util:get_value(<<"continuous">>, PostProps, false),
+ CreateTarget = couch_util:get_value(<<"create_target">>, PostProps, false),
Source = open_db(SourceProps, UserCtx),
Target = open_db(TargetProps, UserCtx, CreateTarget),
@@ -190,8 +190,8 @@ do_init([RepId, {PostProps}, UserCtx] =
source_log = SourceLog,
target_log = TargetLog,
rep_starttime = httpd_util:rfc1123_date(),
- src_starttime = ?getv(instance_start_time, SourceInfo),
- tgt_starttime = ?getv(instance_start_time, TargetInfo),
+ src_starttime = couch_util:get_value(instance_start_time, SourceInfo),
+ tgt_starttime = couch_util:get_value(instance_start_time, TargetInfo),
doc_ids = DocIds
},
{ok, State}.
@@ -302,17 +302,17 @@ start_replication_server(Replicator) ->
compare_replication_logs(SrcDoc, TgtDoc) ->
#doc{body={RepRecProps}} = SrcDoc,
#doc{body={RepRecPropsTgt}} = TgtDoc,
- case ?getv(<<"session_id">>, RepRecProps) ==
- ?getv(<<"session_id">>, RepRecPropsTgt) of
+ case couch_util:get_value(<<"session_id">>, RepRecProps) ==
+ couch_util:get_value(<<"session_id">>, RepRecPropsTgt) of
true ->
% if the records have the same session id,
% then we have a valid replication history
- OldSeqNum = ?getv(<<"source_last_seq">>, RepRecProps, 0),
- OldHistory = ?getv(<<"history">>, RepRecProps, []),
+ OldSeqNum = couch_util:get_value(<<"source_last_seq">>, RepRecProps, 0),
+ OldHistory = couch_util:get_value(<<"history">>, RepRecProps, []),
{OldSeqNum, OldHistory};
false ->
- SourceHistory = ?getv(<<"history">>, RepRecProps, []),
- TargetHistory = ?getv(<<"history">>, RepRecPropsTgt, []),
+ SourceHistory = couch_util:get_value(<<"history">>, RepRecProps, []),
+ TargetHistory = couch_util:get_value(<<"history">>, RepRecPropsTgt, []),
?LOG_INFO("Replication records differ. "
"Scanning histories to find a common ancestor.", []),
?LOG_DEBUG("Record on source:~p~nRecord on target:~p~n",
@@ -324,18 +324,18 @@ compare_rep_history(S, T) when S =:= []
?LOG_INFO("no common ancestry -- performing full replication", []),
{0, []};
compare_rep_history([{S}|SourceRest], [{T}|TargetRest]=Target) ->
- SourceId = ?getv(<<"session_id">>, S),
+ SourceId = couch_util:get_value(<<"session_id">>, S),
case has_session_id(SourceId, Target) of
true ->
- RecordSeqNum = ?getv(<<"recorded_seq">>, S, 0),
+ RecordSeqNum = couch_util:get_value(<<"recorded_seq">>, S, 0),
?LOG_INFO("found a common replication record with source_seq ~p",
[RecordSeqNum]),
{RecordSeqNum, SourceRest};
false ->
- TargetId = ?getv(<<"session_id">>, T),
+ TargetId = couch_util:get_value(<<"session_id">>, T),
case has_session_id(TargetId, SourceRest) of
true ->
- RecordSeqNum = ?getv(<<"recorded_seq">>, T, 0),
+ RecordSeqNum = couch_util:get_value(<<"recorded_seq">>, T, 0),
?LOG_INFO("found a common replication record with source_seq ~p",
[RecordSeqNum]),
{RecordSeqNum, TargetRest};
@@ -433,7 +433,7 @@ terminate_cleanup(#state{source=Source,
has_session_id(_SessionId, []) ->
false;
has_session_id(SessionId, [{Props} | Rest]) ->
- case ?getv(<<"session_id">>, Props, nil) of
+ case couch_util:get_value(<<"session_id">>, Props, nil) of
SessionId ->
true;
_Else ->
@@ -443,7 +443,7 @@ has_session_id(SessionId, [{Props} | Res
maybe_append_options(Options, Props) ->
lists:foldl(fun(Option, Acc) ->
Acc ++
- case ?getv(Option, Props, false) of
+ case couch_util:get_value(Option, Props, false) of
true ->
"+" ++ ?b2l(Option);
false ->
@@ -455,19 +455,19 @@ make_replication_id({Props}, UserCtx) ->
%% funky algorithm to preserve backwards compatibility
{ok, HostName} = inet:gethostname(),
% Port = mochiweb_socket_server:get(couch_httpd, port),
- Src = get_rep_endpoint(UserCtx, ?getv(<<"source">>, Props)),
- Tgt = get_rep_endpoint(UserCtx, ?getv(<<"target">>, Props)),
+ Src = get_rep_endpoint(UserCtx, couch_util:get_value(<<"source">>, Props)),
+ Tgt = get_rep_endpoint(UserCtx, couch_util:get_value(<<"target">>, Props)),
Base = [HostName, Src, Tgt] ++
- case ?getv(<<"filter">>, Props) of
+ case couch_util:get_value(<<"filter">>, Props) of
undefined ->
- case ?getv(<<"doc_ids">>, Props) of
+ case couch_util:get_value(<<"doc_ids">>, Props) of
undefined ->
[];
DocIds ->
[DocIds]
end;
Filter ->
- [Filter, ?getv(<<"query_params">>, Props, {[]})]
+ [Filter, couch_util:get_value(<<"query_params">>, Props, {[]})]
end,
Extension = maybe_append_options(
[<<"continuous">>, <<"create_target">>], Props),
@@ -477,10 +477,10 @@ maybe_add_trailing_slash(Url) ->
re:replace(Url, "[^/]$", "&/", [{return, list}]).
get_rep_endpoint(_UserCtx, {Props}) ->
- Url = maybe_add_trailing_slash(?getv(<<"url">>, Props)),
- {BinHeaders} = ?getv(<<"headers">>, Props, {[]}),
- {Auth} = ?getv(<<"auth">>, Props, {[]}),
- case ?getv(<<"oauth">>, Auth) of
+ Url = maybe_add_trailing_slash(couch_util:get_value(<<"url">>, Props)),
+ {BinHeaders} = couch_util:get_value(<<"headers">>, Props, {[]}),
+ {Auth} = couch_util:get_value(<<"auth">>, Props, {[]}),
+ case couch_util:get_value(<<"oauth">>, Auth) of
undefined ->
{remote, Url, [{?b2l(K),?b2l(V)} || {K,V} <- BinHeaders]};
{OAuth} ->
@@ -519,9 +519,9 @@ open_db(Props, UserCtx) ->
open_db(Props, UserCtx, false).
open_db({Props}, _UserCtx, CreateTarget) ->
- Url = maybe_add_trailing_slash(?getv(<<"url">>, Props)),
- {AuthProps} = ?getv(<<"auth">>, Props, {[]}),
- {BinHeaders} = ?getv(<<"headers">>, Props, {[]}),
+ Url = maybe_add_trailing_slash(couch_util:get_value(<<"url">>, Props)),
+ {AuthProps} = couch_util:get_value(<<"auth">>, Props, {[]}),
+ {BinHeaders} = couch_util:get_value(<<"headers">>, Props, {[]}),
Headers = [{?b2l(K),?b2l(V)} || {K,V} <- BinHeaders],
DefaultHeaders = (#http_db{})#http_db.headers,
Db = #http_db{
@@ -659,8 +659,8 @@ ensure_full_commit(#http_db{} = Target)
method = post
},
{ResultProps} = couch_rep_httpc:request(Req),
- true = ?getv(<<"ok">>, ResultProps),
- ?getv(<<"instance_start_time">>, ResultProps);
+ true = couch_util:get_value(<<"ok">>, ResultProps),
+ couch_util:get_value(<<"instance_start_time">>, ResultProps);
ensure_full_commit(Target) ->
{ok, NewDb} = couch_db:open_int(Target#db.name, []),
UpdateSeq = couch_db:get_update_seq(Target),
@@ -684,9 +684,9 @@ ensure_full_commit(#http_db{} = Source,
qs = [{seq, RequiredSeq}]
},
{ResultProps} = couch_rep_httpc:request(Req),
- case ?getv(<<"ok">>, ResultProps) of
+ case couch_util:get_value(<<"ok">>, ResultProps) of
true ->
- ?getv(<<"instance_start_time">>, ResultProps);
+ couch_util:get_value(<<"instance_start_time">>, ResultProps);
undefined -> nil end;
ensure_full_commit(Source, RequiredSeq) ->
{ok, NewDb} = couch_db:open_int(Source#db.name, []),
@@ -711,7 +711,7 @@ update_local_doc(#http_db{} = Db, Doc) -
headers = [{"x-couch-full-commit", "false"} | Db#http_db.headers]
},
{ResponseMembers} = couch_rep_httpc:request(Req),
- Rev = ?getv(<<"rev">>, ResponseMembers),
+ Rev = couch_util:get_value(<<"rev">>, ResponseMembers),
couch_doc:parse_rev(Rev);
update_local_doc(Db, Doc) ->
{ok, Result} = couch_db:update_doc(Db, Doc, [delay_commit]),
Modified: couchdb/branches/new_replicator/src/couchdb/couch_rep_changes_feed.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_rep_changes_feed.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_rep_changes_feed.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_rep_changes_feed.erl Thu Sep 30 12:31:03 2010
@@ -47,7 +47,7 @@ stop(Server) ->
init([_Parent, #http_db{}=Source, Since, PostProps] = Args) ->
process_flag(trap_exit, true),
- Feed = case ?getv(<<"continuous">>, PostProps, false) of
+ Feed = case couch_util:get_value(<<"continuous">>, PostProps, false) of
false ->
normal;
true ->
@@ -59,11 +59,11 @@ init([_Parent, #http_db{}=Source, Since,
{"since", Since},
{"feed", Feed}
],
- QS = case ?getv(<<"filter">>, PostProps) of
+ QS = case couch_util:get_value(<<"filter">>, PostProps) of
undefined ->
BaseQS;
FilterName ->
- {Params} = ?getv(<<"query_params">>, PostProps, {[]}),
+ {Params} = couch_util:get_value(<<"query_params">>, PostProps, {[]}),
lists:foldr(
fun({K, V}, QSAcc) ->
Ks = couch_util:to_list(K),
@@ -120,8 +120,8 @@ init([_Parent, Source, Since, PostProps]
ChangesArgs = #changes_args{
style = all_docs,
since = Since,
- filter = ?b2l(?getv(<<"filter">>, PostProps, <<>>)),
- feed = case ?getv(<<"continuous">>, PostProps, false) of
+ filter = ?b2l(couch_util:get_value(<<"filter">>, PostProps, <<>>)),
+ feed = case couch_util:get_value(<<"continuous">>, PostProps, false) of
true ->
"continuous";
false ->
@@ -144,11 +144,11 @@ init([_Parent, Source, Since, PostProps]
{ok, #state{changes_loop=ChangesPid, init_args=InitArgs}}.
filter_json_req(Db, PostProps) ->
- case ?getv(<<"filter">>, PostProps) of
+ case couch_util:get_value(<<"filter">>, PostProps) of
undefined ->
{[]};
FilterName ->
- {Query} = ?getv(<<"query_params">>, PostProps, {[]}),
+ {Query} = couch_util:get_value(<<"query_params">>, PostProps, {[]}),
{ok, Info} = couch_db:get_db_info(Db),
% simulate a request to db_name/_changes
{[
@@ -291,7 +291,7 @@ handle_messages([Chunk|Rest], State) ->
#state{reply_to=nil} ->
State#state{
count = Count+1,
- last_seq = ?getv(<<"seq">>, Props),
+ last_seq = couch_util:get_value(<<"seq">>, Props),
partial_chunk = <<>>,
rows=queue:in(Row,Rows)
};
@@ -338,16 +338,16 @@ by_seq_loop(Server, Source, StartSeq) ->
qs = [{limit, 1000}, {startkey, StartSeq}]
},
{Results} = couch_rep_httpc:request(Req),
- Rows = ?getv(<<"rows">>, Results),
+ Rows = couch_util:get_value(<<"rows">>, Results),
if Rows =:= [] -> exit(normal); true -> ok end,
EndSeq = lists:foldl(fun({RowInfoList}, _) ->
- Id = ?getv(<<"id">>, RowInfoList),
- Seq = ?getv(<<"key">>, RowInfoList),
- {RowProps} = ?getv(<<"value">>, RowInfoList),
+ Id = couch_util:get_value(<<"id">>, RowInfoList),
+ Seq = couch_util:get_value(<<"key">>, RowInfoList),
+ {RowProps} = couch_util:get_value(<<"value">>, RowInfoList),
RawRevs = [
- ?getv(<<"rev">>, RowProps),
- ?getv(<<"conflicts">>, RowProps, []),
- ?getv(<<"deleted_conflicts">>, RowProps, [])
+ couch_util:get_value(<<"rev">>, RowProps),
+ couch_util:get_value(<<"conflicts">>, RowProps, []),
+ couch_util:get_value(<<"deleted_conflicts">>, RowProps, [])
],
ParsedRevs = couch_doc:parse_revs(lists:flatten(RawRevs)),
Change = {[
Modified: couchdb/branches/new_replicator/src/couchdb/couch_rep_httpc.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_rep_httpc.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_rep_httpc.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_rep_httpc.erl Thu Sep 30 12:31:03 2010
@@ -34,7 +34,7 @@ do_request(Req) ->
qs = QS
} = Req,
Url = full_url(Req),
- Headers = case ?getv(<<"oauth">>, Auth) of
+ Headers = case couch_util:get_value(<<"oauth">>, Auth) of
undefined ->
Headers0;
{OAuthProps} ->
@@ -75,7 +75,7 @@ db_exists(Req, CanonicalUrl, CreateDB) -
url = Url
} = Req,
HeadersFun = fun(Method) ->
- case ?getv(<<"oauth">>, Auth) of
+ case couch_util:get_value(<<"oauth">>, Auth) of
undefined ->
Headers0;
{OAuthProps} ->
@@ -178,7 +178,7 @@ process_response({error, Reason}, Req) -
redirected_request(Req, RedirectUrl) ->
{Base, QStr, _} = mochiweb_util:urlsplit_path(RedirectUrl),
QS = mochiweb_util:parse_qs(QStr),
- Hdrs = case ?getv(<<"oauth">>, Req#http_db.auth) of
+ Hdrs = case couch_util:get_value(<<"oauth">>, Req#http_db.auth) of
undefined ->
Req#http_db.headers;
_Else ->
@@ -208,11 +208,11 @@ oauth_header(Url, QS, Action, Props) ->
% erlang-oauth doesn't like iolists
QSL = [{couch_util:to_list(K), ?b2l(?l2b(couch_util:to_list(V)))} ||
{K,V} <- QS],
- ConsumerKey = ?b2l(?getv(<<"consumer_key">>, Props)),
- Token = ?b2l(?getv(<<"token">>, Props)),
- TokenSecret = ?b2l(?getv(<<"token_secret">>, Props)),
- ConsumerSecret = ?b2l(?getv(<<"consumer_secret">>, Props)),
- SignatureMethodStr = ?b2l(?getv(<<"signature_method">>, Props, <<"HMAC-SHA1">>)),
+ ConsumerKey = ?b2l(couch_util:get_value(<<"consumer_key">>, Props)),
+ Token = ?b2l(couch_util:get_value(<<"token">>, Props)),
+ TokenSecret = ?b2l(couch_util:get_value(<<"token_secret">>, Props)),
+ ConsumerSecret = ?b2l(couch_util:get_value(<<"consumer_secret">>, Props)),
+ SignatureMethodStr = ?b2l(couch_util:get_value(<<"signature_method">>, Props, <<"HMAC-SHA1">>)),
SignatureMethodAtom = case SignatureMethodStr of
"PLAINTEXT" ->
plaintext;
Modified: couchdb/branches/new_replicator/src/couchdb/couch_rep_missing_revs.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_rep_missing_revs.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_rep_missing_revs.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_rep_missing_revs.erl Thu Sep 30 12:31:03 2010
@@ -145,44 +145,44 @@ changes_loop(OurServer, SourceChangesSer
get_missing_revs(#http_db{}=Target, Changes) ->
Transform = fun({Props}) ->
- C = ?getv(<<"changes">>, Props),
- Id = ?getv(<<"id">>, Props),
+ C = couch_util:get_value(<<"changes">>, Props),
+ Id = couch_util:get_value(<<"id">>, Props),
{Id, [R || {[{<<"rev">>, R}]} <- C]}
end,
IdRevsList = [Transform(Change) || Change <- Changes],
SeqDict = changes_dictionary(Changes),
{LastProps} = lists:last(Changes),
- HighSeq = ?getv(<<"seq">>, LastProps),
+ HighSeq = couch_util:get_value(<<"seq">>, LastProps),
Request = Target#http_db{
resource = "_missing_revs",
method = post,
body = {IdRevsList}
},
{Resp} = couch_rep_httpc:request(Request),
- case ?getv(<<"missing_revs">>, Resp) of
+ case couch_util:get_value(<<"missing_revs">>, Resp) of
{MissingRevs} ->
X = [{Id, dict:fetch(Id, SeqDict), couch_doc:parse_revs(RevStrs)} ||
{Id,RevStrs} <- MissingRevs],
{HighSeq, X};
_ ->
- exit({target_error, ?getv(<<"error">>, Resp)})
+ exit({target_error, couch_util:get_value(<<"error">>, Resp)})
end;
get_missing_revs(Target, Changes) ->
Transform = fun({Props}) ->
- C = ?getv(<<"changes">>, Props),
- Id = ?getv(<<"id">>, Props),
+ C = couch_util:get_value(<<"changes">>, Props),
+ Id = couch_util:get_value(<<"id">>, Props),
{Id, [couch_doc:parse_rev(R) || {[{<<"rev">>, R}]} <- C]}
end,
IdRevsList = [Transform(Change) || Change <- Changes],
SeqDict = changes_dictionary(Changes),
{LastProps} = lists:last(Changes),
- HighSeq = ?getv(<<"seq">>, LastProps),
+ HighSeq = couch_util:get_value(<<"seq">>, LastProps),
{ok, Results} = couch_db:get_missing_revs(Target, IdRevsList),
{HighSeq, [{Id, dict:fetch(Id, SeqDict), Revs} || {Id, Revs, _} <- Results]}.
changes_dictionary(ChangeList) ->
- KVs = [{?getv(<<"id">>,C), couch_util:get_value(<<"seq">>,C)}
+ KVs = [{couch_util:get_value(<<"id">>,C), couch_util:get_value(<<"seq">>,C)}
|| {C} <- ChangeList],
dict:from_list(KVs).
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=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_rep_writer.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_rep_writer.erl Thu Sep 30 12:31:03 2010
@@ -80,7 +80,7 @@ write_bulk_docs(#http_db{headers = Heade
},
ErrorsJson = case couch_rep_httpc:request(Request) of
{FailProps} ->
- exit({target_error, ?getv(<<"error">>, FailProps)});
+ exit({target_error, couch_util:get_value(<<"error">>, FailProps)});
List when is_list(List) ->
List
end,
@@ -141,8 +141,8 @@ write_multi_part_doc(#http_db{headers=He
end.
write_docs_1({Props}) ->
- Id = ?getv(<<"id">>, Props),
- Rev = couch_doc:parse_rev(?getv(<<"rev">>, Props)),
- ErrId = couch_util:to_existing_atom(?getv(<<"error">>, Props)),
- Reason = ?getv(<<"reason">>, Props),
+ Id = couch_util:get_value(<<"id">>, Props),
+ Rev = couch_doc:parse_rev(couch_util:get_value(<<"rev">>, Props)),
+ ErrId = couch_util:to_existing_atom(couch_util:get_value(<<"error">>, Props)),
+ Reason = couch_util:get_value(<<"reason">>, Props),
{{Id, Rev}, {ErrId, Reason}}.
Modified: couchdb/branches/new_replicator/src/couchdb/couch_replicate.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_replicate.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_replicate.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_replicate.erl Thu Sep 30 12:31:03 2010
@@ -23,6 +23,11 @@
-include("couch_db.hrl").
-include("couch_api_wrap.hrl").
+-import(couch_util, [
+ get_value/2,
+ get_value/3
+]).
+
% Can't be greater than the maximum number of child restarts specified
% in couch_rep_sup.erl.
-define(MAX_RESTARTS, 3).
@@ -68,7 +73,7 @@
replicate(#rep{id = RepId, options = Options} = Rep) ->
- case ?getv(cancel, Options, false) of
+ case get_value(cancel, Options, false) of
true ->
end_replication(RepId);
false ->
@@ -80,8 +85,8 @@ replicate(#rep{id = RepId, options = Opt
do_replication_loop(#rep{options = Options, source = Src} = Rep) ->
- DocIds = ?getv(doc_ids, Options),
- Continuous = ?getv(continuous, Options, false),
+ DocIds = get_value(doc_ids, Options),
+ Continuous = get_value(continuous, Options, false),
Seq = case {DocIds, Continuous} of
{undefined, false} ->
last_seq(Src, Rep#rep.user_ctx);
@@ -93,7 +98,7 @@ do_replication_loop(#rep{options = Optio
do_replication_loop(#rep{id = {BaseId,_} = Id, options = Options} = Rep, Seq) ->
case start_replication(Rep) of
{ok, _Pid} ->
- case ?getv(continuous, Options, false) of
+ case get_value(continuous, Options, false) of
true ->
{ok, {continuous, ?l2b(BaseId)}};
false ->
@@ -108,7 +113,7 @@ do_replication_loop(#rep{id = {BaseId,_}
maybe_retry(RepResult, _Rep, undefined) ->
RepResult;
maybe_retry({ok, {Props}} = Result, Rep, Seq) ->
- case ?getv(source_last_seq, Props) >= Seq of
+ case get_value(source_last_seq, Props) >= Seq of
true ->
Result;
false ->
@@ -123,7 +128,7 @@ last_seq(DbName, UserCtx) ->
{ok, Db} ->
{ok, DbInfo} = couch_api_wrap:get_db_info(Db),
couch_api_wrap:db_close(Db),
- ?getv(<<"update_seq">>, DbInfo);
+ get_value(<<"update_seq">>, DbInfo);
_ ->
undefined
end.
@@ -226,7 +231,7 @@ do_init(#rep{options = Options} = Rep) -
{ok, MissingRevsQueue} = couch_work_queue:new(
[{max_size, 100000}, {max_items, 500}, {multi_workers, true}]),
- case ?getv(doc_ids, Options) of
+ case get_value(doc_ids, Options) of
undefined ->
{ok, ChangesQueue} = couch_work_queue:new(
[{max_size, 100000}, {max_items, 500}]),
@@ -265,7 +270,7 @@ do_init(#rep{options = Options} = Rep) -
changes_reader = ChangesReader,
missing_revs_finder = MissingRevsFinder,
doc_copiers = DocCopiers,
- is_successor_seq = ?getv(is_successor_seq, Options,
+ is_successor_seq = get_value(is_successor_seq, Options,
fun(Seq, NextSeq) -> (Seq + 1) =:= NextSeq end)
}
}.
@@ -379,7 +384,7 @@ handle_info({'EXIT', Pid, Reason}, #rep_
handle_info({'EXIT', Pid, Reason}, State) ->
#rep_state{doc_copiers = DocCopiers} = State,
- case ?getv(Pid, DocCopiers) of
+ case get_value(Pid, DocCopiers) of
undefined ->
cancel_timer(State),
{stop, {unknown_process_died, Pid, Reason}, State};
@@ -433,7 +438,7 @@ terminate_cleanup(#rep_state{source = So
start_timer(#rep_state{rep_details = #rep{options = Options}} = State) ->
- case ?getv(doc_ids, Options) of
+ case get_value(doc_ids, Options) of
undefined ->
After = checkpoint_interval(State),
case timer:apply_after(After, gen_server, cast, [self(), checkpoint]) of
@@ -455,7 +460,7 @@ cancel_timer(#rep_state{timer = Timer})
get_result(#rep_state{stats = Stats, rep_details = Rep} = State) ->
- case ?getv(doc_ids, Rep#rep.options) of
+ case get_value(doc_ids, Rep#rep.options) of
undefined ->
State#rep_state.checkpoint_history;
_DocIdList ->
@@ -477,7 +482,7 @@ init_state(Rep) ->
} = Rep,
{ok, Source} = couch_api_wrap:db_open(Src, [{user_ctx, UserCtx}]),
{ok, Target} = couch_api_wrap:db_open(Tgt, [{user_ctx, UserCtx}],
- ?getv(create_target, Options, false)),
+ get_value(create_target, Options, false)),
{ok, SourceInfo} = couch_api_wrap:get_db_info(Source),
{ok, TargetInfo} = couch_api_wrap:get_db_info(Target),
@@ -507,8 +512,8 @@ init_state(Rep) ->
source_log = SourceLog,
target_log = TargetLog,
rep_starttime = httpd_util:rfc1123_date(),
- src_starttime = ?getv(<<"instance_start_time">>, SourceInfo),
- tgt_starttime = ?getv(<<"instance_start_time">>, TargetInfo)
+ src_starttime = get_value(<<"instance_start_time">>, SourceInfo),
+ tgt_starttime = get_value(<<"instance_start_time">>, TargetInfo)
},
State#rep_state{timer = start_timer(State)}.
@@ -820,17 +825,17 @@ commit_to_both(Source, Target) ->
compare_replication_logs(SrcDoc, TgtDoc) ->
#doc{body={RepRecProps}} = SrcDoc,
#doc{body={RepRecPropsTgt}} = TgtDoc,
- case ?getv(<<"session_id">>, RepRecProps) ==
- ?getv(<<"session_id">>, RepRecPropsTgt) of
+ case get_value(<<"session_id">>, RepRecProps) ==
+ get_value(<<"session_id">>, RepRecPropsTgt) of
true ->
% if the records have the same session id,
% then we have a valid replication history
- OldSeqNum = ?getv(<<"source_last_seq">>, RepRecProps, 0),
- OldHistory = ?getv(<<"history">>, RepRecProps, []),
+ OldSeqNum = get_value(<<"source_last_seq">>, RepRecProps, 0),
+ OldHistory = get_value(<<"history">>, RepRecProps, []),
{OldSeqNum, OldHistory};
false ->
- SourceHistory = ?getv(<<"history">>, RepRecProps, []),
- TargetHistory = ?getv(<<"history">>, RepRecPropsTgt, []),
+ SourceHistory = get_value(<<"history">>, RepRecProps, []),
+ TargetHistory = get_value(<<"history">>, RepRecPropsTgt, []),
?LOG_INFO("Replication records differ. "
"Scanning histories to find a common ancestor.", []),
?LOG_DEBUG("Record on source:~p~nRecord on target:~p~n",
@@ -842,18 +847,18 @@ compare_rep_history(S, T) when S =:= []
?LOG_INFO("no common ancestry -- performing full replication", []),
{0, []};
compare_rep_history([{S} | SourceRest], [{T} | TargetRest] = Target) ->
- SourceId = ?getv(<<"session_id">>, S),
+ SourceId = get_value(<<"session_id">>, S),
case has_session_id(SourceId, Target) of
true ->
- RecordSeqNum = ?getv(<<"recorded_seq">>, S, 0),
+ RecordSeqNum = get_value(<<"recorded_seq">>, S, 0),
?LOG_INFO("found a common replication record with source_seq ~p",
[RecordSeqNum]),
{RecordSeqNum, SourceRest};
false ->
- TargetId = ?getv(<<"session_id">>, T),
+ TargetId = get_value(<<"session_id">>, T),
case has_session_id(TargetId, SourceRest) of
true ->
- RecordSeqNum = ?getv(<<"recorded_seq">>, T, 0),
+ RecordSeqNum = get_value(<<"recorded_seq">>, T, 0),
?LOG_INFO("found a common replication record with source_seq ~p",
[RecordSeqNum]),
{RecordSeqNum, TargetRest};
@@ -866,7 +871,7 @@ compare_rep_history([{S} | SourceRest],
has_session_id(_SessionId, []) ->
false;
has_session_id(SessionId, [{Props} | Rest]) ->
- case ?getv(<<"session_id">>, Props, nil) of
+ case get_value(<<"session_id">>, Props, nil) of
SessionId ->
true;
_Else ->
Modified: couchdb/branches/new_replicator/src/couchdb/couch_replicator_utils.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_replicator_utils.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_replicator_utils.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_replicator_utils.erl Thu Sep 30 12:31:03 2010
@@ -18,11 +18,16 @@
-include("couch_api_wrap.hrl").
-include("../ibrowse/ibrowse.hrl").
+-import(couch_util, [
+ get_value/2,
+ get_value/3
+]).
+
parse_rep_doc({Props} = RepObj, UserCtx) ->
- ProxyParams = parse_proxy_params(?getv(<<"proxy">>, Props, <<>>)),
- Source = parse_rep_db(?getv(<<"source">>, Props), ProxyParams),
- Target = parse_rep_db(?getv(<<"target">>, Props), ProxyParams),
+ ProxyParams = parse_proxy_params(get_value(<<"proxy">>, Props, <<>>)),
+ Source = parse_rep_db(get_value(<<"source">>, Props), ProxyParams),
+ Target = parse_rep_db(get_value(<<"target">>, Props), ProxyParams),
Options = convert_options(Props),
Rep = #rep{
id = make_replication_id(Source, Target, UserCtx, Options),
@@ -42,9 +47,9 @@ make_replication_id(Source, Target, User
Src = get_rep_endpoint(UserCtx, Source),
Tgt = get_rep_endpoint(UserCtx, Target),
Base = [HostName, Src, Tgt] ++
- case ?getv(filter, Options) of
+ case get_value(filter, Options) of
undefined ->
- case ?getv(doc_ids, Options) of
+ case get_value(doc_ids, Options) of
undefined ->
[];
DocIds ->
@@ -52,7 +57,7 @@ make_replication_id(Source, Target, User
end;
Filter ->
[filter_code(Filter, Source, UserCtx),
- ?getv(query_params, Options, {[]})]
+ get_value(query_params, Options, {[]})]
end,
Extension = maybe_append_options([continuous, create_target], Options),
{couch_util:to_hex(couch_util:md5(term_to_binary(Base))), Extension}.
@@ -76,7 +81,7 @@ filter_code(Filter, Source, UserCtx) ->
maybe_append_options(Options, RepOptions) ->
lists:foldl(fun(Option, Acc) ->
Acc ++
- case ?getv(Option, RepOptions, false) of
+ case get_value(Option, RepOptions, false) of
true ->
"+" ++ atom_to_list(Option);
false ->
@@ -97,21 +102,21 @@ get_rep_endpoint(UserCtx, <<DbName/binar
parse_rep_db({Props}, ProxyParams) ->
- Url = maybe_add_trailing_slash(?getv(<<"url">>, Props)),
- {AuthProps} = ?getv(<<"auth">>, Props, {[]}),
- {BinHeaders} = ?getv(<<"headers">>, Props, {[]}),
+ Url = maybe_add_trailing_slash(get_value(<<"url">>, Props)),
+ {AuthProps} = get_value(<<"auth">>, Props, {[]}),
+ {BinHeaders} = get_value(<<"headers">>, Props, {[]}),
Headers = [{?b2l(K), ?b2l(V)} || {K, V} <- BinHeaders],
- OAuth = case ?getv(<<"oauth">>, AuthProps) of
+ OAuth = case get_value(<<"oauth">>, AuthProps) of
undefined ->
nil;
{OauthProps} ->
#oauth{
- consumer_key = ?b2l(?getv(<<"consumer_key">>, OauthProps)),
- token = ?b2l(?getv(<<"token">>, OauthProps)),
- token_secret = ?b2l(?getv(<<"token_secret">>, OauthProps)),
- consumer_secret = ?b2l(?getv(<<"consumer_secret">>, OauthProps)),
+ consumer_key = ?b2l(get_value(<<"consumer_key">>, OauthProps)),
+ token = ?b2l(get_value(<<"token">>, OauthProps)),
+ token_secret = ?b2l(get_value(<<"token_secret">>, OauthProps)),
+ consumer_secret = ?b2l(get_value(<<"consumer_secret">>, OauthProps)),
signature_method =
- case ?getv(<<"signature_method">>, OauthProps) of
+ case get_value(<<"signature_method">>, OauthProps) of
undefined -> hmac_sha1;
<<"PLAINTEXT">> -> plaintext;
<<"HMAC-SHA1">> -> hmac_sha1;
Modified: couchdb/branches/new_replicator/src/couchdb/couch_server.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_server.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_server.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_server.erl Thu Sep 30 12:31:03 2010
@@ -53,7 +53,7 @@ sup_start_link() ->
open(DbName, Options) ->
case gen_server:call(couch_server, {open, DbName, Options}, infinity) of
{ok, Db} ->
- Ctx = ?getv(user_ctx, Options, #user_ctx{}),
+ Ctx = couch_util:get_value(user_ctx, Options, #user_ctx{}),
{ok, Db#db{user_ctx=Ctx}};
Error ->
Error
@@ -62,7 +62,7 @@ open(DbName, Options) ->
create(DbName, Options) ->
case gen_server:call(couch_server, {create, DbName, Options}, infinity) of
{ok, Db} ->
- Ctx = ?getv(user_ctx, Options, #user_ctx{}),
+ Ctx = couch_util:get_value(user_ctx, Options, #user_ctx{}),
{ok, Db#db{user_ctx=Ctx}};
Error ->
Error
Modified: couchdb/branches/new_replicator/src/couchdb/couch_stream.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_stream.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_stream.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_stream.erl Thu Sep 30 12:31:03 2010
@@ -135,7 +135,7 @@ foldl_decode(DecFun, Fd, [Pos|Rest], Md5
foldl_decode(DecFun, Fd, Rest, Md5, Md5Acc2, Fun, Fun(Bin, Acc)).
gzip_init(Options) ->
- case ?getv(compression_level, Options, 0) of
+ case couch_util:get_value(compression_level, Options, 0) of
Lvl when Lvl >= 1 andalso Lvl =< 9 ->
Z = zlib:open(),
% 15 = ?MAX_WBITS (defined in the zlib module)
Modified: couchdb/branches/new_replicator/src/couchdb/couch_view.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_view.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_view.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_view.erl Thu Sep 30 12:31:03 2010
@@ -80,7 +80,7 @@ cleanup_index_files(Db) ->
% make unique list of group sigs
Sigs = lists:map(fun(#doc{id = GroupId}) ->
{ok, Info} = get_group_info(Db, GroupId),
- ?b2l(?getv(signature, Info))
+ ?b2l(couch_util:get_value(signature, Info))
end, [DD||DD <- DesignDocs, DD#doc.deleted == false]),
FileList = list_index_files(Db),
Modified: couchdb/branches/new_replicator/src/couchdb/couch_view_group.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_view_group.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_view_group.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_view_group.erl Thu Sep 30 12:31:03 2010
@@ -502,16 +502,16 @@ get_group_info(State) ->
% maybe move to another module
design_doc_to_view_group(#doc{id=Id,body={Fields}}) ->
- Language = ?getv(<<"language">>, Fields, <<"javascript">>),
- {DesignOptions} = ?getv(<<"options">>, Fields, {[]}),
- {RawViews} = ?getv(<<"views">>, Fields, {[]}),
+ Language = couch_util:get_value(<<"language">>, Fields, <<"javascript">>),
+ {DesignOptions} = couch_util:get_value(<<"options">>, Fields, {[]}),
+ {RawViews} = couch_util:get_value(<<"views">>, Fields, {[]}),
% add the views to a dictionary object, with the map source as the key
DictBySrc =
lists:foldl(
fun({Name, {MRFuns}}, DictBySrcAcc) ->
- MapSrc = ?getv(<<"map">>, MRFuns),
- RedSrc = ?getv(<<"reduce">>, MRFuns, null),
- {ViewOptions} = ?getv(<<"options">>, MRFuns, {[]}),
+ MapSrc = couch_util:get_value(<<"map">>, MRFuns),
+ RedSrc = couch_util:get_value(<<"reduce">>, MRFuns, null),
+ {ViewOptions} = couch_util:get_value(<<"options">>, MRFuns, {[]}),
View =
case dict:find({MapSrc, ViewOptions}, DictBySrcAcc) of
{ok, View0} -> View0;
@@ -574,7 +574,7 @@ init_group(Db, Fd, #group{def_lang=Lang,
{Count, Reduced}
end,
- case ?getv(<<"collation">>, Options, <<"default">>) of
+ case couch_util:get_value(<<"collation">>, Options, <<"default">>) of
<<"default">> ->
Less = fun couch_view:less_json_ids/2;
<<"raw">> ->
Modified: couchdb/branches/new_replicator/src/couchdb/couch_view_updater.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_view_updater.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_view_updater.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_view_updater.erl Thu Sep 30 12:31:03 2010
@@ -51,9 +51,9 @@ update(Owner, Group) ->
% update status every half second
couch_task_status:set_update_frequency(500),
#group{ design_options = DesignOptions } = Group,
- IncludeDesign = ?getv(<<"include_design">>,
+ IncludeDesign = couch_util:get_value(<<"include_design">>,
DesignOptions, false),
- LocalSeq = ?getv(<<"local_seq">>, DesignOptions, false),
+ LocalSeq = couch_util:get_value(<<"local_seq">>, DesignOptions, false),
DocOpts =
case LocalSeq of
true -> [conflicts, deleted_conflicts, local_seq];
Modified: couchdb/branches/new_replicator/src/couchdb/couch_work_queue.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_work_queue.erl?rev=1003040&r1=1003039&r2=1003040&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_work_queue.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_work_queue.erl Thu Sep 30 12:31:03 2010
@@ -20,8 +20,6 @@
-export([init/1, terminate/2]).
-export([handle_call/3, handle_cast/2, code_change/3, handle_info/2]).
--include("couch_db.hrl").
-
-record(q, {
queue = queue:new(),
blocked = [],
@@ -61,9 +59,9 @@ close(Wq) ->
init(Options) ->
Q = #q{
- max_size = ?getv(max_size, Options),
- max_items = ?getv(max_items, Options),
- multi_workers = ?getv(multi_workers, Options, false)
+ max_size = couch_util:get_value(max_size, Options),
+ max_items = couch_util:get_value(max_items, Options),
+ multi_workers = couch_util:get_value(multi_workers, Options, false)
},
{ok, Q}.