From: Paul Eggert Date: Mon, 1 Aug 2022 07:38:34 +0000 (-0700) Subject: Prefer ‘time-equal-p’ to ‘equal’ on timestamps X-Git-Tag: emacs-29.0.90~1447^2~575 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2cd204d8bbc5ef9bc049b593f85b2fa46c07db1b;p=emacs.git Prefer ‘time-equal-p’ to ‘equal’ on timestamps This is more robust since timestamps can have multiple forms. * lisp/auth-source.el (auth-source-netrc-parse): * lisp/bookmark.el (bookmark--watch-file-already-queried-p) (bookmark-maybe-load-default-file): * lisp/cedet/semantic/db.el (semanticdb-needs-refresh-p): * lisp/dired.el (dired-directory-changed-p): * lisp/files.el (dir-locals-find-file): * lisp/gnus/gnus-util.el (gnus-cache-file-contents): * lisp/gnus/nneething.el (nneething-create-mapping): * lisp/gnus/nnfolder.el (nnfolder-read-folder): * lisp/gnus/nnmaildir.el (nnmaildir--update-nov) (nnmaildir--scan, nnmaildir-request-scan) (nnmaildir-request-update-info): * lisp/gnus/nnmh.el (nnmh-update-gnus-unreads): * lisp/gnus/spam-stat.el (spam-stat-load): * lisp/mail/mailabbrev.el (mail-abbrevs-sync-aliases): * lisp/mail/sendmail.el (sendmail-sync-aliases): * lisp/net/netrc.el (netrc-parse): * lisp/nxml/rng-loc.el (rng-get-parsed-schema-locating-file): * lisp/play/cookie1.el (cookie-snarf): * lisp/vc/vc-cvs.el (vc-cvs-state-heuristic): * lisp/vc/vc-hg.el (vc-hg--ignore-patterns-valid-p) (vc-hg--cached-dirstate-search): * lisp/vc/vc-hooks.el (vc-after-save): Prefer ‘time-equal-p’ to ‘equal’ when comparing timestamps for equality. --- diff --git a/lisp/auth-source.el b/lisp/auth-source.el index a802ef856dc..a36386101af 100644 --- a/lisp/auth-source.el +++ b/lisp/auth-source.el @@ -957,7 +957,8 @@ Note that the MAX parameter is used so we can exit the parse early." result) (if (and (functionp cached-secrets) - (equal cached-mtime + (time-equal-p + cached-mtime (file-attribute-modification-time (file-attributes file)))) (progn diff --git a/lisp/bookmark.el b/lisp/bookmark.el index b2130557dcc..30a03e0431e 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el @@ -1172,7 +1172,7 @@ it to the name of the bookmark currently being set, advancing (defun bookmark--watch-file-already-queried-p (new-mtime) ;; Don't ask repeatedly if user already said "no" to reloading a ;; file with this mtime: - (prog1 (equal new-mtime bookmark--watch-already-asked-mtime) + (prog1 (time-equal-p new-mtime bookmark--watch-already-asked-mtime) (setq bookmark--watch-already-asked-mtime new-mtime))) (defun bookmark-maybe-load-default-file () @@ -1185,7 +1185,7 @@ it to the name of the bookmark currently being set, advancing (let ((new-mtime (nth 5 (file-attributes (car bookmark-bookmarks-timestamp)))) (old-mtime (cdr bookmark-bookmarks-timestamp))) - (and (not (equal new-mtime old-mtime)) + (and (not (time-equal-p new-mtime old-mtime)) (not (bookmark--watch-file-already-queried-p new-mtime)) (or (eq 'silent bookmark-watch-bookmark-file) (yes-or-no-p diff --git a/lisp/cedet/semantic/db.el b/lisp/cedet/semantic/db.el index 82785ec6d2e..757e46677ed 100644 --- a/lisp/cedet/semantic/db.el +++ b/lisp/cedet/semantic/db.el @@ -609,7 +609,7 @@ The file associated with OBJ does not need to be in a buffer." (or (not (slot-boundp obj 'tags)) ;; (not (oref obj tags)) --> not needed anymore? (/= (or (oref obj fsize) 0) actualsize) - (not (equal (oref obj lastmodtime) actualmod)) + (not (time-equal-p (oref obj lastmodtime) actualmod)) ) )))) diff --git a/lisp/dired.el b/lisp/dired.el index 7cdcc3438d8..f261f9f477a 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -1140,7 +1140,8 @@ If DIRNAME is already in a Dired buffer, that buffer is used without refresh." (modtime (visited-file-modtime))) (or (eq modtime 0) (not (eq (file-attribute-type attributes) t)) - (equal (file-attribute-modification-time attributes) modtime))))) + (time-equal-p (file-attribute-modification-time attributes) + modtime))))) (defvar auto-revert-remote-files) diff --git a/lisp/files.el b/lisp/files.el index 65f9039b33e..5df19661936 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -4446,7 +4446,8 @@ This function returns either: ;; The entry MTIME should match the most recent ;; MTIME among matching files. (and cached-files - (equal (nth 2 dir-elt) + (time-equal-p + (nth 2 dir-elt) (let ((latest 0)) (dolist (f cached-files latest) (let ((f-time diff --git a/lisp/gnus/gnus-util.el b/lisp/gnus/gnus-util.el index ea11642cf41..9bf48b1f4c3 100644 --- a/lisp/gnus/gnus-util.el +++ b/lisp/gnus/gnus-util.el @@ -1254,7 +1254,7 @@ SPEC is a predicate specifier that contains stuff like `or', `and', contents value) (if (or (null (setq value (symbol-value variable))) (not (equal (car value) file)) - (not (equal (nth 1 value) time))) + (not (time-equal-p (nth 1 value) time))) (progn (setq contents (funcall function file)) (set variable (list file time contents)) diff --git a/lisp/gnus/nneething.el b/lisp/gnus/nneething.el index 829d912cb2d..0c565a8230c 100644 --- a/lisp/gnus/nneething.el +++ b/lisp/gnus/nneething.el @@ -245,7 +245,8 @@ included.") (while map (if (and (member (cadr (car map)) files) ;; We also remove files that have changed mod times. - (equal (file-attribute-modification-time (file-attributes + (time-equal-p + (file-attribute-modification-time (file-attributes (nneething-file-name (cadr (car map))))) (cadr (cdar map)))) (progn diff --git a/lisp/gnus/nnfolder.el b/lisp/gnus/nnfolder.el index 5dc8e5c30d0..c3f7073a7b8 100644 --- a/lisp/gnus/nnfolder.el +++ b/lisp/gnus/nnfolder.el @@ -860,7 +860,8 @@ deleted. Point is left where the deleted region was." (nnheader-find-file-noselect file t))))) (mm-enable-multibyte) ;; Use multibyte buffer for future copying. (buffer-disable-undo) - (if (equal (cadr (assoc group nnfolder-scantime-alist)) + (if (time-equal-p + (cadr (assoc group nnfolder-scantime-alist)) (file-attribute-modification-time (file-attributes file))) ;; This looks up-to-date, so we don't do any scanning. (if (file-exists-p file) diff --git a/lisp/gnus/nnmaildir.el b/lisp/gnus/nnmaildir.el index 30f473b1291..98e074233df 100644 --- a/lisp/gnus/nnmaildir.el +++ b/lisp/gnus/nnmaildir.el @@ -463,7 +463,7 @@ This variable is set by `nnmaildir-request-article'.") ;; usable: if the message has been edited or if nnmail-extra-headers ;; has been augmented since this data was parsed from the message, ;; then we have to reparse. Otherwise it's up-to-date. - (when (and nov (equal mtime (nnmaildir--nov-get-mtime nov))) + (when (and nov (time-equal-p mtime (nnmaildir--nov-get-mtime nov))) ;; The timestamp matches. Now check nnmail-extra-headers. (setq old-extra (nnmaildir--nov-get-extra nov)) (when (equal nnmaildir--extra old-extra) ;; common case @@ -799,7 +799,7 @@ This variable is set by `nnmaildir-request-article'.") isnew (throw 'return t)) (setq nattr (file-attribute-modification-time nattr)) - (if (equal nattr (nnmaildir--grp-new group)) + (if (time-equal-p nattr (nnmaildir--grp-new group)) (setq nattr nil)) (if read-only (setq dir (and (or isnew nattr) ndir)) (when (or isnew nattr) @@ -811,7 +811,7 @@ This variable is set by `nnmaildir-request-article'.") (rename-file x (concat cdir (nnmaildir--ensure-suffix file))))) (setf (nnmaildir--grp-new group) nattr)) (setq cattr (file-attribute-modification-time (file-attributes cdir))) - (if (equal cattr (nnmaildir--grp-cur group)) + (if (time-equal-p cattr (nnmaildir--grp-cur group)) (setq cattr nil)) (setq dir (and (or isnew cattr) cdir))) (unless dir (throw 'return t)) @@ -899,7 +899,7 @@ This variable is set by `nnmaildir-request-article'.") (remhash scan-group groups)) (setq x (file-attribute-modification-time (file-attributes srv-dir)) scan-group (null scan-group)) - (if (equal x (nnmaildir--srv-mtime nnmaildir--cur-server)) + (if (time-equal-p x (nnmaildir--srv-mtime nnmaildir--cur-server)) (when scan-group (maphash (lambda (group-name _group) (nnmaildir--scan group-name t groups @@ -1049,7 +1049,7 @@ This variable is set by `nnmaildir-request-article'.") (t markdir-mtime)))) (puthash mark mtime new-mmth) - (when (equal mtime (gethash mark old-mmth)) + (when (time-equal-p mtime (gethash mark old-mmth)) (setq ranges (assq mark old-marks)) (if ranges (setq ranges (cdr ranges))) (throw 'got-ranges nil)) diff --git a/lisp/gnus/nnmh.el b/lisp/gnus/nnmh.el index 5d016267bc6..312a4a2a828 100644 --- a/lisp/gnus/nnmh.el +++ b/lisp/gnus/nnmh.el @@ -539,7 +539,7 @@ as unread by Gnus.") (let ((arts articles) art) (while (setq art (pop arts)) - (when (not (equal + (when (not (time-equal-p (file-attribute-modification-time (file-attributes (concat dir (int-to-string (car art))))) (cdr art))) diff --git a/lisp/gnus/spam-stat.el b/lisp/gnus/spam-stat.el index 084eb3d7745..5763ac14bb3 100644 --- a/lisp/gnus/spam-stat.el +++ b/lisp/gnus/spam-stat.el @@ -422,7 +422,8 @@ spam-stat (spam-stat-to-hash-table '(" spam-stat-ngood spam-stat-nbad)) (cond (spam-stat-dirty (message "Spam stat not loaded: spam-stat-dirty t")) ((or (not (boundp 'spam-stat-last-saved-at)) (null spam-stat-last-saved-at) - (not (equal spam-stat-last-saved-at + (not (time-equal-p + spam-stat-last-saved-at (file-attribute-modification-time (file-attributes spam-stat-file))))) (progn diff --git a/lisp/mail/mailabbrev.el b/lisp/mail/mailabbrev.el index e4061bd2f14..86711a4543f 100644 --- a/lisp/mail/mailabbrev.el +++ b/lisp/mail/mailabbrev.el @@ -163,7 +163,7 @@ no aliases, which is represented by this being a table with no entries.)") (if (file-exists-p mail-personal-alias-file) (let ((modtime (file-attribute-modification-time (file-attributes mail-personal-alias-file)))) - (if (not (equal mail-abbrev-modtime modtime)) + (if (not (time-equal-p mail-abbrev-modtime modtime)) (progn (setq mail-abbrev-modtime modtime) (build-mail-abbrevs))))))) diff --git a/lisp/mail/sendmail.el b/lisp/mail/sendmail.el index 76ef65b3437..f985b2ceac4 100644 --- a/lisp/mail/sendmail.el +++ b/lisp/mail/sendmail.el @@ -537,7 +537,7 @@ This also saves the value of `send-mail-function' via Customize." (when mail-personal-alias-file (let ((modtime (file-attribute-modification-time (file-attributes mail-personal-alias-file)))) - (or (equal mail-alias-modtime modtime) + (or (time-equal-p mail-alias-modtime modtime) (setq mail-alias-modtime modtime mail-aliases t))))) diff --git a/lisp/net/netrc.el b/lisp/net/netrc.el index c272c07e4c5..2f38e221781 100644 --- a/lisp/net/netrc.el +++ b/lisp/net/netrc.el @@ -63,8 +63,9 @@ "port")) alist elem result pair) (if (and netrc-cache - (equal (car netrc-cache) (file-attribute-modification-time - (file-attributes file)))) + (time-equal-p (car netrc-cache) + (file-attribute-modification-time + (file-attributes file)))) (insert (base64-decode-string (rot13-string (cdr netrc-cache)))) (insert-file-contents file) (when (string-match "\\.gpg\\'" file) diff --git a/lisp/nxml/rng-loc.el b/lisp/nxml/rng-loc.el index 0fa455cbb59..302aa05176f 100644 --- a/lisp/nxml/rng-loc.el +++ b/lisp/nxml/rng-loc.el @@ -414,7 +414,7 @@ or nil." (setq rng-schema-locating-file-alist (delq cached rng-schema-locating-file-alist))) nil) - ((and cached (equal (nth 1 cached) mtime)) + ((and cached (time-equal-p (nth 1 cached) mtime)) (nth 2 cached)) (t (setq parsed (rng-parse-schema-locating-file file)) diff --git a/lisp/play/cookie1.el b/lisp/play/cookie1.el index fcdd2a7ce94..7ede8e358aa 100644 --- a/lisp/play/cookie1.el +++ b/lisp/play/cookie1.el @@ -123,7 +123,8 @@ Emit STARTMSG and ENDMSG before and after. Cache the result; second and subsequent calls on the same file won't go to disk." (setq phrase-file (cookie-check-file phrase-file)) (let ((sym (intern-soft phrase-file cookie-cache))) - (and sym (not (equal (symbol-function sym) + (and sym (not (time-equal-p + (symbol-function sym) (file-attribute-modification-time (file-attributes phrase-file)))) (yes-or-no-p (concat phrase-file diff --git a/lisp/vc/vc-cvs.el b/lisp/vc/vc-cvs.el index 1f81ff2e0fe..52cc42791fa 100644 --- a/lisp/vc/vc-cvs.el +++ b/lisp/vc/vc-cvs.el @@ -250,7 +250,7 @@ See also variable `vc-cvs-sticky-date-format-string'." (let ((checkout-time (vc-file-getprop file 'vc-checkout-time)) (lastmod (file-attribute-modification-time (file-attributes file)))) (cond - ((equal checkout-time lastmod) 'up-to-date) + ((time-equal-p checkout-time lastmod) 'up-to-date) ((string= (vc-working-revision file) "0") 'added) ((null checkout-time) 'unregistered) (t 'edited)))) diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el index 026f125396e..5fba2b3908a 100644 --- a/lisp/vc/vc-hg.el +++ b/lisp/vc/vc-hg.el @@ -966,7 +966,7 @@ REPO must be the directory name of an hg repository." (attr (file-attributes (nth 0 fs))) (current-mtime (file-attribute-modification-time attr)) (current-size (file-attribute-size attr))) - (unless (and (equal saved-mtime current-mtime) + (unless (and (time-equal-p saved-mtime current-mtime) (equal saved-size current-size)) (setf valid nil)))) valid)) @@ -1037,7 +1037,7 @@ Avoids the need to repeatedly scan dirstate on repeated calls to ) (if (and cache (equal dirstate (pop cache)) - (equal mtime (pop cache)) + (time-equal-p mtime (pop cache)) (equal size (pop cache)) (equal ascii-fname (pop cache))) (pop cache) diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el index 80508570f32..405c9bc2ca4 100644 --- a/lisp/vc/vc-hooks.el +++ b/lisp/vc/vc-hooks.el @@ -631,9 +631,10 @@ Before doing that, check if there are any old backups and get rid of them." (cond ((null backend)) ((eq (vc-checkout-model backend (list file)) 'implicit) - ;; If the file was saved in the same second in which it was + ;; If the file was saved at the same time that it was ;; checked out, clear the checkout-time to avoid confusion. - (if (equal (vc-file-getprop file 'vc-checkout-time) + (if (time-equal-p + (vc-file-getprop file 'vc-checkout-time) (file-attribute-modification-time (file-attributes file))) (vc-file-setprop file 'vc-checkout-time nil)) (if (vc-state-refresh file backend)