changeset 91882:c694afffaf41

(locate-dominating-file): Remove initial loop because it's not careful enough. Detect the uid-change all within the main loop.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 16 Feb 2008 21:39:31 +0000
parents 6067cc57ab47
children 984503c8d1a0
files lisp/ChangeLog lisp/files.el
diffstat 2 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Sat Feb 16 18:08:41 2008 +0000
+++ b/lisp/ChangeLog	Sat Feb 16 21:39:31 2008 +0000
@@ -1,3 +1,8 @@
+2008-02-16  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* files.el (locate-dominating-file): Remove initial loop because it's
+	not careful enough.  Detect the uid-change all within the main loop.
+
 2008-02-16  Lawrence Mitchell  <wence@gmx.li>  (tiny change)
 
 	* ielm.el (ielm-is-whitespace-or-comment): Docstring fix.
--- a/lisp/files.el	Sat Feb 16 18:08:41 2008 +0000
+++ b/lisp/files.el	Sat Feb 16 21:39:31 2008 +0000
@@ -727,18 +727,22 @@
 
 (defun locate-dominating-file (file regexp)
   "Look up the directory hierarchy from FILE for a file matching REGEXP."
-  (while (and file (not (file-directory-p file)))
-    (setq file (file-name-directory (directory-file-name file))))
   (catch 'found
-    (let ((user (nth 2 (file-attributes file)))
+    ;; `user' is not initialized yet because `file' may not exist, so we may
+    ;; have to walk up part of the hierarchy before we find the "initial UID".
+    (let ((user nil)
           ;; Abbreviate, so as to stop when we cross ~/.
           (dir (abbreviate-file-name (file-name-as-directory file)))
           files)
-      ;; As a heuristic, we stop looking up the hierarchy of directories as
-      ;; soon as we find a directory belonging to another user.  This should
-      ;; save us from looking in things like /net and /afs.  This assumes
-      ;; that all the files inside a project belong to the same user.
-      (while (and dir (equal user (nth 2 (file-attributes dir))))
+      (while (and dir
+                  ;; As a heuristic, we stop looking up the hierarchy of
+                  ;; directories as soon as we find a directory belonging to
+                  ;; another user.  This should save us from looking in
+                  ;; things like /net and /afs.  This assumes that all the
+                  ;; files inside a project belong to the same user.
+                  (let ((prev-user user))
+                    (setq user (nth 2 (file-attributes file)))
+                    (not (or (null prev-user) (equal user prev-user)))))
         (if (setq files (directory-files dir 'full regexp))
             (throw 'found (car files))
           (if (equal dir