all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Albinus <michael.albinus@gmx.de>
To: emacs-devel@gnu.org
Cc: Paul Eggert <eggert@cs.ucla.edu>
Subject: Re: master d0c77a1: Remove some assumptions about timestamp format
Date: Tue, 25 Sep 2018 12:09:53 +0200	[thread overview]
Message-ID: <87bm8lanwu.fsf@gmx.de> (raw)
In-Reply-To: <20180925021528.9A119204E8@vcs0.savannah.gnu.org> (Paul Eggert's message of "Mon, 24 Sep 2018 22:15:28 -0400 (EDT)")

eggert@cs.ucla.edu (Paul Eggert) writes:

Hi Paul,

>     Remove some assumptions about timestamp format
>     
>     These changes remove some assumptions of Lisp code on timestamp
>     format.  Although we’re not going to change the default format any
>     time soon, I went looking for code that was too intimate about
>     details of timestamp format and removed assumptions where this was
>     easy to do with current Emacs primitives.
>     * test/lisp/calendar/parse-time-tests.el (parse-time-tests):
>     * test/lisp/emacs-lisp/timer-tests.el (timer-test-multiple-of-time):
>     * test/lisp/net/tramp-tests.el:
>     (tramp-test19-directory-files-and-attributes)
>     (tramp-test22-file-times, tramp-test23-visited-file-modtime):
>     Don’t assume detailed format of returned Lisp timestamps.

> diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
> index 55884f3..7901355 100644
> --- a/test/lisp/net/tramp-tests.el
> +++ b/test/lisp/net/tramp-tests.el
> @@ -2882,16 +2882,16 @@ This tests also `file-readable-p', `file-regular-p' and
>  	    ;; able to return the date correctly.  They say "don't know".
>  	    (dolist (elt attr)
>  	      (unless
> -		  (equal
> -		   (nth
> -		    5 (file-attributes (expand-file-name (car elt) tmp-name2)))
> -		   '(0 0))
> +		  (zerop
> +		   (float-time
> +		    (nth 5 (file-attributes
> +			    (expand-file-name (car elt) tmp-name2)))))
>  		(should
>  		 (equal (file-attributes (expand-file-name (car elt) tmp-name2))
>  			(cdr elt)))))
>  	    (setq attr (directory-files-and-attributes tmp-name2 'full))
>  	    (dolist (elt attr)
> -	      (unless (equal (nth 5 (file-attributes (car elt))) '(0 0))
> +	      (unless (zerop (float-time (nth 5 (file-attributes (car elt)))))
>  		(should
>  		 (equal (file-attributes (car elt)) (cdr elt)))))
>  	    (setq attr (directory-files-and-attributes tmp-name2 nil "^b"))
> @@ -3215,14 +3215,14 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
>  	    (write-region "foo" nil tmp-name1)
>  	    (should (file-exists-p tmp-name1))
>  	    (should (consp (nth 5 (file-attributes tmp-name1))))
> -	    ;; '(0 0) means don't know, and will be replaced by
> -	    ;; `current-time'.  Therefore, we use '(0 1).  We skip the
> +	    ;; A zero timestamp means don't know, and will be replaced by
> +	    ;; `current-time'.  Therefore, use timestamp 1.  Skip the
>  	    ;; test, if the remote handler is not able to set the
>  	    ;; correct time.
>  	    (skip-unless (set-file-times tmp-name1 (seconds-to-time 1)))
>  	    ;; Dumb remote shells without perl(1) or stat(1) are not
>  	    ;; able to return the date correctly.  They say "don't know".
> -	    (unless (equal (nth 5 (file-attributes tmp-name1)) '(0 0))
> +	    (unless (zerop (float-time (nth 5 (file-attributes tmp-name1))))
>  	      (should
>  	       (equal (nth 5 (file-attributes tmp-name1)) (seconds-to-time 1)))
>  	      (write-region "bla" nil tmp-name2)
> @@ -3250,9 +3250,9 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
>  	    (with-temp-buffer
>  	      (insert-file-contents tmp-name)
>  	      (should (verify-visited-file-modtime))
> -	      (set-visited-file-modtime '(0 1))
> +              (set-visited-file-modtime (seconds-to-time 1))
>  	      (should (verify-visited-file-modtime))
> -	      (should (equal (visited-file-modtime) '(0 1 0 0)))))
> +	      (should (= 1 (float-time (visited-file-modtime))))))
>  
>  	;; Cleanup.
>  	(ignore-errors (delete-file tmp-name))))))

In the different tramp*.el files, '(0 0) is explicitly quoted as "don't
know value". This is there for ages.

If you want to change this in the tests, it shall be changed in
tramp*.el as well. Maybe it would be even worth an own constant?
Something like

(defconst time-dont-know (seconds-to-time 0)
  "A time value indicating an unknown time.")

If you like, it could even have the value 0 instead of (seconds-to-time
0). But this would also introduce "some assumptions of Lisp code on
timestamp format" - what you try to avoid.

Best regards, Michael.



       reply	other threads:[~2018-09-25 10:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20180925021527.10418.61555@vcs0.savannah.gnu.org>
     [not found] ` <20180925021528.9A119204E8@vcs0.savannah.gnu.org>
2018-09-25 10:09   ` Michael Albinus [this message]
2018-09-26  1:09     ` master d0c77a1: Remove some assumptions about timestamp format Paul Eggert
2018-09-26  9:24       ` Michael Albinus
2018-09-26  9:39         ` Eli Zaretskii
2018-09-26  9:43           ` Michael Albinus
2018-09-27 20:46         ` Paul Eggert
2018-09-28  6:32           ` Eli Zaretskii
2018-09-28 10:26             ` Michael Albinus
2018-09-28 17:27               ` Paul Eggert
2018-09-29 13:35                 ` Michael Albinus
2018-09-28 14:45             ` Paul Eggert
2018-09-28 14:54               ` Michael Albinus
2018-09-28  1:50         ` Paul Eggert
2018-09-28 10:35           ` Michael Albinus
2018-09-28 17:39             ` Paul Eggert
2018-09-28 18:06               ` Naming predicates (was: master d0c77a1: Remove some assumptions about timestamp format) Stefan Monnier
2018-09-28 18:28                 ` Drew Adams
2018-09-28 19:12                   ` Paul Eggert
2018-09-28 19:26                     ` Naming predicates Stefan Monnier
2018-09-28 19:40                       ` Drew Adams
2018-09-28 19:41                     ` Naming predicates (was: master d0c77a1: Remove some assumptions about timestamp format) Drew Adams

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

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

  git send-email \
    --in-reply-to=87bm8lanwu.fsf@gmx.de \
    --to=michael.albinus@gmx.de \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.