{"thread":{"id":"63092","subject":"Defining timestamp_t as intmax_t instead of uintmax_t","startedAt":"2025-03-11T10:00:15Z","lastAt":"2025-03-11T18:23:57Z","messageCount":4,"participants":["Arnav Bhate","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"513973","messageId":"629c3c21-ab11-42c1-8cb1-34698e736db6@gmail.com","threadId":"63092","inReplyTo":null,"subject":"Defining timestamp_t as intmax_t instead of uintmax_t","fromName":"Arnav Bhate","fromEmail":"bhatearnav@gmail.com","sentAt":"2025-03-11T10:00:12Z","receivedAt":"2025-03-11T10:00:15Z","isPatch":false,"sender":{"key":"bhatearnav@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86760472?v=4"},"body":"timestamp_t is a data type defined in git-compat-util.h as uintmax_t since\n28f4aee3fb (use uintmax_t for timestamps, 2017-04-26). It was introduced with\ndddbad728c (timestamp_t: a new data type for timestamps, 2017-04-26) to replace\nuse of both time_t and unsigned long for time-related uses.\n\nOn Linux with glibc[1] and on Windows with MSVC[2], time_t is always a signed\ntype. I think this is also the case on MacOS and FreeBSD. Thus, any conversion\nor comparison between the two types is one between a signed and an unsigned\ntype. This also means git cannot deal with time before 1970, though I can't\nthink of a scenario where it will have to. However, it does it to sign\ncompare warnings from the compiler.\n\nI propose swapping uintmax_t with intmax_t to fix this problem. I do not think\nthat this will cause any problem unless any code sets the most significant bit\nof the timestamp for some special purpose. However, the fix will take some\nwork, considering the number of references to timestamp_t. So I want to get\neveryone's opinions on whether this should be done before starting work on it.\n\n[1] https://www.gnu.org/software/libc/manual/html_node/Time-Types.html\n[2] https://learn.microsoft.com/en-us/cpp/c-runtime-library/standard-types?view=msvc-170\n-- \nRegards,\nArnav Bhate\n(He/Him)\n\n"},{"id":"513974","messageId":"65ea4bed-1513-4721-af63-1ebc78194a7d@gmail.com","threadId":"63092","inReplyTo":"629c3c21-ab11-42c1-8cb1-34698e736db6@gmail.com","subject":"Re: Defining timestamp_t as intmax_t instead of uintmax_t","fromName":"Arnav Bhate","fromEmail":"bhatearnav@gmail.com","sentAt":"2025-03-11T10:54:21Z","receivedAt":"2025-03-11T10:54:25Z","isPatch":false,"sender":{"key":"bhatearnav@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86760472?v=4"},"body":"Arnav Bhate <bhatearnav@gmail.com> writes:\n> This also means git cannot deal with time before 1970, though I can't\n> think of a scenario where it will have to.\n\nI just tested and found that if the user enters dates before 1970 the output is\nincorrect, for example with git log. This error also seems to propagate to\nGitHub. This may or may not be related to using uintmax_t, however it seems\nlikely.\n\n-- \nRegards,\nArnav Bhate\n(He/Him)\n\n"},{"id":"513993","messageId":"xmqqv7sf32a6.fsf@gitster.g","threadId":"63092","inReplyTo":"629c3c21-ab11-42c1-8cb1-34698e736db6@gmail.com","subject":"Re: Defining timestamp_t as intmax_t instead of uintmax_t","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-03-11T17:28:17Z","receivedAt":"2025-03-11T17:28:20Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Arnav Bhate <bhatearnav@gmail.com> writes:\n\n> timestamp_t is a data type defined in git-compat-util.h as uintmax_t since\n> 28f4aee3fb (use uintmax_t for timestamps, 2017-04-26). It was introduced with\n> dddbad728c (timestamp_t: a new data type for timestamps, 2017-04-26) to replace\n> use of both time_t and unsigned long for time-related uses.\n\nI do not think the object format and the existing object parsers are\nprepared to handle timestamp before the epoch.\n\nYou may want to go back to the list archive for discussions around\nthe choice of the type back then, which should have enough\ninformation to go by.\n\nhttps://lore.kernel.org/git/20170228200145.ymbqmxwrbbrwagks@sigill.intra.peff.net/\n\nmight be a good starting point.\n\nhttps://lore.kernel.org/git/?q=f:peff@+d:20170201..20170430+timestamp_t\n\ngives 6 entry points to a single large thread that may be worth\nfollowing before tackling this topic further.\n\nThanks.\n"},{"id":"513996","messageId":"ab2af3ec-f4cf-4337-82ce-7c4ade244568@gmail.com","threadId":"63092","inReplyTo":"xmqqv7sf32a6.fsf@gitster.g","subject":"Re: Defining timestamp_t as intmax_t instead of uintmax_t","fromName":"Arnav Bhate","fromEmail":"bhatearnav@gmail.com","sentAt":"2025-03-11T18:23:53Z","receivedAt":"2025-03-11T18:23:57Z","isPatch":false,"sender":{"key":"bhatearnav@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86760472?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n> Arnav Bhate <bhatearnav@gmail.com> writes:\n> \n>> timestamp_t is a data type defined in git-compat-util.h as uintmax_t since\n>> 28f4aee3fb (use uintmax_t for timestamps, 2017-04-26). It was introduced with\n>> dddbad728c (timestamp_t: a new data type for timestamps, 2017-04-26) to replace\n>> use of both time_t and unsigned long for time-related uses.\n> \n> I do not think the object format and the existing object parsers are\n> prepared to handle timestamp before the epoch.\n\nLooks like I bit off more than I could chew. Maybe this could be a medium-sized\nproject in itself.\n\n> You may want to go back to the list archive for discussions around\n> the choice of the type back then, which should have enough\n> information to go by.\n> \n> https://lore.kernel.org/git/20170228200145.ymbqmxwrbbrwagks@sigill.intra.peff.net/\n> \n> might be a good starting point.\n> \n> https://lore.kernel.org/git/?q=f:peff@+d:20170201..20170430+timestamp_t\n> \n> gives 6 entry points to a single large thread that may be worth\n> following before tackling this topic further.\n> \n> Thanks.\n\nI'll go through it.\n\n-- \nRegards,\nArnav Bhate\n(He/Him)\n\n"}]}