Commit b6967c39 by Patrick Steinhardt

attr_file: refactor stripping of trailing spaces

The stripping of trailing spaces currently happens as part of
`git_attr_fnmatch__parse`. As we aren't currently parsing
trailing whitespaces correct in case they're escaped, we'll have
to change that code, though. To make actual behavioural change
easier to review, refactor the code up-front by pulling it out
into its own function that is expected to retain the exact same
functionality as before. Like this, the fix will be trivial to
apply.
parent b1795e0d
......@@ -560,6 +560,19 @@ void git_attr_path__free(git_attr_path *info)
*/
/*
* Determine the length of trailing spaces.
*/
static size_t trailing_space_length(const char *p, size_t len)
{
size_t n;
for (n = len; n; n--) {
if (p[n-1] != ' ' && p[n-1] != '\t')
break;
}
return len - n;
}
/*
* This will return 0 if the spec was filled out,
* GIT_ENOTFOUND if the fnmatch does not require matching, or
* another error code there was an actual problem.
......@@ -646,9 +659,10 @@ int git_attr_fnmatch__parse(
return GIT_ENOTFOUND;
/* Remove trailing spaces. */
while (pattern[spec->length - 1] == ' ' || pattern[spec->length - 1] == '\t')
if (--spec->length == 0)
return GIT_ENOTFOUND;
spec->length -= trailing_space_length(pattern, spec->length);
if (spec->length == 0)
return GIT_ENOTFOUND;
if (pattern[spec->length - 1] == '/') {
spec->length--;
......
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