Skip to content

pr-2318/letmaik/diff-lib-fsmonitor-leading-path-v1

tagged this 18 Nov 18:22
From: Maik Riechert <letmaik@outlook.com>

Since 4f3d6d0261 (fsmonitor: skip lstat deletion check during git
diff-index, 2021-03-17), check_removed() does not lstat() entries
that fsmonitor says are unchanged. But it still calls
has_symlink_leading_path() for them, which lstat()s the directories
leading up to each path.

That check is there to notice a leading directory that was replaced
by a symlink. fsmonitor would have reported such a change, and
refresh_fsmonitor() would have cleared CE_FSMONITOR_VALID for every
entry below it, so we would not get here. preload_index() already
trusts the flag this way and skips these entries altogether.

The S_ISDIR() check that follows cannot trigger either: the mode
comes from the index, and gitlinks are never marked valid.

So return as soon as fake_lstat() has filled in the stat data.

The first new test checks the shortcut itself by replacing a parent
directory with a symlink without telling fsmonitor. The other two make
sure we still notice when fsmonitor does report that directory, with
and without a trailing slash, since nothing else checks for it now.

On Linux, with 100,000 files (ten per directory), a hook that
reports nothing and a warm cache, "git diff HEAD" goes from 57ms to
26ms.

Signed-off-by: Maik Riechert <letmaik@outlook.com>

Submitted-As: https://lore.kernel.org/git/pull.2318.git.1795026168007.gitgitgadget@gmail.com
Assets 2
Loading