git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnav Bhate <bhatearnav@gmail.com>
To: git@vger.kernel.org
Subject: Defining timestamp_t as intmax_t instead of uintmax_t
Date: Tue, 11 Mar 2025 15:30:12 +0530	[thread overview]
Message-ID: <629c3c21-ab11-42c1-8cb1-34698e736db6@gmail.com> (raw)

timestamp_t is a data type defined in git-compat-util.h as uintmax_t since
28f4aee3fb (use uintmax_t for timestamps, 2017-04-26). It was introduced with
dddbad728c (timestamp_t: a new data type for timestamps, 2017-04-26) to replace
use of both time_t and unsigned long for time-related uses.

On Linux with glibc[1] and on Windows with MSVC[2], time_t is always a signed
type. I think this is also the case on MacOS and FreeBSD. Thus, any conversion
or comparison between the two types is one between a signed and an unsigned
type. This also means git cannot deal with time before 1970, though I can't
think of a scenario where it will have to. However, it does it to sign
compare warnings from the compiler.

I propose swapping uintmax_t with intmax_t to fix this problem. I do not think
that this will cause any problem unless any code sets the most significant bit
of the timestamp for some special purpose. However, the fix will take some
work, considering the number of references to timestamp_t. So I want to get
everyone's opinions on whether this should be done before starting work on it.

[1] https://www.gnu.org/software/libc/manual/html_node/Time-Types.html
[2] https://learn.microsoft.com/en-us/cpp/c-runtime-library/standard-types?view=msvc-170
-- 
Regards,
Arnav Bhate
(He/Him)


             reply	other threads:[~2025-03-11 10:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-11 10:00 Arnav Bhate [this message]
2025-03-11 10:54 ` Defining timestamp_t as intmax_t instead of uintmax_t Arnav Bhate
2025-03-11 17:28 ` Junio C Hamano
2025-03-11 18:23   ` Arnav Bhate

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=629c3c21-ab11-42c1-8cb1-34698e736db6@gmail.com \
    --to=bhatearnav@gmail.com \
    --cc=git@vger.kernel.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.
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 NNTP newsgroup(s).