git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] read-cache: use time_t instead of unsigned long

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 12, 2018, 10:53 UTC
Message-ID
<xmqqftw61sa0.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20181112084031.11769-3-carenas@gmail.com>
Carlo Marcelo Arenas Belón  <carenas@gmail.com> writes:
Show 28 quoted lines
> b968372279 ("read-cache: unlink old sharedindex files", 2017-03-06)
> introduced get_shared_index_expire_date using unsigned long to track
> the modification times of a shared index.
>
> dddbad728c ("timestamp_t: a new data type for timestamps", 2017-04-26)
> shows why that might problematic so move to time_t instead.
>
> Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
> ---
>  read-cache.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/read-cache.c b/read-cache.c
> index 7b1354d759..5525d8e679 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -2625,9 +2625,9 @@ static int write_split_index(struct index_state *istate,
>  
>  static const char *shared_index_expire = "2.weeks.ago";
>  
> -static unsigned long get_shared_index_expire_date(void)
> +static time_t get_shared_index_expire_date(void)
>  {
> -	static unsigned long shared_index_expire_date;
> +	static time_t shared_index_expire_date;
>  	static int shared_index_expire_date_prepared;
>  
>  	if (!shared_index_expire_date_prepared) {
After this line, the post-context reads like this:
		git_config_get_expiry("splitindex.sharedindexexpire",
				      &shared_index_expire);
		shared_index_expire_date = approxidate(shared_index_expire);
		shared_index_expire_date_prepared = 1;
	}
	return shared_index_expire_date;

Given that the function returns the value obtained from approxidate(), which is approxidate_careful() in disguise, time_t is not as appropriate as timestamp_t, no?

IOW, what if time_t were narrower than timestamp_t?
Show 9 quoted lines
> @@ -2643,7 +2643,7 @@ static unsigned long get_shared_index_expire_date(void)
>  static int should_delete_shared_index(const char *shared_index_path)
>  {
>  	struct stat st;
> -	unsigned long expiration;
> +	time_t expiration;
>  
>  	/* Check timestamp */
>  	expiration = get_shared_index_expire_date();
Previous: Eric SunshineNext: Johannes Schindelin
Message 5 of 12 in “avoid unsigned long for timestamps”
  1. 0/2 avoid unsigned long for timestampsCarlo Marcelo Arenas Belón, Nov 12, 2018
  2. 1/2 builtin/commit: use timestamp_t in parse_force_dateCarlo Marcelo Arenas Belón, Nov 12, 2018
  3. 2/2 read-cache: use time_t instead of unsigned longCarlo Marcelo Arenas Belón, Nov 12, 2018
  4. Eric SunshineNov 12, 2018
  5. Junio C HamanoNov 12, 2018
  6. Johannes SchindelinNov 12, 2018
  7. Junio C HamanoNov 12, 2018
  8. 2/2 read-cache: use time_t instead of unsigned longCarlo Marcelo Arenas Belón, Nov 13, 2018
  9. Johannes SchindelinNov 13, 2018
  10. Carlo ArenasNov 13, 2018
  11. Junio C HamanoNov 13, 2018
  12. Johannes SchindelinNov 12, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.