public inbox for patchutils-list@sourceware.org
 help / color / mirror / Atom feed
From: Serj Kalichev <serj.kalichev@gmail.com>
To: patchutils-list@sourceware.org
Subject: -X and -I options implementation
Date: Fri, 06 Jun 2008 13:45:00 -0000	[thread overview]
Message-ID: <48493BA7.1030502@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 3023 bytes --]

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) {

[-- Attachment #2: patchutils-0.2.31-XI.patch --]
[-- Type: text/x-diff, Size: 2706 bytes --]

--- 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) {

             reply	other threads:[~2008-06-06 13:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-06 13:45 Serj Kalichev [this message]
2008-06-11 15:46 ` Tim Waugh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48493BA7.1030502@gmail.com \
    --to=serj.kalichev@gmail.com \
    --cc=patchutils-list@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).