diff options
| author | Michael Albinus | 2013-02-19 16:17:55 +0100 |
|---|---|---|
| committer | Michael Albinus | 2013-02-19 16:17:55 +0100 |
| commit | 81ed22e4cad625e297314bc609d146e7e62695db (patch) | |
| tree | 0281493f15f2608378187d647d755dc09a4f3296 | |
| parent | 8b17a8b9583e8e4af9d6a66ca7319a398040e19f (diff) | |
| download | emacs-81ed22e4cad625e297314bc609d146e7e62695db.tar.gz emacs-81ed22e4cad625e297314bc609d146e7e62695db.zip | |
* 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'.
| -rw-r--r-- | lisp/ChangeLog | 12 | ||||
| -rw-r--r-- | lisp/net/tramp-cache.el | 114 |
2 files changed, 69 insertions, 57 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d430ba0908f..c1e75fcdca8 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2013-02-19 Michael Albinus <michael.albinus@gmx.de> | ||
| 2 | |||
| 3 | * net/tramp-cache.el (tramp-get-hash-table): New defun. | ||
| 4 | (tramp-get-file-property, tramp-set-file-property) | ||
| 5 | (tramp-get-connection-property, tramp-set-connection-property): Use it. | ||
| 6 | (tramp-flush-file-property, tramp-flush-directory-property): | ||
| 7 | Rename argument to KEY. | ||
| 8 | (tramp-flush-connection-property): Simplify a little bit. | ||
| 9 | (tramp-connection-property-p): New defun. | ||
| 10 | (top): Reapply saved values only if there isn't a corresponding | ||
| 11 | entry in `tramp-connection-properties'. | ||
| 12 | |||
| 1 | 2013-02-19 Fabián Ezequiel Gallina <fgallina@cuca> | 13 | 2013-02-19 Fabián Ezequiel Gallina <fgallina@cuca> |
| 2 | 14 | ||
| 3 | * progmodes/python.el (python-indent-context): | 15 | * progmodes/python.el (python-indent-context): |
diff --git a/lisp/net/tramp-cache.el b/lisp/net/tramp-cache.el index dc45a57b7c6..13a955ff579 100644 --- a/lisp/net/tramp-cache.el +++ b/lisp/net/tramp-cache.el | |||
| @@ -98,16 +98,30 @@ matching entry in for PROPERTY in `tramp-cache-data'." | |||
| 98 | (defvar tramp-cache-data-changed nil | 98 | (defvar tramp-cache-data-changed nil |
| 99 | "Whether persistent cache data have been changed.") | 99 | "Whether persistent cache data have been changed.") |
| 100 | 100 | ||
| 101 | (defun tramp-get-hash-table (key) | ||
| 102 | "Returns the hash table for KEY. | ||
| 103 | If it doesn't exist yet, it is created and initialized with | ||
| 104 | matching entries of `tramp-connection-properties'." | ||
| 105 | (or (gethash key tramp-cache-data) | ||
| 106 | (let ((hash | ||
| 107 | (puthash key (make-hash-table :test 'equal) tramp-cache-data))) | ||
| 108 | (when (vectorp key) | ||
| 109 | (dolist (elt tramp-connection-properties) | ||
| 110 | (when (string-match | ||
| 111 | (or (nth 0 elt) "") | ||
| 112 | (tramp-make-tramp-file-name | ||
| 113 | (aref key 0) (aref key 1) (aref key 2) nil)) | ||
| 114 | (tramp-set-connection-property key (nth 1 elt) (nth 2 elt))))) | ||
| 115 | hash))) | ||
| 116 | |||
| 101 | ;;;###tramp-autoload | 117 | ;;;###tramp-autoload |
| 102 | (defun tramp-get-file-property (vec file property default) | 118 | (defun tramp-get-file-property (key file property default) |
| 103 | "Get the PROPERTY of FILE from the cache context of VEC. | 119 | "Get the PROPERTY of FILE from the cache context of KEY. |
| 104 | Returns DEFAULT if not set." | 120 | Returns DEFAULT if not set." |
| 105 | ;; Unify localname. | 121 | ;; Unify localname. |
| 106 | (setq vec (copy-sequence vec)) | 122 | (setq key (copy-sequence key)) |
| 107 | (aset vec 3 (tramp-run-real-handler 'directory-file-name (list file))) | 123 | (aset key 3 (tramp-run-real-handler 'directory-file-name (list file))) |
| 108 | (let* ((hash (or (gethash vec tramp-cache-data) | 124 | (let* ((hash (tramp-get-hash-table key)) |
| 109 | (puthash vec (make-hash-table :test 'equal) | ||
| 110 | tramp-cache-data))) | ||
| 111 | (value (when (hash-table-p hash) (gethash property hash)))) | 125 | (value (when (hash-table-p hash) (gethash property hash)))) |
| 112 | (if | 126 | (if |
| 113 | ;; We take the value only if there is any, and | 127 | ;; We take the value only if there is any, and |
| @@ -125,7 +139,7 @@ Returns DEFAULT if not set." | |||
| 125 | (setq value (cdr value)) | 139 | (setq value (cdr value)) |
| 126 | (setq value default)) | 140 | (setq value default)) |
| 127 | 141 | ||
| 128 | (tramp-message vec 8 "%s %s %s" file property value) | 142 | (tramp-message key 8 "%s %s %s" file property value) |
| 129 | (when (>= tramp-verbose 10) | 143 | (when (>= tramp-verbose 10) |
| 130 | (let* ((var (intern (concat "tramp-cache-get-count-" property))) | 144 | (let* ((var (intern (concat "tramp-cache-get-count-" property))) |
| 131 | (val (or (ignore-errors (symbol-value var)) 0))) | 145 | (val (or (ignore-errors (symbol-value var)) 0))) |
| @@ -133,18 +147,16 @@ Returns DEFAULT if not set." | |||
| 133 | value)) | 147 | value)) |
| 134 | 148 | ||
| 135 | ;;;###tramp-autoload | 149 | ;;;###tramp-autoload |
| 136 | (defun tramp-set-file-property (vec file property value) | 150 | (defun tramp-set-file-property (key file property value) |
| 137 | "Set the PROPERTY of FILE to VALUE, in the cache context of VEC. | 151 | "Set the PROPERTY of FILE to VALUE, in the cache context of KEY. |
| 138 | Returns VALUE." | 152 | Returns VALUE." |
| 139 | ;; Unify localname. | 153 | ;; Unify localname. |
| 140 | (setq vec (copy-sequence vec)) | 154 | (setq key (copy-sequence key)) |
| 141 | (aset vec 3 (tramp-run-real-handler 'directory-file-name (list file))) | 155 | (aset key 3 (tramp-run-real-handler 'directory-file-name (list file))) |
| 142 | (let ((hash (or (gethash vec tramp-cache-data) | 156 | (let ((hash (tramp-get-hash-table key))) |
| 143 | (puthash vec (make-hash-table :test 'equal) | ||
| 144 | tramp-cache-data)))) | ||
| 145 | ;; We put the timestamp there. | 157 | ;; We put the timestamp there. |
| 146 | (puthash property (cons (current-time) value) hash) | 158 | (puthash property (cons (current-time) value) hash) |
| 147 | (tramp-message vec 8 "%s %s %s" file property value) | 159 | (tramp-message key 8 "%s %s %s" file property value) |
| 148 | (when (>= tramp-verbose 10) | 160 | (when (>= tramp-verbose 10) |
| 149 | (let* ((var (intern (concat "tramp-cache-set-count-" property))) | 161 | (let* ((var (intern (concat "tramp-cache-set-count-" property))) |
| 150 | (val (or (ignore-errors (symbol-value var)) 0))) | 162 | (val (or (ignore-errors (symbol-value var)) 0))) |
| @@ -152,26 +164,26 @@ Returns VALUE." | |||
| 152 | value)) | 164 | value)) |
| 153 | 165 | ||
| 154 | ;;;###tramp-autoload | 166 | ;;;###tramp-autoload |
| 155 | (defun tramp-flush-file-property (vec file) | 167 | (defun tramp-flush-file-property (key file) |
| 156 | "Remove all properties of FILE in the cache context of VEC." | 168 | "Remove all properties of FILE in the cache context of KEY." |
| 157 | ;; Remove file property of symlinks. | 169 | ;; Remove file property of symlinks. |
| 158 | (let ((truename (tramp-get-file-property vec file "file-truename" nil))) | 170 | (let ((truename (tramp-get-file-property key file "file-truename" nil))) |
| 159 | (when (and (stringp truename) | 171 | (when (and (stringp truename) |
| 160 | (not (string-equal file truename))) | 172 | (not (string-equal file truename))) |
| 161 | (tramp-flush-file-property vec truename))) | 173 | (tramp-flush-file-property key truename))) |
| 162 | ;; Unify localname. | 174 | ;; Unify localname. |
| 163 | (setq vec (copy-sequence vec)) | 175 | (setq key (copy-sequence key)) |
| 164 | (aset vec 3 (tramp-run-real-handler 'directory-file-name (list file))) | 176 | (aset key 3 (tramp-run-real-handler 'directory-file-name (list file))) |
| 165 | (tramp-message vec 8 "%s" file) | 177 | (tramp-message key 8 "%s" file) |
| 166 | (remhash vec tramp-cache-data)) | 178 | (remhash key tramp-cache-data)) |
| 167 | 179 | ||
| 168 | ;;;###tramp-autoload | 180 | ;;;###tramp-autoload |
| 169 | (defun tramp-flush-directory-property (vec directory) | 181 | (defun tramp-flush-directory-property (key directory) |
| 170 | "Remove all properties of DIRECTORY in the cache context of VEC. | 182 | "Remove all properties of DIRECTORY in the cache context of KEY. |
| 171 | Remove also properties of all files in subdirectories." | 183 | Remove also properties of all files in subdirectories." |
| 172 | (let ((directory (tramp-run-real-handler | 184 | (let ((directory (tramp-run-real-handler |
| 173 | 'directory-file-name (list directory)))) | 185 | 'directory-file-name (list directory)))) |
| 174 | (tramp-message vec 8 "%s" directory) | 186 | (tramp-message key 8 "%s" directory) |
| 175 | (maphash | 187 | (maphash |
| 176 | (lambda (key value) | 188 | (lambda (key value) |
| 177 | (when (and (stringp (tramp-file-name-localname key)) | 189 | (when (and (stringp (tramp-file-name-localname key)) |
| @@ -216,28 +228,10 @@ If the value is not set for the connection, returns DEFAULT." | |||
| 216 | (when (vectorp key) | 228 | (when (vectorp key) |
| 217 | (setq key (copy-sequence key)) | 229 | (setq key (copy-sequence key)) |
| 218 | (aset key 3 nil)) | 230 | (aset key 3 nil)) |
| 219 | (let* ((hash (gethash key tramp-cache-data)) | 231 | (let* ((hash (tramp-get-hash-table key)) |
| 220 | (value | 232 | (value (if (hash-table-p hash) |
| 221 | (catch 'result | 233 | (gethash property hash default) |
| 222 | (or | 234 | default))) |
| 223 | ;; Check for dynamic properties. | ||
| 224 | (and | ||
| 225 | (hash-table-p hash) | ||
| 226 | (maphash | ||
| 227 | (lambda (x y) (when (equal x property) (throw 'result y))) | ||
| 228 | hash)) | ||
| 229 | ;; Check for static properties. | ||
| 230 | (and | ||
| 231 | (vectorp key) | ||
| 232 | (dolist (elt tramp-connection-properties) | ||
| 233 | (when (and (string-match | ||
| 234 | (or (nth 0 elt) "") | ||
| 235 | (tramp-make-tramp-file-name | ||
| 236 | (aref key 0) (aref key 1) (aref key 2) nil)) | ||
| 237 | (string-equal (or (nth 1 elt) "") (or property ""))) | ||
| 238 | (throw 'result (nth 2 elt))))) | ||
| 239 | ;; The default value. | ||
| 240 | default)))) | ||
| 241 | (tramp-message key 7 "%s %s" property value) | 235 | (tramp-message key 7 "%s %s" property value) |
| 242 | value)) | 236 | value)) |
| 243 | 237 | ||
| @@ -251,15 +245,19 @@ PROPERTY is set persistent when KEY is a vector." | |||
| 251 | (when (vectorp key) | 245 | (when (vectorp key) |
| 252 | (setq key (copy-sequence key)) | 246 | (setq key (copy-sequence key)) |
| 253 | (aset key 3 nil)) | 247 | (aset key 3 nil)) |
| 254 | (let ((hash (or (gethash key tramp-cache-data) | 248 | (let ((hash (tramp-get-hash-table key))) |
| 255 | (puthash key (make-hash-table :test 'equal) | ||
| 256 | tramp-cache-data)))) | ||
| 257 | (puthash property value hash) | 249 | (puthash property value hash) |
| 258 | (setq tramp-cache-data-changed t) | 250 | (setq tramp-cache-data-changed t) |
| 259 | (tramp-message key 7 "%s %s" property value) | 251 | (tramp-message key 7 "%s %s" property value) |
| 260 | value)) | 252 | value)) |
| 261 | 253 | ||
| 262 | ;;;###tramp-autoload | 254 | ;;;###tramp-autoload |
| 255 | (defun tramp-connection-property-p (key property) | ||
| 256 | "Check whether named PROPERTY of a connection is defined. | ||
| 257 | KEY identifies the connection, it is either a process or a vector." | ||
| 258 | (not (eq (tramp-get-connection-property key property 'undef) 'undef))) | ||
| 259 | |||
| 260 | ;;;###tramp-autoload | ||
| 263 | (defun tramp-flush-connection-property (key) | 261 | (defun tramp-flush-connection-property (key) |
| 264 | "Remove all properties identified by KEY. | 262 | "Remove all properties identified by KEY. |
| 265 | KEY identifies the connection, it is either a process or a vector." | 263 | KEY identifies the connection, it is either a process or a vector." |
| @@ -272,10 +270,8 @@ KEY identifies the connection, it is either a process or a vector." | |||
| 272 | key 7 "%s %s" key | 270 | key 7 "%s %s" key |
| 273 | (let ((hash (gethash key tramp-cache-data)) | 271 | (let ((hash (gethash key tramp-cache-data)) |
| 274 | properties) | 272 | properties) |
| 275 | (if (hash-table-p hash) | 273 | (when (hash-table-p hash) |
| 276 | (maphash | 274 | (maphash (lambda (x y) (add-to-list 'properties x 'append)) hash)) |
| 277 | (lambda (x y) (add-to-list 'properties x 'append)) | ||
| 278 | (gethash key tramp-cache-data))) | ||
| 279 | properties)) | 275 | properties)) |
| 280 | (setq tramp-cache-data-changed t) | 276 | (setq tramp-cache-data-changed t) |
| 281 | (remhash key tramp-cache-data)) | 277 | (remhash key tramp-cache-data)) |
| @@ -396,7 +392,11 @@ for all methods. Resulting data are derived from connection history." | |||
| 396 | (while (setq element (pop list)) | 392 | (while (setq element (pop list)) |
| 397 | (setq key (pop element)) | 393 | (setq key (pop element)) |
| 398 | (while (setq item (pop element)) | 394 | (while (setq item (pop element)) |
| 399 | (tramp-set-connection-property key (pop item) (car item))))) | 395 | ;; We set only values which are not contained in |
| 396 | ;; `tramp-connection-properties'. The cache is | ||
| 397 | ;; initialized properly by side effect. | ||
| 398 | (unless (tramp-connection-property-p key (car item)) | ||
| 399 | (tramp-set-connection-property key (pop item) (car item)))))) | ||
| 400 | (setq tramp-cache-data-changed nil)) | 400 | (setq tramp-cache-data-changed nil)) |
| 401 | (file-error | 401 | (file-error |
| 402 | ;; Most likely because the file doesn't exist yet. No message. | 402 | ;; Most likely because the file doesn't exist yet. No message. |