This is the mail archive of the patchutils-list@sourceware.org mailing list for the patchutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

-X and -I options implementation


Hello
Consider this patch that implements -X and -I options for filterdiff utility.


--- orig/patchutils-0.2.31/doc/filterdiff.1 2005-06-13 21:41:07.000000000 +0400
+++ work/patchutils-0.2.31/doc/filterdiff.1 2008-06-06 15:48:48.000000000 +0400
@@ -61,10 +61,18 @@ You can use both unified and context for
Include only files matching \fIPATTERN\fR\&. All other lines in the input are suppressed\&.


.TP
+\fB\-I\fR \fIFILE\fR
+Include only files that match any \fIPATTERN\fR in \fIFILE\fR\&. All other lines in the input are suppressed\&.
+
+.TP
\fB\-x\fR \fIPATTERN\fR
Exclude files matching \fIPATTERN\fR\&. All other lines in the input are displayed\&.


.TP
+\fB\-X\fR \fIFILE\fR
+Exclude files that match any \fIPATTERN\fR in \fIFILE\fR\&. All other lines in the input are displayed\&.
+
+.TP
\fB\-p\fR \fIn\fR
When matching, ignore the first \fIn\fR components of the pathname\&.


--- orig/patchutils-0.2.31/src/filterdiff.c 2004-11-29 18:14:50.000000000 +0300
+++ work/patchutils-0.2.31/src/filterdiff.c 2008-06-06 15:54:35.000000000 +0400
@@ -1012,7 +1012,9 @@ static int filterdiff (FILE *f, const ch
const char * syntax_str =
"Options:\n"
" -x PAT exclude files matching PAT\n"
+" -X FILE exclude files that match any pattern in FILE\n"
" -i PAT include only files matching PAT\n"
+" -I FILE include only files that match any pattern in FILE\n"
" --hunks=H, -# H\n"
" include only hunks in range H\n"
" --lines=L include only hunks with (original) lines in range L\n"
@@ -1309,9 +1311,15 @@ int main (int argc, char *argv[])
case 'x':
patlist_add (&pat_exclude, optarg);
break;
+ case 'X':
+ patlist_add_file (&pat_exclude, optarg);
+ break;
case 'i':
patlist_add (&pat_include, optarg);
break;
+ case 'I':
+ patlist_add_file (&pat_include, optarg);
+ break;
case 'z':
unzip = 1;
break;
--- orig/patchutils-0.2.31/src/util.c 2004-06-07 18:07:46.000000000 +0400
+++ work/patchutils-0.2.31/src/util.c 2008-06-06 15:59:25.000000000 +0400
@@ -34,6 +34,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
+#include <limits.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
@@ -109,6 +110,28 @@ void patlist_add(struct patlist **dst, c
*dst = item;
}


+void patlist_add_file(struct patlist **dst, const char *fn)
+{
+ FILE *fd;
+ char buf[PATH_MAX];
+ size_t len;
+ + fd = fopen (fn, "r");
+ if (NULL == fd)
+ return;
+
+ while (fgets (buf, sizeof(buf), fd)) {
+ len = strlen(buf);
+ if (len <= 1) /* only '\n' presents */
+ continue;
+ /* Remove '\n' from pattern */
+ if ('\n' == buf[len - 1])
+ buf[len - 1] = '\0';
+ patlist_add (dst, buf);
+ }
+ fclose (fd);
+}
+
int patlist_match(struct patlist *list, const char *s)
{
while (list) {
--- orig/patchutils-0.2.31/doc/filterdiff.1	2005-06-13 21:41:07.000000000 +0400
+++ work/patchutils-0.2.31/doc/filterdiff.1	2008-06-06 15:48:48.000000000 +0400
@@ -61,10 +61,18 @@ You can use both unified and context for
 Include only files matching \fIPATTERN\fR\&. All other lines in the input are suppressed\&.
 
 .TP
+\fB\-I\fR \fIFILE\fR
+Include only files that match any \fIPATTERN\fR in \fIFILE\fR\&. All other lines in the input are suppressed\&.
+
+.TP
 \fB\-x\fR \fIPATTERN\fR
 Exclude files matching \fIPATTERN\fR\&. All other lines in the input are displayed\&.
 
 .TP
+\fB\-X\fR \fIFILE\fR
+Exclude files that match any \fIPATTERN\fR in \fIFILE\fR\&. All other lines in the input are displayed\&.
+
+.TP
 \fB\-p\fR \fIn\fR
 When matching, ignore the first \fIn\fR components of the pathname\&.
 
--- orig/patchutils-0.2.31/src/filterdiff.c	2004-11-29 18:14:50.000000000 +0300
+++ work/patchutils-0.2.31/src/filterdiff.c	2008-06-06 15:54:35.000000000 +0400
@@ -1012,7 +1012,9 @@ static int filterdiff (FILE *f, const ch
 const char * syntax_str =
 "Options:\n"
 "  -x PAT    exclude files matching PAT\n"
+"  -X FILE   exclude files that match any pattern in FILE\n"
 "  -i PAT    include only files matching PAT\n"
+"  -I FILE   include only files that match any pattern in FILE\n"
 "  --hunks=H, -# H\n"
 "            include only hunks in range H\n"
 "  --lines=L include only hunks with (original) lines in range L\n"
@@ -1309,9 +1311,15 @@ int main (int argc, char *argv[])
 		case 'x':
 			patlist_add (&pat_exclude, optarg);
 			break;
+		case 'X':
+			patlist_add_file (&pat_exclude, optarg);
+			break;
 		case 'i':
 			patlist_add (&pat_include, optarg);
 			break;
+		case 'I':
+			patlist_add_file (&pat_include, optarg);
+			break;
 		case 'z':
 			unzip = 1;
 			break;
--- orig/patchutils-0.2.31/src/util.c	2004-06-07 18:07:46.000000000 +0400
+++ work/patchutils-0.2.31/src/util.c	2008-06-06 15:59:25.000000000 +0400
@@ -34,6 +34,7 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
+#include <limits.h>
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif /* HAVE_UNISTD_H */
@@ -109,6 +110,28 @@ void patlist_add(struct patlist **dst, c
 	*dst = item;
 }
 
+void patlist_add_file(struct patlist **dst, const char *fn)
+{
+	FILE *fd;
+	char buf[PATH_MAX];
+	size_t len;
+	
+	fd = fopen (fn, "r");
+	if (NULL == fd)
+		return;
+
+	while (fgets (buf, sizeof(buf), fd)) {
+		len = strlen(buf);
+		if (len <= 1) /* only '\n' presents */
+			continue;
+		/* Remove '\n' from pattern */
+		if ('\n' == buf[len - 1])
+			buf[len - 1] = '\0';
+		patlist_add (dst, buf);
+	} 
+	fclose (fd);
+}
+
 int patlist_match(struct patlist *list, const char *s)
 {
 	while (list) {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]