This is the mail archive of the
patchutils-list@sourceware.org
mailing list for the patchutils project.
-X and -I options implementation
- From: Serj Kalichev <serj dot kalichev at gmail dot com>
- To: patchutils-list at sourceware dot org
- Date: Fri, 06 Jun 2008 17:29:11 +0400
- Subject: -X and -I options implementation
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:content-type; bh=oVt2klmBf/KuxpiuEwOkaaLgKeBOaU0ErEjf9UWyW6U=; b=YlQU0zTiWQGKcrlgoevNCtuy1rouFOfOZYzqL/KCkVLhK9giAAisHBnouj9j2YakHv 1V8MHFpjy7jpBLXkOdPDlIZiQMJfp1Bo1vyyjCrQewl9PAo73W5XIzaDrCgc0V7tROFq sOErttZZg5j9+WIb2GtBxi/F86D7UHCNIT3BE=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type; b=hkcRB4HMwosgs4Wlds+9BVMlo4MGlLSXWZWaY386p+y91bdzt963P3XWpWNU4iMIPu nkJ9jgS/eXKF2qjPkOO8cYdwn7JLsuOBLZ4WchnH85+D2fvcO1OoszLjtbBfkfPcVCff 1YsxfGSzpmvh8dVusA6nsLXy0z7NUl+6x5W4g=
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) {