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
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Nov 13, 2018, 08:49 UTC
Message-ID
<nycvar.QRO.7.76.6.1811130948420.39@tvgsbejvaqbjf.bet>
In-Reply-To
<20181113074017.17292-1-carenas@gmail.com>
Hi,
On Mon, 12 Nov 2018, Carlo Marcelo Arenas Belón wrote:
Show 22 quoted lines
> There are still some more possible improvements around this code but
> they are orthogonal to this change :
> 
> * migrate to approxidate_careful or parse_expiry_date
> * maybe make sure only approxidate are used for expiration
> 
> Changes in v2:
> * improved commit message as suggested by Eric
> * failsafe against time_t truncation as suggested by Junio
> 
> -- >8 --
> Subject: [PATCH v2 2/2] read-cache: use time specific types instead of
>  unsigned long
> 
> 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 be problematic so move to timestamp_t/time_t.
> 
> if time_t can't represent a valid time keep the indexes for failsafe
Is this sentence incomplete? What are those "indexes"?

Thanks, Johannes

Show 43 quoted lines
> 
> Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
> ---
>  read-cache.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/read-cache.c b/read-cache.c
> index 7b1354d759..7d322f11c8 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 timestamp_t get_shared_index_expire_date(void)
>  {
> -	static unsigned long shared_index_expire_date;
> +	static timestamp_t shared_index_expire_date;
>  	static int shared_index_expire_date_prepared;
>  
>  	if (!shared_index_expire_date_prepared) {
> @@ -2643,12 +2643,12 @@ 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;
> +	timestamp_t t = get_shared_index_expire_date();
>  
> -	/* Check timestamp */
> -	expiration = get_shared_index_expire_date();
> -	if (!expiration)
> +	if (!t || date_overflows(t))
>  		return 0;
> +	expiration = t;
>  	if (stat(shared_index_path, &st))
>  		return error_errno(_("could not stat '%s'"), shared_index_path);
>  	if (st.st_mtime > expiration)
> -- 
> 2.19.1.856.g8858448bb
> 
> 
Previous: Carlo Marcelo Arenas BelónNext: Carlo Arenas
Message 9 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.