unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Chong Yidong <cyd@stupidchicken.com>
Cc: 2833@emacsbugs.donarmstrong.com
Subject: bug#2833: 23.0.92; Bug in Directory Variables
Date: Thu, 09 Apr 2009 10:27:22 -0400	[thread overview]
Message-ID: <jwv63hdapcn.fsf-monnier+gnus-read-ephemeral-bug@gnu.org> (raw)
In-Reply-To: <87fxgicz1b.fsf@cyd.mit.edu> (Chong Yidong's message of "Wed, 08 Apr 2009 22:59:44 -0400")

> The following patch changes the directory local variables code so that
> the cache stores the file atime.  Before using each cache entry, we
> check that against the file modtime.

I'm not sure this is the right thing to do:
- We don't know that the (float-time) is in sync with the filesystem's
  time, so the check may not work right.  Better check the file's
  current mtime against the file's mtime when it was last read.
- the variable you changed could previously be setq in the .emacs,
  whereas you changed it into an internal var.

FWIW, here's the patch I was working on instead.


        Stefan


--- files.el.~1.1044.~	2009-04-08 20:09:55.000000000 -0400
+++ files.el	2009-04-09 10:24:53.000000000 -0400
@@ -3314,21 +3314,31 @@
 	  dir-elt)
       (or locals-file dir-elt))))
 
+(defvar dir-locals--file-cache nil
+  "Cache of dir-locals files's contents.")
+
 (defun dir-locals-read-from-file (file)
   "Load a variables FILE and register a new class and instance.
 FILE is the name of the file holding the variables to apply.
 The new class name is the same as the directory in which FILE
 is found.  Returns the new class name."
+  (let ((mtime (nth 5 (file-attributes file)))
+        (cache (assoc file dir-locals--file-cache)))
+    (unless (equal (nth 1 cache) mtime)
+      (setq dir-locals--file-cache (delq cache dir-locals--file-cache))
+      (setq cache nil))
+    (if cache
+        (nth 2 cache)
+      (let ((val
   (with-temp-buffer
-    ;; We should probably store the modtime of FILE and then
-    ;; reload it whenever it changes.
     (insert-file-contents file)
     (let* ((dir-name (file-name-directory file))
 	   (class-name (intern dir-name))
 	   (variables (read (current-buffer))))
       (dir-locals-set-class-variables class-name variables)
-      (dir-locals-set-directory-class dir-name class-name)
-      class-name)))
+                 class-name))))
+        (push (list file mtime val) dir-locals--file-cache)
+        val))))
 
 (declare-function c-postprocess-file-styles "cc-mode" ())
 






  parent reply	other threads:[~2009-04-09 14:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87fxgicz1b.fsf@cyd.mit.edu>
2009-04-09 11:03 ` bug#2833: 23.0.92; Bug in Directory Variables David De La Harpe Golden
2009-04-09 14:27 ` Stefan Monnier [this message]
2009-04-09 15:20   ` Chong Yidong
2009-04-11 15:31 Chong Yidong
2009-04-12 13:22 ` Leo
  -- strict thread matches above, loose matches on Subject: below --
2009-04-09  2:59 Chong Yidong
2009-04-09 11:31 ` Leo
2009-04-02 18:50 Chong Yidong
2009-03-31 14:32 Leo
2009-04-01  1:14 ` Stefan Monnier
2009-04-01 10:01   ` Leo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv63hdapcn.fsf-monnier+gnus-read-ephemeral-bug@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=2833@emacsbugs.donarmstrong.com \
    --cc=cyd@stupidchicken.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).