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

Re: [PATCH v2 1/2] t7508: add tests capturing racy timestamp handling

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 5, 2022, 20:59 UTC
Message-ID
<xmqqczl5hpaq.fsf@gitster.g>
In-Reply-To
<7d58f80611193f8696d99e317fe6b1e53ac740f7.1641388523.git.gitgitgadget@gmail.com>
"Marc Strapetz via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 30 quoted lines
> From: Marc Strapetz <marc.strapetz@syntevo.com>
>
> "git status" fixes racy timestamps regardless of the worktree being
> dirty or not. The new test cases capture this behavior.
>
> Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
> ---
>  t/t7508-status.sh | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
>
> diff --git a/t/t7508-status.sh b/t/t7508-status.sh
> index 05c6c02435d..652cbb5ed2e 100755
> --- a/t/t7508-status.sh
> +++ b/t/t7508-status.sh
> @@ -1656,4 +1656,32 @@ test_expect_success '--no-optional-locks prevents index update' '
>  	! grep ^1234567890 out
>  '
>  
> +test_expect_success 'racy timestamps will be fixed for clean worktree' '
> +	echo content >racy-dirty &&
> +	echo content >racy-racy &&
> +	git add racy* &&
> +	git commit -m "racy test files" &&
> +	# let status rewrite the index, if necessary; after that we expect
> +	# no more index writes unless caused by racy timestamps; note that
> +	# timestamps may already be racy now (depending on previous tests)
> +	git status &&
> +	test-tool chmtime =1234567890 .git/index &&
> +	test-tool chmtime --get .git/index >out &&
> +	grep ^1234567890 out &&

If file contents were 1234567890999, this will still hit, but I do not think that is what you wanted to see. Perhaps

	git status &&
	echo 1234567890 >expect &&
	test-tool chmtime=$(cat expect) .git/index &&
	test-tool chmtime --get .git/index >actual &&
	test_cmp expect actual

or something? But I think you inherited this bogosity from the previous test, so I am OK to add a few more copies of the same bogosity to the test.

Somebody later has to step in and clean them all up, though. When that happens, we should document how the magic 1234567890 timestamp was chosen near its first use.

I think it is because it is a timestamp in year 2009, so as long as your filetime clock is reasonably accurate, a write to the file would never get such a low timestamp.

> +	git status &&
> +	test-tool chmtime --get .git/index >out &&
> +	! grep ^1234567890 out
Previous: Marc Strapetz via GitGitGadgetNext: Marc Strapetz
Message 6 of 20 in “update-index: refresh should rewrite index in case of racy timestamps”
  1. update-index: refresh should rewrite index in case of racy timestampsMarc Strapetz via GitGitGadget, Dec 22, 2021
  2. Junio C HamanoDec 22, 2021
  3. Marc StrapetzDec 23, 2021
  4. 0/2 update-index: refresh should rewrite index in case of racy timestampsMarc Strapetz via GitGitGadget, Jan 5, 2022
  5. 1/2 t7508: add tests capturing racy timestamp handlingMarc Strapetz via GitGitGadget, Jan 5, 2022
  6. Junio C HamanoJan 5, 2022
  7. Marc StrapetzJan 6, 2022
  8. 2/2 update-index: refresh should rewrite index in case of racy timestampsMarc Strapetz via GitGitGadget, Jan 5, 2022
  9. Junio C HamanoJan 5, 2022
  10. 0/4 update-index: refresh should rewrite index in case of racy timestampsMarc Strapetz via GitGitGadget, Jan 6, 2022
  11. 1/4 test-lib: introduce API for verifying file mtimeMarc Strapetz via GitGitGadget, Jan 6, 2022
  12. Junio C HamanoJan 6, 2022
  13. 2/4 t7508: fix bogus mtime verificationMarc Strapetz via GitGitGadget, Jan 6, 2022
  14. 3/4 t7508: add tests capturing racy timestamp handlingMarc Strapetz via GitGitGadget, Jan 6, 2022
  15. 4/4 update-index: refresh should rewrite index in case of racy timestampsMarc Strapetz via GitGitGadget, Jan 6, 2022
  16. 0/4 update-index: refresh should rewrite index in case of racy timestampsMarc Strapetz via GitGitGadget, Jan 7, 2022
  17. 1/4 test-lib: introduce API for verifying file mtimeMarc Strapetz via GitGitGadget, Jan 7, 2022
  18. 2/4 t7508: fix bogus mtime verificationMarc Strapetz via GitGitGadget, Jan 7, 2022
  19. 3/4 t7508: add tests capturing racy timestamp handlingMarc Strapetz via GitGitGadget, Jan 7, 2022
  20. 4/4 update-index: refresh should rewrite index in case of racy timestampsMarc Strapetz via GitGitGadget, Jan 7, 2022

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.