Bug 116567 - grep frontend should suppress errors, allow user-defined exclusions [Patch]
Summary: grep frontend should suppress errors, allow user-defined exclusions [Patch]
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: general (show other bugs)
Version: 3.2.3
Platform: Compiled Sources Linux
: NOR wishlist
Target Milestone: ---
Assignee: Matt Rogers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-17 16:31 UTC by Matthew Woehlke
Modified: 2006-09-22 19:45 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
patch to create the features requested in this bug, for 3.4.3 Stable (KDevelop 3.2.3 Stable) (1.05 KB, patch)
2005-11-17 16:35 UTC, Matthew Woehlke
Details
patch to create the features requested in this bug, for 3.4.3 Stable (KDevelop 3.2.3 Stable) (1.07 KB, application/x-gzip)
2005-12-13 23:53 UTC, Matthew Woehlke
Details
patch (this time -U3) to create the features requested in this bug, for KDE 3.4.3 Stable/KDevelop 3.2.3 Stable (4.92 KB, patch)
2006-03-31 20:40 UTC, Matthew Woehlke
Details
Updated patch against 3.3.91 (6.30 KB, patch)
2006-07-27 22:25 UTC, Matthew Woehlke
Details
Patch to remove vcs dirs checkbox, against 3.3.92 (2.73 KB, patch)
2006-09-08 18:09 UTC, Matthew Woehlke
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Woehlke 2005-11-17 16:31:35 UTC
Version:           3.2.3 (using KDE KDE 3.4.3)
Installed from:    Compiled From Sources
Compiler:          3.4.3 
OS:                Linux

Two issues:

1: When grep generates a lot of errors (in my particular case, due to unresolvable symlinks), the output can become very cluttered, and worse, corrupted (because stdout and stderr output at different priorities; I have gotten interrupted and possibly missing results due to this). There should be an option to suppress GREP's errors.

2: There needs to be a way to specify exclusions, both for files and directories. The way I came up with to do this is to pass the results through a series of grep -v pipes. There might be a 'better' way to do this using 'find' but I think it would need to handle files and directories differently, which would be somewhat ugly.

I have already implemented both of these myself in 3.4.3 Stable and will upload diffs for the three affected files.
Comment 1 Matthew Woehlke 2005-11-17 16:35:37 UTC
Created attachment 13511 [details]
patch to create the features requested in this bug, for 3.4.3 Stable (KDevelop 3.2.3 Stable)
Comment 2 Matthew Woehlke 2005-12-13 23:53:23 UTC
Created attachment 13902 [details]
patch to create the features requested in this bug, for 3.4.3 Stable (KDevelop 3.2.3 Stable)

Hmm, apparently "patch" needs a certain file type... trying it as a normal file
Comment 3 Alexander Dymo 2006-03-14 21:22:15 UTC
Could you please resubmit your patch against the recent kdevelop source.
Also please use unified format (diff -U3).
Comment 4 Matthew Woehlke 2006-03-31 20:40:03 UTC
Created attachment 15400 [details]
patch (this time -U3) to create the features requested in this bug, for KDE 3.4.3 Stable/KDevelop 3.2.3 Stable

I'm re-uploading the patch in '-U3' format against the source I have; it's not
all that complicated, has the grepview part changed enough that this can't be
used? (If you do need more recent, how recent is "recent", so I can go download
it?)

One note: the 'excludes' list should really be preserved with the kdev project,
but I'm not sure how to go about making such a change.
Comment 5 Matt Rogers 2006-07-26 03:05:14 UTC
I tried to apply this patch against the KDevelop 3.4 source in branches/kdevelop/3.4 and it wouldn't apply cleanly. Would you mind regenerating the patch again? "svn diff > name_of_patch" generally works best.

Thanks!
Comment 6 Matthew Woehlke 2006-07-27 22:25:48 UTC
Created attachment 17143 [details]
Updated patch against 3.3.91

Uploading a newer version of the patch created against 3.3.91. This one also
remembers the exclusion pattern across sessions (Yay!).
Comment 7 Matt Rogers 2006-08-08 02:00:55 UTC
SVN commit 570885 by mattr:

fix bug 116567 using patch from Matthew Woehlke

BUG: 116567



 M  +37 -9     grepdlg.cpp  
 M  +7 -4      grepdlg.h  
 M  +14 -3     grepviewwidget.cpp  


--- branches/kdevelop/3.4/parts/grepview/grepdlg.cpp #570884:570885
@@ -90,7 +90,7 @@
     config = GrepViewFactory::instance()->config();
     config->setGroup("GrepDialog");
 
-    QGridLayout *layout = new QGridLayout(this, 6, 2, 10, 4);
+    QGridLayout *layout = new QGridLayout(this, 7, 2, 10, 4);
     layout->addRowSpacing(4, 10);
     layout->setRowStretch(4, 0);
     layout->setColStretch(0, 0);
@@ -129,11 +129,27 @@
     files_combo->insertStrList(filepatterns);
     layout->addWidget(files_combo, 2, 1);
 
+    QLabel *exclude_label = new QLabel(i18n("&Exclude:"), this);
+    layout->addWidget(exclude_label, 3, 0, AlignRight | AlignVCenter);
+
+    QStringList exclude_list = config->readListEntry("exclude_patterns");
+    exclude_combo = new KComboBox(true, this);
+    exclude_label->setBuddy(files_combo->focusProxy());
+    if (exclude_list.count()) {
+        exclude_combo->insertStringList(exclude_list);
+    }
+    else
+    {
+        exclude_combo->insertItem("/CVS/,/SCCS/,/\\.svn/,/_darcs/");
+        exclude_combo->insertItem("");
+    }
+    layout->addWidget(exclude_combo, 3, 1);
+
     QLabel *dir_label = new QLabel(i18n("&Directory:"), this);
-    layout->addWidget(dir_label, 3, 0, AlignRight | AlignVCenter);
+    layout->addWidget(dir_label, 4, 0, AlignRight | AlignVCenter);
 
     QBoxLayout *dir_layout = new QHBoxLayout(4);
-    layout->addLayout(dir_layout, 3, 1);
+    layout->addLayout(dir_layout, 4, 1);
 
     dir_combo = new KComboBox( true, this );
     dir_combo->insertStringList(config->readPathListEntry("LastSearchPaths"));
@@ -153,8 +169,8 @@
 	dir_layout->addWidget( synch_button );
 
     QBoxLayout *dir_checks_layout = new QHBoxLayout(4);
-    layout->addLayout(dir_checks_layout, 4, 1);
-	
+    layout->addLayout(dir_checks_layout, 5, 1);
+
     regexp_box = new QCheckBox(i18n("Regular &Expression"), this);
     regexp_box->setChecked(true);
     dir_checks_layout->addSpacing(10);
@@ -169,19 +185,24 @@
     case_sens_box->setChecked(config->readBoolEntry("case_sens", true));
     dir_checks_layout->addSpacing(10);
     dir_checks_layout->addWidget(case_sens_box);
-    
+
     keep_output_box = new QCheckBox(i18n("New view"), this);
     keep_output_box->setChecked(config->readBoolEntry("new_view", true));
     dir_checks_layout->addSpacing(10);
     dir_checks_layout->addWidget(keep_output_box);
-    
+
     ignore_scm_box = new QCheckBox(i18n("S&kip VCS dirs"), this);
     ignore_scm_box->setChecked(config->readBoolEntry("vcs_dirs", true));
     dir_checks_layout->addSpacing(10);
     dir_checks_layout->addWidget(ignore_scm_box);
 
+    no_find_err_box = new QCheckBox(i18n("&Suppress find errors"), this);
+    no_find_err_box->setChecked(config->readBoolEntry("no_find_errs", true));
+    dir_checks_layout->addSpacing(10);
+    dir_checks_layout->addWidget(no_find_err_box);
+
     QBoxLayout *button_layout = new QHBoxLayout(4);
-    layout->addLayout(button_layout, 5, 1);
+    layout->addLayout(button_layout, 6, 1);
     search_button = new KPushButton(KGuiItem(i18n("&Search"),"grep"), this);
     search_button->setDefault(true);
     KPushButton *done_button = new KPushButton(KStdGuiItem::cancel(), this);
@@ -257,7 +278,8 @@
 	config->writeEntry("recursive", recursive_box->isChecked());
 	config->writeEntry("case_sens", case_sens_box->isChecked());
 	config->writeEntry("new_view", keep_output_box->isChecked());
-	config->writeEntry("vcs_dirs", ignore_scm_box->isChecked());
+	config->writeEntry("no_find_errs", no_find_err_box->isChecked());
+	config->writeEntry("exclude_patterns", qCombo2StringList(exclude_combo));
 }
 
 void GrepDialog::slotPatternChanged( const QString & _text )
@@ -297,6 +319,12 @@
     if (pattern_combo->count() > 15) {
 	pattern_combo->removeItem(15);
     }
+    if (!qComboContains(exclude_combo->currentText(), exclude_combo)) {
+	exclude_combo->insertItem(exclude_combo->currentText(), 0);
+    }
+    if (exclude_combo->count() > 15) {
+	exclude_combo->removeItem(15);
+    }
     if (!qComboContains(dir_combo->currentText(), dir_combo)) {
 	dir_combo->insertItem(dir_combo->currentText(), 0);
     }
--- branches/kdevelop/3.4/parts/grepview/grepdlg.h #570884:570885
@@ -12,8 +12,6 @@
 #ifndef _GREPDLG_H_
 #define _GREPDLG_H_
 
-#define IGNORE_SCM_DIRS
-
 #include <qdialog.h>
 #include <qcombobox.h>
 #include <qcheckbox.h>
@@ -46,15 +44,19 @@
 	{ return template_edit->text(); }
     QString filesString() const
 	{ return files_combo->currentText(); }
+    QString excludeString() const
+	{ return exclude_combo->currentText(); }
     QString directoryString() const
 	{ return dir_combo->currentText(); }
-	
+
 	bool regexpFlag() const
 		{ return regexp_box->isChecked(); }
 	bool recursiveFlag() const
 		{ return recursive_box->isChecked(); }
 	bool ignoreSCMDirsFlag() const
 		{ return ignore_scm_box->isChecked(); }
+	bool noFindErrorsFlag() const
+		{ return no_find_err_box->isChecked(); }
 	bool caseSensitiveFlag() const
 		{ return case_sens_box->isChecked(); }
 	bool keepOutputFlag() const
@@ -73,13 +75,14 @@
 
 private:
     KLineEdit *template_edit;
-    KComboBox *pattern_combo, *files_combo;
+    KComboBox *pattern_combo, *files_combo, *exclude_combo;
     KComboBox * dir_combo;
     KURLRequester * url_requester;
 
     QCheckBox *regexp_box;
     QCheckBox *recursive_box;
     QCheckBox *ignore_scm_box;
+    QCheckBox *no_find_err_box;
     QCheckBox *case_sens_box;
     QCheckBox *keep_output_box;
     KConfig* config;
--- branches/kdevelop/3.4/parts/grepview/grepviewwidget.cpp #570884:570885
@@ -193,7 +193,7 @@
 {
 	if ( grepdlg->keepOutputFlag() )
 		slotKeepOutput();
-		
+
 	m_tabWidget->showPage( m_curOutput );
 
 	m_curOutput->setLastFileName("");
@@ -225,8 +225,19 @@
 	filepattern += " \\( -name ";
 	filepattern += files;
 	filepattern += " \\) -print -follow";
+	if (grepdlg->noFindErrorsFlag())
+		filepattern += " 2>/dev/null";
 
 	QString command = filepattern + " " ;
+
+	QStringList excludelist = QStringList::split(",", grepdlg->excludeString());
+	if (!excludelist.isEmpty())
+	{
+		QStringList::Iterator it(excludelist.begin());
+		for (; it != excludelist.end(); ++it)
+			command += "| grep -v " + KShellProcess::quote(*it) + " ";
+	}
+
 	if (grepdlg->ignoreSCMDirsFlag())
 	{
 		command += "| grep -v -e \"SCCS/\" ";
@@ -322,7 +333,7 @@
 	if(m_curOutput->isRunning()) return;
 
 	KPopupMenu rmbMenu;
-	
+
 	if(KAction *findAction = m_part->actionCollection()->action("edit_grep"))
 	{
 		rmbMenu.insertTitle(i18n("Find in Files"));
@@ -334,7 +345,7 @@
 void GrepViewWidget::slotKeepOutput( )
 {
 	if ( m_lastPattern == QString::null ) return;
-	
+
 	m_tabWidget->changeTab(m_curOutput, m_lastPattern);
 
 	m_curOutput = new GrepViewProcessWidget(m_tabWidget);
Comment 8 Matthew Woehlke 2006-09-08 01:17:59 UTC
I just installed beta 2, and I see the 'exclude vcs dirs' checkbox somehow escaped. Reopening until this is fixed; I'll try to get a patch together either today or next week if no one beats me to it.

I'd also like to point out again that I think this should be marked a duplicate of bug 88017, since this functionality should cover that request.
Comment 9 Matthew Woehlke 2006-09-08 18:09:57 UTC
Created attachment 17669 [details]
Patch to remove vcs dirs checkbox, against 3.3.92

This removes the 'Ignore VCS Dirs' option. It also optimizes the exclude list
to use '| grep -v -e 'foo' -e 'bar' ...' instead of '| grep -v foo | grep -v
bar ...'.

Justification:
The 'Ignore VCS Dirs' uses hard-coded rules that cannot be modified by the
user. Checking this box adds '| grep -v -e "/SCCS/" -e "CVS/" -e "\.svn/" -e
"_darcs/"' to the command line. The default 'Exclude' setting adds '| grep -v
-e "/CVS/" -e "/SCCS/" -e "/\.svn/" -e "/_darcs/"' to the command line, which
is almost identical (and could easily be changed to be identical, although the
order doesn't matter and I would think the leading '/'s won't hurt anything).
In other words, the 'exclude' functionality duplicates the 'Ignore VCS Dirs'
functionality, but is much more flexible and more encompassing. Therefore the
superceeded feature should be removed.

This removal WAS in the last patch (and one line of it was applied; see below).
If it somehow failed to apply, please ignore the next sentence :). However, if
this is not going to be accepted (especially given the above justification),
then I would appreciate an explanation (and someone needs to apply the patch
below). Thanks!


The one line previously applied causes the VCS dirs checkbox to not be
remembered. This fixes it (iff the attached patch is rejected; applying both
would be Bad ;-) ):
--- branches/kdevelop/3.4/parts/grepview/grepdlg.cpp #570884:570885 @@ -273,6
+273,7 @@
  config->writeEntry("recursive", recursive_box->isChecked());
  config->writeEntry("case_sens", case_sens_box->isChecked());
  config->writeEntry("new_view", keep_output_box->isChecked());
+ config->writeEntry("vcs_dirs", ignore_scm_box->isChecked());
  config->writeEntry("no_find_errs", no_find_err_box->isChecked());
  config->writeEntry("exclude_patterns", qCombo2StringList(exclude_combo));
 }
Comment 10 Matt Rogers 2006-09-22 19:45:38 UTC
SVN commit 587426 by mattr:

Remove 'Exclude VCS dirs' it's not needed with the current functionality
provided by the grep part.

BUG: 116567



 M  +1 -6      grepdlg.cpp  
 M  +0 -3      grepdlg.h  
 M  +2 -9      grepviewwidget.cpp  


--- branches/kdevelop/3.4/parts/grepview/grepdlg.cpp #587425:587426
@@ -168,7 +168,7 @@
 	QToolTip::add( synch_button, i18n("Set directory to that of the current file") );
 	dir_layout->addWidget( synch_button );
 
-    QBoxLayout *dir_checks_layout = new QHBoxLayout(4);
+    QBoxLayout *dir_checks_layout = new QHBoxLayout(5);
     layout->addLayout(dir_checks_layout, 5, 1);
 
     regexp_box = new QCheckBox(i18n("Regular &Expression"), this);
@@ -191,11 +191,6 @@
     dir_checks_layout->addSpacing(10);
     dir_checks_layout->addWidget(keep_output_box);
 
-    ignore_scm_box = new QCheckBox(i18n("S&kip VCS dirs"), this);
-    ignore_scm_box->setChecked(config->readBoolEntry("vcs_dirs", true));
-    dir_checks_layout->addSpacing(10);
-    dir_checks_layout->addWidget(ignore_scm_box);
-
     no_find_err_box = new QCheckBox(i18n("&Suppress find errors"), this);
     no_find_err_box->setChecked(config->readBoolEntry("no_find_errs", true));
     dir_checks_layout->addSpacing(10);
--- branches/kdevelop/3.4/parts/grepview/grepdlg.h #587425:587426
@@ -53,8 +53,6 @@
 		{ return regexp_box->isChecked(); }
 	bool recursiveFlag() const
 		{ return recursive_box->isChecked(); }
-	bool ignoreSCMDirsFlag() const
-		{ return ignore_scm_box->isChecked(); }
 	bool noFindErrorsFlag() const
 		{ return no_find_err_box->isChecked(); }
 	bool caseSensitiveFlag() const
@@ -81,7 +79,6 @@
 
     QCheckBox *regexp_box;
     QCheckBox *recursive_box;
-    QCheckBox *ignore_scm_box;
     QCheckBox *no_find_err_box;
     QCheckBox *case_sens_box;
     QCheckBox *keep_output_box;
--- branches/kdevelop/3.4/parts/grepview/grepviewwidget.cpp #587425:587426
@@ -234,18 +234,11 @@
 	if (!excludelist.isEmpty())
 	{
 		QStringList::Iterator it(excludelist.begin());
+		command += "| grep -v ";
 		for (; it != excludelist.end(); ++it)
-			command += "| grep -v " + KShellProcess::quote(*it) + " ";
+			command += "-e " + KShellProcess::quote(*it) + " ";
 	}
 
-	if (grepdlg->ignoreSCMDirsFlag())
-	{
-		command += "| grep -v -e \"SCCS/\" ";
-		command += "-e \"CVS/\" ";
-		command += "-e \"\\.svn/\" ";
-		command += "-e \"_darcs/\" ";
-	}
-
 	// quote spaces in filenames going to xargs
 	command += "| sed \"s/ /\\\\\\ /g\" ";