Bug 417628 - Exclude filter in find/replace files dialog doesn't seem to work
Summary: Exclude filter in find/replace files dialog doesn't seem to work
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: UI: general (show other bugs)
Version: 5.5.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Igor Kushnir
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-14 12:09 UTC by Geert Janssens
Modified: 2020-05-02 18:11 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.5.1


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Geert Janssens 2020-02-14 12:09:01 UTC
SUMMARY
For the last couple of releases I have some trouble to use the exclude file filter in the find/replace files dialog.
No matter what I enter in there files matching the expressions in the exclude filter are searched anyway.

For example, in my C++ project I set the exclude filter to "*.c", kdevelop still searches all c source files and will display search results in these c source files.
This has been going on for a couple of releases (say at least a year), though unfortunately I can't recollect when exactly it started

STEPS TO REPRODUCE
1. Open a project in kdevelop
2. Select Edit->Find/Replace in Files...
3. Enter something to search for and that you know is present in files you plan to exclude in the next step
4. Adjust the exclude step to exclude some files, for example "*.c" to exclude all c source files.
5. Run the search

OBSERVED RESULT
The search results will also show files that have been excluded via the exclude filter.


EXPECTED RESULT
Only show results from files that had not been excluded via the exclude filter.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Fedora 31
(available in About System)
KDE Plasma Version: 5.17.5
KDE Frameworks Version: 5.66.0
Qt Version: 5.13.2

ADDITIONAL INFORMATION
Comment 1 Igor Kushnir 2020-03-24 16:03:26 UTC
This is one of the consequences of QDir::match() behavior change since Qt 5.12: https://bugreports.qt.io/browse/QTBUG-73797. I'm working on a fix.
Comment 2 Igor Kushnir 2020-05-02 18:11:47 UTC
Git commit f56cdda54b7f88b119f2c7cfb2f534b4fe74478f by Igor Kushnir.
Committed on 02/05/2020 at 16:28.
Pushed by igorkushnir into branch '5.5'.

Work around QDir::match() behavior change in Qt 5.12.0

QDir::match() migrated to QRegularExpression in Qt 5.12.0. In the new
implementation asterisk in a wildcard no longer matches path separators.

This caused two bugs in KDevelop:
1. kdev_format_source rejects input files if the 'format_sources' file
  is not located in the same directory as the target file.
2. Exclude filter in Find/Replace in Files has no effect (unless the
  user specifies almost complete paths in the format supported by Bash
  Filename Expansion with the globstar shell option disabled).

Note that Files (aka `include`) filter in Find/Replace in Files is
unaffected by the behavior change because in its code a filename rather
than a path is passed as the second argument to QDir::match().

WildcardHelpers can migrate to
QRegularExpression::wildcardToRegularExpression() once we require
Qt 5.12.1 or later. This function was added in Qt 5.12.0 and started
anchoring wildcard pattern in Qt 5.12.1.

Ideally support for globstar (**) in glob patterns should be added to
QRegularExpression::wildcardToRegularExpression() and to QDir::match().
In that case WildcardHelpers could be eliminated and QDir::match() could
be used again.

If globstar support is not added to
QRegularExpression::wildcardToRegularExpression(), WildcardHelpers can
port away from QRegExp, for example, by replacing `starEscape` (see the
definition of wildcardToRegularExpression()) with ".*" in the value
returned by wildcardToRegularExpression() and passing
DotMatchesEverythingOption to QRegularExpression constructor.

When we port away from QRegExp, we can change the syntax of
format_sources and possibly Exclude filter to match Bash globstar
syntax or perhaps some other new Qt wildcard syntax. Alternatively, we
can process user-provided wildcard patterns before and/or after passing
them to wildcardToRegularExpression() so as to preserve our syntax.
Related: bug 409222
FIXED-IN: 5.5.1

M  +1    -0    kdevplatform/util/CMakeLists.txt
M  +3    -1    kdevplatform/util/kdevformatfile.cpp
A  +59   -0    kdevplatform/util/wildcardhelpers.h     [License: LGPL (v2+)]
M  +2    -1    plugins/grepview/grepdialog.cpp
M  +4    -2    plugins/grepview/grepfindthread.cpp

https://invent.kde.org/kde/kdevelop/commit/f56cdda54b7f88b119f2c7cfb2f534b4fe74478f