Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dir.c: regression fix for add_excludes with fscache #1407

Merged
merged 2 commits into from
Dec 20, 2017

Conversation

jeffhostetler
Copy link

Fix regression described in:
#1392
which was introduced in:
b235337

When the user has a .gitignore file that is a symlink, the fscache
optimization introduced above caused the stat-data from the symlink,
rather that of the target file, to be returned. Later when the ignore
file was read, the buffer length did not match the stat.st_size field
and we called die("cannot use as an exclude file")

Added code to replace the stat-data when the path is a symlink. This
preserves the effect of the performance gains for the normal case where
it is not a symlink.

Signed-off-by: Jeff Hostetler jeffhost@microsoft.com

dir.c Outdated
* If the .gitignore file is successfully opened and in the
* rare case that it is a symlink, we fstat it to replace the
* original lstat stat-data to complete our illusion.
*/
if (lstat(fname, &st) < 0) {

This comment was marked as off-topic.

This comment was marked as off-topic.

@@ -257,7 +252,7 @@ static void fscache_clear(void)
/*
* Checks if the cache is enabled for the given path.
*/
static inline int fscache_enabled(const char *path)
int fscache_enabled(const char *path)

This comment was marked as off-topic.

Make fscache_enabled() function public rather than static.
Remove unneeded fscache_is_enabled() function.
Change is_fscache_enabled() macro to call fscache_enabled().

is_fscache_enabled() now takes a pathname so that the answer
is more precise and mean "is fscache enabled for this pathname",
since fscache only stores repo-relative paths and not absolute
paths, we can avoid attempting lookups for absolute paths.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Fix regression described in:
git-for-windows#1392

which was introduced in:
git-for-windows@b235337

Problem Symptoms
================
When the user has a .gitignore file that is a symlink, the fscache
optimization introduced above caused the stat-data from the symlink,
rather that of the target file, to be returned.  Later when the ignore
file was read, the buffer length did not match the stat.st_size field
and we called die("cannot use <path> as an exclude file")

Optimization Rationale
======================
The above optimization calls lstat() before open() primarily to ask
fscache if the file exists.  It gets the current stat-data as a side
effect essentially for free (since we already have it in memory).
If the file does not exist, it does not need to call open().  And
since very few directories have .gitignore files, we can greatly
reduce time spent in the filesystem.

Discussion of Fix
=================
The above optimization calls lstat() rather than stat() because the
fscache only intercepts lstat() calls.  Calls to stat() stay directed
to the mingw_stat() completly bypassing fscache.  Furthermore, calls
to mingw_stat() always call {open, fstat, close} so that symlinks are
properly dereferenced, which adds *additional* open/close calls on top
of what the original code in dir.c is doing.

Since the problem only manifests for symlinks, we add code to overwrite
the stat-data when the path is a symlink.  This preserves the effect of
the performance gains provided by the fscache in the normal case.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
@dscho dscho merged commit 0d6ec2f into git-for-windows:master Dec 20, 2017
@dscho
Copy link
Member

dscho commented Dec 20, 2017

Thank you so much!

@dscho dscho added this to the v2.15.1(3) milestone Dec 20, 2017
@jeffhostetler jeffhostetler deleted the regression_1392 branch December 22, 2017 13:46
dscho added a commit that referenced this pull request Jan 2, 2018
dir.c: regression fix for add_excludes with fscache
dscho added a commit that referenced this pull request Jan 18, 2018
dir.c: regression fix for add_excludes with fscache
@dscho dscho modified the milestones: v2.15.1(3), v2.16.0 Jan 18, 2018
git-for-windows-ci pushed a commit that referenced this pull request Jan 20, 2018
dir.c: regression fix for add_excludes with fscache
git-for-windows-ci pushed a commit that referenced this pull request Jan 22, 2018
dir.c: regression fix for add_excludes with fscache
git-for-windows-ci pushed a commit that referenced this pull request Jan 22, 2018
dir.c: regression fix for add_excludes with fscache
dscho added a commit that referenced this pull request Jan 22, 2018
dir.c: regression fix for add_excludes with fscache
dscho added a commit that referenced this pull request Feb 16, 2018
dir.c: regression fix for add_excludes with fscache
dscho added a commit that referenced this pull request Mar 23, 2018
dir.c: regression fix for add_excludes with fscache
dscho added a commit that referenced this pull request Apr 3, 2018
dir.c: regression fix for add_excludes with fscache
dscho added a commit that referenced this pull request May 29, 2018
dir.c: regression fix for add_excludes with fscache
dscho added a commit that referenced this pull request May 29, 2018
dir.c: regression fix for add_excludes with fscache
PKRoma pushed a commit to PKRoma/git-for-windows that referenced this pull request Jun 22, 2018
…_1392

dir.c: regression fix for add_excludes with fscache
PKRoma pushed a commit to PKRoma/git-for-windows that referenced this pull request Jun 22, 2018
…_1392

dir.c: regression fix for add_excludes with fscache
PKRoma pushed a commit to PKRoma/git-for-windows that referenced this pull request Jun 22, 2018
…_1392

dir.c: regression fix for add_excludes with fscache
dscho added a commit that referenced this pull request Aug 22, 2018
dir.c: regression fix for add_excludes with fscache
dscho added a commit to dscho/git that referenced this pull request Aug 22, 2018
…_1392

dir.c: regression fix for add_excludes with fscache
dscho added a commit that referenced this pull request Aug 23, 2018
dir.c: regression fix for add_excludes with fscache
dscho added a commit that referenced this pull request Aug 23, 2018
dir.c: regression fix for add_excludes with fscache
dscho added a commit that referenced this pull request Aug 23, 2018
dir.c: regression fix for add_excludes with fscache
jamill pushed a commit to jamill/git that referenced this pull request Aug 28, 2018
…_1392

dir.c: regression fix for add_excludes with fscache
jamill pushed a commit to jamill/git that referenced this pull request Sep 5, 2018
…_1392

dir.c: regression fix for add_excludes with fscache
git-for-windows-ci pushed a commit that referenced this pull request Sep 10, 2018
dir.c: regression fix for add_excludes with fscache
jamill pushed a commit to jamill/git that referenced this pull request Sep 11, 2018
…_1392

dir.c: regression fix for add_excludes with fscache
git-for-windows-ci pushed a commit that referenced this pull request Sep 24, 2018
dir.c: regression fix for add_excludes with fscache
dscho added a commit that referenced this pull request Oct 10, 2018
dir.c: regression fix for add_excludes with fscache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants