branch: elpa/annotate commit e53c0f5adff8e8c0c6ef3f3ddca5706f974ccf70 Author: cage <cage-invalid@invalid> Commit: cage <cage-invalid@invalid>
- added checking encrypted (GPG) file format In many parts of the code we use 'annotate-guess-file-format', a function that try to guess the format of the file that produced the contents of a buffer. Sometimes (for example buffers that shows info nodes) this check is very expensive because involves reading (and possibly decompress or even decrypt) the file contents and check for a regular expression. If we could know in advance that the file is symmetrically encrypted with GPG we could skip other, more expensive checks for guessing file format (like info files). --- annotate.el | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/annotate.el b/annotate.el index db0fd1540f..59ceadfd99 100644 --- a/annotate.el +++ b/annotate.el @@ -2212,8 +2212,31 @@ sophisticated way than plain text" (and has-separator-p has-info-p)) :info - nil)))))) - (info-format-p))) + nil))))) + (gpg-format-p () + (with-temp-buffer + (let* ((magic-0 #x8c) + (magic-1 #x0d) + (magic-4 #x03) + (magic-5 #x02) + (attributes (file-attributes filename)) + (file-size (file-attribute-size attributes))) + (when (> file-size 6) + (let* ((bytes (insert-file-contents-literally filename + nil + 0 + 7))) + (setf bytes + (cl-loop for i from 1 to 6 collect + (elt (buffer-substring-no-properties i (1+ i)) + 0))) + (when (and (= (logand (elt bytes 0) #x0000ff) magic-0) + (= (logand (elt bytes 1) #x0000ff) magic-1) + (= (logand (elt bytes 4) #x0000ff) magic-4) + (= (logand (elt bytes 5) #x0000ff) magic-5)) + :encrypted-symmetric))))))) + (or (gpg-format-p) + (info-format-p)))) ;; keep this one for last as it is the slowest ;;;; summary window procedures