Commit 9465bedb by Edward Thomson

attr: don't mangle file path during attr matching

When determining whether some file matches an attr pattern, do
not try to truncate the path to pass to fnmatch.  When there is
no containing directory for an item (eg, from a .gitignore in the
root) this will cause us to truncate our path, which means that
we cannot do meaningful comparisons on it and we may have false
positives when trying to determine whether a given file is actually
a file or a folder (as we have lost the path's base information.)

This mangling was to allow fnmatch to compare a directory on disk to
the name of a directory, but it is unnecessary as our fnmatch accepts
FNM_LEADING_DIR.
parent 30e629a0
...@@ -401,10 +401,9 @@ bool git_attr_fnmatch__match( ...@@ -401,10 +401,9 @@ bool git_attr_fnmatch__match(
path->basename == path->path) path->basename == path->path)
return false; return false;
/* for ignore checks, use container of current item for check */
path->basename[-1] = '\0';
flags |= FNM_LEADING_DIR; flags |= FNM_LEADING_DIR;
/* for ignore checks, use container of current item for check */
if (match->containing_dir) if (match->containing_dir)
matchpath = path->basename; matchpath = path->basename;
else else
...@@ -419,7 +418,7 @@ bool git_attr_fnmatch__match( ...@@ -419,7 +418,7 @@ bool git_attr_fnmatch__match(
return false; return false;
matchval = p_fnmatch(match->pattern, matchpath, flags); matchval = p_fnmatch(match->pattern, matchpath, flags);
path->basename[-1] = '/';
return (matchval != FNM_NOMATCH); return (matchval != FNM_NOMATCH);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment