emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r111828: * net/tramp-cache.el (tramp-


From: Michael Albinus
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111828: * net/tramp-cache.el (tramp-get-hash-table): New defun.
Date: Tue, 19 Feb 2013 16:17:55 +0100
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111828
committer: Michael Albinus <address@hidden
branch nick: trunk
timestamp: Tue 2013-02-19 16:17:55 +0100
message:
  * net/tramp-cache.el (tramp-get-hash-table): New defun.
  (tramp-get-file-property, tramp-set-file-property)
  (tramp-get-connection-property, tramp-set-connection-property): Use it.
  (tramp-flush-file-property, tramp-flush-directory-property):
  Rename argument to KEY.
  (tramp-flush-connection-property): Simplify a little bit.
  (tramp-connection-property-p): New defun.
  (top): Reapply saved values only if there isn't a corresponding
  entry in `tramp-connection-properties'.
modified:
  lisp/ChangeLog
  lisp/net/tramp-cache.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-02-19 03:29:28 +0000
+++ b/lisp/ChangeLog    2013-02-19 15:17:55 +0000
@@ -1,3 +1,15 @@
+2013-02-19  Michael Albinus  <address@hidden>
+
+       * net/tramp-cache.el (tramp-get-hash-table): New defun.
+       (tramp-get-file-property, tramp-set-file-property)
+       (tramp-get-connection-property, tramp-set-connection-property): Use it.
+       (tramp-flush-file-property, tramp-flush-directory-property):
+       Rename argument to KEY.
+       (tramp-flush-connection-property): Simplify a little bit.
+       (tramp-connection-property-p): New defun.
+       (top): Reapply saved values only if there isn't a corresponding
+       entry in `tramp-connection-properties'.
+
 2013-02-19  Fabián Ezequiel Gallina  <address@hidden>
 
        * progmodes/python.el (python-indent-context):

=== modified file 'lisp/net/tramp-cache.el'
--- a/lisp/net/tramp-cache.el   2013-02-16 17:44:00 +0000
+++ b/lisp/net/tramp-cache.el   2013-02-19 15:17:55 +0000
@@ -98,16 +98,30 @@
 (defvar tramp-cache-data-changed nil
   "Whether persistent cache data have been changed.")
 
+(defun tramp-get-hash-table (key)
+  "Returns the hash table for KEY.
+If it doesn't exist yet, it is created and initialized with
+matching entries of `tramp-connection-properties'."
+  (or (gethash key tramp-cache-data)
+      (let ((hash
+            (puthash key (make-hash-table :test 'equal) tramp-cache-data)))
+       (when (vectorp key)
+         (dolist (elt tramp-connection-properties)
+           (when (string-match
+                  (or (nth 0 elt) "")
+                  (tramp-make-tramp-file-name
+                   (aref key 0) (aref key 1) (aref key 2) nil))
+             (tramp-set-connection-property key (nth 1 elt) (nth 2 elt)))))
+       hash)))
+
 ;;;###tramp-autoload
-(defun tramp-get-file-property (vec file property default)
-  "Get the PROPERTY of FILE from the cache context of VEC.
+(defun tramp-get-file-property (key file property default)
+  "Get the PROPERTY of FILE from the cache context of KEY.
 Returns DEFAULT if not set."
   ;; Unify localname.
-  (setq vec (copy-sequence vec))
-  (aset vec 3 (tramp-run-real-handler 'directory-file-name (list file)))
-  (let* ((hash (or (gethash vec tramp-cache-data)
-                  (puthash vec (make-hash-table :test 'equal)
-                           tramp-cache-data)))
+  (setq key (copy-sequence key))
+  (aset key 3 (tramp-run-real-handler 'directory-file-name (list file)))
+  (let* ((hash (tramp-get-hash-table key))
         (value (when (hash-table-p hash) (gethash property hash))))
     (if
        ;; We take the value only if there is any, and
@@ -125,7 +139,7 @@
        (setq value (cdr value))
       (setq value default))
 
-    (tramp-message vec 8 "%s %s %s" file property value)
+    (tramp-message key 8 "%s %s %s" file property value)
     (when (>= tramp-verbose 10)
       (let* ((var (intern (concat "tramp-cache-get-count-" property)))
             (val (or (ignore-errors (symbol-value var)) 0)))
@@ -133,18 +147,16 @@
     value))
 
 ;;;###tramp-autoload
-(defun tramp-set-file-property (vec file property value)
-  "Set the PROPERTY of FILE to VALUE, in the cache context of VEC.
+(defun tramp-set-file-property (key file property value)
+  "Set the PROPERTY of FILE to VALUE, in the cache context of KEY.
 Returns VALUE."
   ;; Unify localname.
-  (setq vec (copy-sequence vec))
-  (aset vec 3 (tramp-run-real-handler 'directory-file-name (list file)))
-  (let ((hash (or (gethash vec tramp-cache-data)
-                 (puthash vec (make-hash-table :test 'equal)
-                          tramp-cache-data))))
+  (setq key (copy-sequence key))
+  (aset key 3 (tramp-run-real-handler 'directory-file-name (list file)))
+  (let ((hash (tramp-get-hash-table key)))
     ;; We put the timestamp there.
     (puthash property (cons (current-time) value) hash)
-    (tramp-message vec 8 "%s %s %s" file property value)
+    (tramp-message key 8 "%s %s %s" file property value)
     (when (>= tramp-verbose 10)
       (let* ((var (intern (concat "tramp-cache-set-count-" property)))
             (val (or (ignore-errors (symbol-value var)) 0)))
@@ -152,26 +164,26 @@
     value))
 
 ;;;###tramp-autoload
-(defun tramp-flush-file-property (vec file)
-  "Remove all properties of FILE in the cache context of VEC."
+(defun tramp-flush-file-property (key file)
+  "Remove all properties of FILE in the cache context of KEY."
   ;; Remove file property of symlinks.
-  (let ((truename (tramp-get-file-property vec file "file-truename" nil)))
+  (let ((truename (tramp-get-file-property key file "file-truename" nil)))
     (when (and (stringp truename)
               (not (string-equal file truename)))
-      (tramp-flush-file-property vec truename)))
+      (tramp-flush-file-property key truename)))
   ;; Unify localname.
-  (setq vec (copy-sequence vec))
-  (aset vec 3 (tramp-run-real-handler 'directory-file-name (list file)))
-  (tramp-message vec 8 "%s" file)
-  (remhash vec tramp-cache-data))
+  (setq key (copy-sequence key))
+  (aset key 3 (tramp-run-real-handler 'directory-file-name (list file)))
+  (tramp-message key 8 "%s" file)
+  (remhash key tramp-cache-data))
 
 ;;;###tramp-autoload
-(defun tramp-flush-directory-property (vec directory)
-  "Remove all properties of DIRECTORY in the cache context of VEC.
+(defun tramp-flush-directory-property (key directory)
+  "Remove all properties of DIRECTORY in the cache context of KEY.
 Remove also properties of all files in subdirectories."
   (let ((directory (tramp-run-real-handler
                    'directory-file-name (list directory))))
-  (tramp-message vec 8 "%s" directory)
+    (tramp-message key 8 "%s" directory)
     (maphash
      (lambda (key value)
        (when (and (stringp (tramp-file-name-localname key))
@@ -216,28 +228,10 @@
   (when (vectorp key)
     (setq key (copy-sequence key))
     (aset key 3 nil))
-  (let* ((hash (gethash key tramp-cache-data))
-        (value
-         (catch 'result
-           (or
-            ;; Check for dynamic properties.
-            (and
-             (hash-table-p hash)
-             (maphash
-              (lambda (x y) (when (equal x property) (throw 'result y)))
-              hash))
-            ;; Check for static properties.
-            (and
-             (vectorp key)
-             (dolist (elt tramp-connection-properties)
-               (when (and (string-match
-                           (or (nth 0 elt) "")
-                           (tramp-make-tramp-file-name
-                            (aref key 0) (aref key 1) (aref key 2) nil))
-                          (string-equal (or (nth 1 elt) "") (or property "")))
-                 (throw 'result (nth 2 elt)))))
-            ;; The default value.
-            default))))
+  (let* ((hash (tramp-get-hash-table key))
+        (value (if (hash-table-p hash)
+                   (gethash property hash default)
+                 default)))
     (tramp-message key 7 "%s %s" property value)
     value))
 
@@ -251,15 +245,19 @@
   (when (vectorp key)
     (setq key (copy-sequence key))
     (aset key 3 nil))
-  (let ((hash (or (gethash key tramp-cache-data)
-                 (puthash key (make-hash-table :test 'equal)
-                          tramp-cache-data))))
+  (let ((hash (tramp-get-hash-table key)))
     (puthash property value hash)
     (setq tramp-cache-data-changed t)
     (tramp-message key 7 "%s %s" property value)
     value))
 
 ;;;###tramp-autoload
+(defun tramp-connection-property-p (key property)
+  "Check whether named PROPERTY of a connection is defined.
+KEY identifies the connection, it is either a process or a vector."
+  (not (eq (tramp-get-connection-property key property 'undef) 'undef)))
+
+;;;###tramp-autoload
 (defun tramp-flush-connection-property (key)
   "Remove all properties identified by KEY.
 KEY identifies the connection, it is either a process or a vector."
@@ -272,10 +270,8 @@
    key 7 "%s %s" key
    (let ((hash (gethash key tramp-cache-data))
         properties)
-     (if (hash-table-p hash)
-        (maphash
-         (lambda (x y) (add-to-list 'properties x 'append))
-         (gethash key tramp-cache-data)))
+     (when (hash-table-p hash)
+       (maphash (lambda (x y) (add-to-list 'properties x 'append)) hash))
      properties))
   (setq tramp-cache-data-changed t)
   (remhash key tramp-cache-data))
@@ -396,7 +392,11 @@
          (while (setq element (pop list))
            (setq key (pop element))
            (while (setq item (pop element))
-             (tramp-set-connection-property key (pop item) (car item)))))
+             ;; We set only values which are not contained in
+             ;; `tramp-connection-properties'.  The cache is
+             ;; initialized properly by side effect.
+             (unless (tramp-connection-property-p key (car item))
+               (tramp-set-connection-property key (pop item) (car item))))))
        (setq tramp-cache-data-changed nil))
     (file-error
      ;; Most likely because the file doesn't exist yet.  No message.


reply via email to

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