You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2009/09/05 22:37:45 UTC

svn commit: r811709 - in /couchdb/trunk/src/couchdb: couch_config.erl couch_httpd_auth.erl couch_rep.erl

Author: jan
Date: Sat Sep  5 20:37:45 2009
New Revision: 811709

URL: http://svn.apache.org/viewvc?rev=811709&view=rev
Log:
code =~ s/imperative/declarative & faster/, thanks to Kostis Sagonas for pointing these out, more to come

Modified:
    couchdb/trunk/src/couchdb/couch_config.erl
    couchdb/trunk/src/couchdb/couch_httpd_auth.erl
    couchdb/trunk/src/couchdb/couch_rep.erl

Modified: couchdb/trunk/src/couchdb/couch_config.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_config.erl?rev=811709&r1=811708&r2=811709&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_config.erl (original)
+++ couchdb/trunk/src/couchdb/couch_config.erl Sat Sep  5 20:37:45 2009
@@ -94,8 +94,8 @@
         {ok, ParsedIniValues} = parse_ini_file(IniFile),
         ets:insert(?MODULE, ParsedIniValues)
     end, IniFiles),
-    WriteFile = case length(IniFiles) > 0 of
-        true -> lists:last(IniFiles);
+    WriteFile = case IniFiles of
+        [_|_] -> lists:last(IniFiles);
         _ -> undefined
     end,
     {ok, #config{write_filename=WriteFile}}.

Modified: couchdb/trunk/src/couchdb/couch_httpd_auth.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_auth.erl?rev=811709&r1=811708&r2=811709&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_auth.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_auth.erl Sat Sep  5 20:37:45 2009
@@ -446,7 +446,7 @@
             Hash = case Password of
                 <<>> -> 
                     CurrentPasswordHash;
-                _P when length(OldPassword) == 0 ->
+                _P when OldPassword = [] ->
                     throw({forbidden, <<"Old password is incorrect.">>});
                 _Else ->
                     OldPasswordHash = hash_password(OldPassword1, UserSalt),

Modified: couchdb/trunk/src/couchdb/couch_rep.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_rep.erl?rev=811709&r1=811708&r2=811709&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_rep.erl (original)
+++ couchdb/trunk/src/couchdb/couch_rep.erl Sat Sep  5 20:37:45 2009
@@ -268,7 +268,7 @@
         compare_rep_history(SourceHistory, TargetHistory)
     end.
 
-compare_rep_history(S, T) when length(S) =:= 0 orelse length(T) =:= 0 ->
+compare_rep_history([], []) ->
     ?LOG_INFO("no common ancestry -- performing full replication", []),
     {0, []};
 compare_rep_history([{S}|SourceRest], [{T}|TargetRest]=Target) ->



Re: svn commit: r811709 - in /couchdb/trunk/src/couchdb: couch_config.erl couch_httpd_auth.erl couch_rep.erl

Posted by Adam Kocoloski <ko...@apache.org>.
On Sep 5, 2009, at 4:37 PM, jan@apache.org wrote:

> -compare_rep_history(S, T) when length(S) =:= 0 orelse length(T) =:=  
> 0 ->
> +compare_rep_history([], []) ->

Hi Jan, this patch isn't quite right and can crash the replicator.   
The old version checked if _either_ list was empty and aborted the  
comparison; the new version requires that _both_ are empty.  If the  
histories have different lengths we'll get a badmatch in the next clause

> compare_rep_history([{S}|SourceRest], [{T}|TargetRest]=Target) ->

I think what you wanted was

> compare_rep_history(S, T) when S =:= [] orelse T =:= [] ->

Best, Adam