Re: [PATCH] exclude: fix a bug in prefix comparison optimization

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] exclude: fix a bug in prefix comparison optimization

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:55:01

Nguyễn Thái Ngọc Duy [off-list ref] writes:
When "namelen" becomes zero at this stage, we have matched the fixed
part, but whether it actually matches the pattern still depends on the
pattern in "exclude". As demonstrated in t3001, path "three/a.3"
exists and it matches the "three/a.3" part in pattern "three/a.3[abc]",
but that does not mean a true match.

Don't be too optimistic and let fnmatch() do the job.
Yeah, the existing code is correct _only_ if the pattern part can
match an empty string (e.g. "three/a.3*") and this is a correct fix.

With your "teach attr.c match the same optimization as dir.c"
series, you would need something like this
diff --git i/attr.c w/attr.c
index 6d39406..528e935 100644
--- i/attr.c
+++ w/attr.c
@@ -710,7 +710,7 @@ static int path_matches(const char *pathname, int pathlen,
 	 * if the non-wildcard part is longer than the remaining
 	 * pathname, surely it cannot match.
 	 */
-	if (!namelen || prefix > namelen)
+	if (prefix > namelen)
 		return 0;
 	if (baselen != 0)
 		baselen++;
Comparing the corresponding code in dir.c, there is no "compare the
literal prefix part with strcmp() before doing the fnmatch()"
optimization.  Intended?

(warning: I haven't had my caffeine yet)

Re: [PATCH] exclude: fix a bug in prefix comparison optimization

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:55:01

On Mon, Oct 15, 2012 at 12:36 AM, Junio C Hamano [off-list ref] wrote:
quoted hunk
With your "teach attr.c match the same optimization as dir.c"
series, you would need something like this
diff --git i/attr.c w/attr.c
index 6d39406..528e935 100644
--- i/attr.c
+++ w/attr.c
@@ -710,7 +710,7 @@ static int path_matches(const char *pathname, int pathlen,
         * if the non-wildcard part is longer than the remaining
         * pathname, surely it cannot match.
         */
-       if (!namelen || prefix > namelen)
+       if (prefix > namelen)
                return 0;
        if (baselen != 0)
                baselen++;
If there's still a chance to rewrite attr-match-optim-more series (I
see it's in next now), then I could reorder the patches so that
excluded_from_list code refactoring goes first, then rewrite "teach
attr.c match... as dir.c" patch makes use of the new functions without
code duplication. The end result would be the same, except that we
won't see this bug in attr.c's history. Not much value so if it may
take a lot of your time, don't bother.
--
Duy
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help