Re: [PATCH 3/6] Introduce a new "printf format" for timestamps
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 1, 2017, 18:20 UTC
- Message-ID
- <xmqqbmtkhna9.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <f4ff525dda1964dd0e7cef1d0507e1f2403469e1.1488231002.git.johannes.schindelin@gmx.de>
Johannes Schindelin <johannes.schindelin@gmx.de> writes:
> So let's introduce the pseudo format "PRItime" (currently simply being > "lu") so that it is easy later on to change the data type to time_t.
The problem being solved is a good thing to solve, and
> - printf("author-time %lu\n", ci.author_time);
> + printf("author-time %"PRItime"\n", ci.author_time);is one of the two ingredients to the solution for this line. But the final form would require casting ci.author_time to the type expected by %PRItime format specifier. With this change alone, you could define PRItime to expect an winder type in the next step but that would be a bad conversion. IOW, changing only the format without introducing an explicit cast appears to invite future mistakes.
It would be better to introduce the timestamp_t we discussed earlier before (or at) this step, and typedef it to ulong first, and then in this step, change the above to
printf("author-time %"PRItime"\n", (timestamp_t)ci.author_time);to keep them in sync. And at a later step in the series, you can update definition of PRItime and timestamp_t to make them wider at the same time, and the changes in this patch like the above line would not need to be touched again.