[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH] add a -o to only compare files that you want to compare.
From: |
Steven Rostedt |
Subject: |
[RFC PATCH] add a -o to only compare files that you want to compare. |
Date: |
Wed, 23 Aug 2006 11:08:21 -0400 |
I'm not on the list and this not a bug report, but a feature request
(with a patch :). Several times I like to do diffs of different source
trees without hitting all the .svn, CVS, .git, *.o and other crud that's
in the directories that I don't want to diff. So I downloaded the
source to diffutils and made this little patch.
It adds the -o and -O which act pretty much like -x and -X but opposite.
It also should only work for recursive searches and it doesn't
exclude/include directory names.
Basically what the -o option does is allows the user to put in a regexpr
for the files that they want to compare. The -x still works with this
and takes precedence. It also doesn't effect directories, so it will
still descend into directories that doesn't match the -o regexpr.
So -o allows the user to only compare files within directories that
match the regexpr name given by the user in a recursive diff.
For example I can do the following:
diff -ur -o '*.[ch]' linux-2.6.16/ linux-2.6.17/
and this will give me a diff of all the *.c and *.h files that changed
between the two directories.
If anyone is interested, the patch is below. For comments, please CC me
since I'm not on the list.
This was a quick patch, it probably needs a little more clean up to add
it. But it works for what I want to use it for, and that's all that I
wanted, and all that I did :)
Thanks,
-- Steve
Signed-off-by: Steven Rostedt <address@hidden>
Index: diffutils-2.8.1/src/diff.c
===================================================================
--- diffutils-2.8.1.orig/src/diff.c 2006-08-23 09:42:38.000000000 -0400
+++ diffutils-2.8.1/src/diff.c 2006-08-23 10:27:28.000000000 -0400
@@ -139,7 +139,7 @@ exclude_options (void)
}
static char const shortopts[] =
-"0123456789abBcC:dD:eEfF:hHiI:lL:nNpPqrsS:tTuU:vwW:x:X:y";
+"0123456789abBcC:dD:eEfF:hHiI:lL:nNpPqrsS:tTuU:vwW:x:X:yo:O:";
/* Values for long options that do not have single-letter equivalents. */
enum
@@ -428,6 +428,20 @@ main (int argc, char **argv)
new_file = 1;
break;
+ case 'o':
+ if (!included)
+ included = new_exclude ();
+ add_exclude (included, optarg, exclude_options ());
+ break;
+
+ case 'O':
+ if (!included)
+ included = new_exclude ();
+ if (add_exclude_file (add_exclude, included, optarg,
+ exclude_options (), '\n'))
+ pfatal_with_name (optarg);
+ break;
+
case 'p':
show_c_function = 1;
add_regexp (&function_regexp_list, "^[[:alpha:]$_]");
@@ -1066,6 +1080,9 @@ compare_files (struct comparison const *
char const *name = name0 == 0 ? name1 : name0;
char const *dir = parent->file[name0 == 0].name;
+ if (included && !excluded_filename (included, name))
+ return EXIT_SUCCESS;
+
/* See POSIX 1003.1-2001 for this format. */
message ("Only in %s: %s\n", dir, name);
@@ -1278,13 +1295,20 @@ compare_files (struct comparison const *
&& (cmp.file[0].desc == NONEXISTENT
|| S_ISREG (cmp.file[0].stat.st_mode))
&& (cmp.file[1].desc == NONEXISTENT
- || S_ISREG (cmp.file[1].stat.st_mode)))
+ || S_ISREG (cmp.file[1].stat.st_mode))
+ && (!included || excluded_filename (included, cmp.file[0].name))
+ )
{
message ("Files %s and %s differ\n",
file_label[0] ? file_label[0] : cmp.file[0].name,
file_label[1] ? file_label[1] : cmp.file[1].name);
status = EXIT_FAILURE;
}
+ else if (included && !excluded_filename (included, cmp.file[0].name))
+ {
+ /* this does not match the "only" flag */
+ status = EXIT_SUCCESS;
+ }
else
{
/* Both exist and neither is a directory. */
Index: diffutils-2.8.1/src/diff.h
===================================================================
--- diffutils-2.8.1.orig/src/diff.h 2006-08-23 09:42:40.000000000 -0400
+++ diffutils-2.8.1/src/diff.h 2006-08-23 09:44:07.000000000 -0400
@@ -191,6 +191,9 @@ XTERN bool speed_large_files;
/* Patterns that match file names to be excluded. */
XTERN struct exclude *excluded;
+/* Patterns that match file names to only include. */
+XTERN struct exclude *included;
+
/* Don't discard lines. This makes things slower (sometimes much
slower) but will find a guaranteed minimal set of changes. */
XTERN bool minimal;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [RFC PATCH] add a -o to only compare files that you want to compare.,
Steven Rostedt <=