emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r103322: auth-source.el (auth-source-


From: Katsumi Yamaoka
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r103322: auth-source.el (auth-source-search): Do a two-phase search, one with no :create to get the responses from all backends.
Date: Thu, 17 Feb 2011 23:48:59 +0000
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 103322
author: Lars Ingebrigtsen <address@hidden>
committer: Katsumi Yamaoka <address@hidden>
branch nick: trunk
timestamp: Thu 2011-02-17 23:48:59 +0000
message:
  auth-source.el (auth-source-search): Do a two-phase search, one with no 
:create to get the responses from all backends.
modified:
  lisp/gnus/ChangeLog
  lisp/gnus/auth-source.el
=== modified file 'lisp/gnus/ChangeLog'
--- a/lisp/gnus/ChangeLog       2011-02-17 23:46:18 +0000
+++ b/lisp/gnus/ChangeLog       2011-02-17 23:48:59 +0000
@@ -1,5 +1,8 @@
 2011-02-17  Lars Ingebrigtsen  <address@hidden>
 
+       * auth-source.el (auth-source-search): Do a two-phase search, one with
+       no :create to get the responses from all backends.
+
        * nnimap.el (nnimap-open-connection-1): Delete duplicate server names
        when getting credentials.
 

=== modified file 'lisp/gnus/auth-source.el'
--- a/lisp/gnus/auth-source.el  2011-02-17 23:46:18 +0000
+++ b/lisp/gnus/auth-source.el  2011-02-17 23:48:59 +0000
@@ -500,7 +500,7 @@
                      unless (memq (nth i spec) ignored-keys)
                      collect (nth i spec)))
          (found (auth-source-recall spec))
-         filtered-backends accessor-key found-here goal)
+         filtered-backends accessor-key found-here goal matches)
 
     (if (and found auth-source-do-cache)
         (auth-source-do-debug
@@ -529,38 +529,57 @@
 
       ;; (debug spec "filtered" filtered-backends)
       (setq goal max)
-      (dolist (backend filtered-backends)
-        (setq found-here (apply
-                          (slot-value backend 'search-function)
-                          :backend backend
-                          :create create
-                          :delete delete
-                          spec))
-
-        ;; if max is 0, as soon as we find something, return it
-        (when (and (zerop max) (> 0 (length found-here)))
-          (return t))
-
-        ;; decrement the goal by the number of new results
-        (decf goal (length found-here))
-        ;; and append the new results to the full list
-        (setq found (append found found-here))
-
-        (auth-source-do-debug
-         "auth-source-search: found %d results (max %d/%d) in %S matching %S"
-         (length found-here) max goal backend spec)
-
-        ;; return full list if the goal is 0 or negative
-        (when (zerop (max 0 goal))
-          (return found))
-
-        ;; change the :max parameter in the spec to the goal
-        (setq spec (plist-put spec :max goal)))
-
-      (when (and found auth-source-do-cache)
-        (auth-source-remember spec found)))
-
-      found))
+      ;; First go through all the backends without :create, so we can
+      ;; query them all.
+      (let ((uspec (copy-sequence spec)))
+       (plist-put uspec :create nil)
+       (dolist (backend filtered-backends)
+         (let ((match (apply
+                       (slot-value backend 'search-function)
+                       :backend backend
+                       uspec)))
+           (when match
+             (push (list backend match) matches)))))
+      ;; If we didn't find anything, then we allow the backend(s) to
+      ;; create the entries.
+      (unless matches
+       (let ((match (apply
+                     (slot-value backend 'search-function)
+                     :backend backend
+                     :create create
+                     :delete delete
+                     spec)))
+         (when match
+           (push (list backend match) matches))))
+
+      (setq backend (caar matches)
+           found-here (cadar matches))
+
+      (block nil
+       ;; if max is 0, as soon as we find something, return it
+       (when (and (zerop max) (> 0 (length found-here)))
+         (return t))
+
+       ;; decrement the goal by the number of new results
+       (decf goal (length found-here))
+       ;; and append the new results to the full list
+       (setq found (append found found-here))
+
+       (auth-source-do-debug
+        "auth-source-search: found %d results (max %d/%d) in %S matching %S"
+        (length found-here) max goal backend spec)
+
+       ;; return full list if the goal is 0 or negative
+       (when (zerop (max 0 goal))
+         (return found))
+
+       ;; change the :max parameter in the spec to the goal
+       (setq spec (plist-put spec :max goal))
+
+       (when (and found auth-source-do-cache)
+         (auth-source-remember spec found))))
+
+    found))
 
 ;;; (auth-source-search :max 1)
 ;;; (funcall (plist-get (nth 0 (auth-source-search :max 1)) :secret))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]