Re: [PATCH 2/5] pathspec: add tree_recursive_diff parameter
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:49:38
Nguyen Thai Ngoc Duy [off-list ref] writes:
2010/9/28 Junio C Hamano [off-list ref]:quoted
Nguyễn Thái Ngọc Duy [off-list ref] writes: ...quoted
- If it's recursive diff, directories are just an intermediate step. All path must end with a file name. Thus, directories will be unconditionally matched.Hmm, I am not sure what you mean by this. If the pathspec says a/b*/c, you are in "a" and are deciding if you should descend to its subdirectory, then you would surely want to be able to say: (1) Ah, the subdirectory I am looking at is "bar" and it does match "b*". It might contain "c"; I should descend into it. (2) Nope, the subdirectory I am looking at is "frotz" and it can never match "b*", so there is no point recursing into it.I did not go that far, trying to analyse the pattern. When I wrote "immediate step" I was thinking of "*foo" pattern, which effectively means descending to any reachable directories because '*' matches slashes too. I think that's the worst case. Anyway I did not know that I could borrow some optimizations from pathspec_matches() in builtin/grep.c.
As you noticed, over time we have polished our re-implementations of the pathspec logic to avoid needlessly descending into subdirectories, and the one in the grep may be the latest incarnation of it. The logic that uses the path_simplify structure in dir.c may also offer you some inspirations. Note that the worst case will fall out as a natural consequence of doing the fallback in the dumb and simple way, so you do not have to worry too much about it ;-) I would prefer to see the new, consolidated logic to at least know the easy optimizations we already have. Thanks.