git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, Paul Eggert <eggert@cs.ucla.edu>,
	Eric Wong <e@80x24.org>, Taylor Blau <me@ttaylorr.com>
Subject: Re: [PATCH v2] git-compat-util: use gettimeofday(2) for time(2)
Date: Tue, 21 Mar 2023 13:04:49 -0700	[thread overview]
Message-ID: <xmqqh6udhnvi.fsf@gitster.g> (raw)
In-Reply-To: 20230321182252.GJ3119834@coredump.intra.peff.net

Jeff King <peff@peff.net> writes:

> This looks good to me, but I wanted to mention one alternative. If we
> are declaring that time() sucks and gettimeofday() is how to do it, then
> we could just use gettimeofday() everywhere, and add time() to banned.h
> to catch stragglers.
>
> It has two mild advantages:
>
>   1. gettimeofday() gives the callers extra resolution if they want it
>      (though in practice I guess none of them really do)

True.  Many of our data structures do not have room to store the
extra resolution right now.

>   2. It more directly describes what's going on, and we'd play fewer
>      games with macros (though we may end up with a git_gettimeofday()
>      wrapper if somebody doesn't support it; I really wonder about
>      Windows here).

I think they already have a compat/ function for their use in
compat/mingw.c so that may not be an issue.

> The disadvantage is that it's longer to type, and that you have to
> declare a timeval in the caller. So maybe it's a dumb idea.

Yes, you have to declare and use a timeval, but you are already
declaring and using time_t in today's code, so if we were writing
like so from scratch, the result wouldn't have been so bad.  We just
do nto use time_t and use timeval instead consistently.

The patch noise to go from here to there may not be worth it,
though.

Also, unless we are going to actively take advantage of extra
resolution, I am not sure if it is wise to ask for extra resolution
in the first place.  If time(2), at least on some platforms whose
maintainers care, gets corrected to avoid going backwards or being
inconsistent with filesystem timestamp in the future, converting
everything that calls time(2) to call gettimeofday(2) would lose
information---we will want to know which ones need only seconds
resolution and convert them back when the world advances.

So, I am not quite sure I am sold on the idea of rewriting
everything to use gettimeofday(2).

Thanks.


  parent reply	other threads:[~2023-03-21 20:05 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-19  6:43 [PATCH 0/2] use gettimeofday for current time Paul Eggert
2023-03-19  6:43 ` [PATCH 1/2] git-compat-util: time_now " Paul Eggert
2023-03-19  6:43 ` [PATCH 2/2] git-compat-util: use gettimeofday " Paul Eggert
2023-03-19 19:34   ` Eric Wong
2023-03-20 16:33     ` Junio C Hamano
2023-03-20 17:01       ` Junio C Hamano
2023-03-20 19:00         ` Paul Eggert
2023-03-20 19:40           ` Junio C Hamano
2023-03-20 20:36             ` Taylor Blau
2023-03-20 20:35       ` Taylor Blau
2023-03-20 23:05 ` [PATCH v2] git-compat-util: use gettimeofday(2) for time(2) Junio C Hamano
2023-03-20 23:21   ` Paul Eggert
2023-03-21 16:20     ` Junio C Hamano
2023-03-21 17:44   ` Konstantin Khomoutov
2023-03-21 18:22     ` Junio C Hamano
2023-03-21 18:22   ` Jeff King
2023-03-21 19:06     ` Taylor Blau
2023-03-21 20:04     ` Junio C Hamano [this message]
2023-03-22 17:11       ` Jeff King

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqqh6udhnvi.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=e@80x24.org \
    --cc=eggert@cs.ucla.edu \
    --cc=git@vger.kernel.org \
    --cc=me@ttaylorr.com \
    --cc=peff@peff.net \
    /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 public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).