This is the mail archive of the
patchutils-list@sourceware.org
mailing list for the patchutils project.
Option --clean for filterdiff
- From: Serj Kalichev <serj dot kalichev at gmail dot com>
- To: patchutils-list at sourceware dot org
- Date: Thu, 19 Jun 2008 17:32:52 +0400
- Subject: Option --clean for filterdiff
- 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=Qf9+rhegcnEwIlnMsNRwDqGvxiezcADY1bokPwSBMoE=; b=dddksiBdkQ0uQ3UZKfqwRALm59zcZVT0aVy0IIKphQztCdMDjlmVvywatDG0Nxe6ve L/BdT3xl4Z7eI95js0N38CmsTxuoP8cnFXiOQAJDfbLyLyt/YNBm8SsnwzTXZsfwA7W6 wRs3aSHehKhK3Fi5jftVMgbMjjOwy8eNUQ/Jw=
- 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=dqsjDFfFjHpDBOMnxDitHaQ9yumMWu5RtroDsAtVF4ETh6u0ZL1YYTM6gPsy0kEkMk OW+N3Xdmst1APKF86QbM8QYlY0QKVb25XT8jw5yw6+3jB2KOvIw2JKxL8DWoHpnrqtZ0 7skCEvNyovHB5UHrWEAliFqfoYzEdVioISzgk=
Patch to implement --clean option.
This option force removing of non-diff strings from the output.
Even when -x -X (exclude mode) options in use.
diff -uNr patchutils_git/doc/patchutils.xml patchutils_new/doc/patchutils.xml
--- patchutils_git/doc/patchutils.xml 2008-06-18 12:56:53.000000000 +0400
+++ patchutils_new/doc/patchutils.xml 2008-06-19 15:29:00.000000000 +0400
@@ -549,6 +549,8 @@
<arg choice="opt">-X <replaceable>FILE</replaceable></arg>
<arg choice="opt">--verbose</arg>
<arg choice="opt">-v</arg>
+ <arg choice="opt">--clean</arg>
+ <arg choice="opt">-c</arg>
<arg choice="opt">-z</arg>
<group choice="opt">
<arg>-# <replaceable>RANGE</replaceable></arg>
@@ -761,6 +763,15 @@
</varlistentry>
<varlistentry>
+ <term><option>-c</option>, <option>--clean</option></term>
+ <listitem>
+ <para>Always remove all non-diff lines
+ from the output. Even when excluding
+ a filename pattern.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><option>-z</option></term>
<listitem>
<para>Decompress files with extensions .gz and .bz2.</para>
diff -uNr patchutils_git/src/filterdiff.c patchutils_new/src/filterdiff.c
--- patchutils_git/src/filterdiff.c 2008-06-18 12:56:53.000000000 +0400
+++ patchutils_new/src/filterdiff.c 2008-06-19 15:35:00.000000000 +0400
@@ -77,6 +77,7 @@
} mode;
static regex_t *regex = NULL;
static size_t num_regex = 0;
+static int clean_comments = 0;
static int numbering = 0;
static int annotating = 0;
static int ignore_components = 0;
@@ -902,8 +903,9 @@
}
/* Show non-diff lines if excluding, or if
- * in verbose mode. */
- if (mode == mode_filter && (pat_exclude || verbose))
+ * in verbose mode, and if --clean isn't specified. */
+ if (mode == mode_filter && (pat_exclude || verbose)
+ && !clean_comments)
fputs (line, stdout);
if (getline (&line, &linelen, f) == -1)
@@ -920,8 +922,9 @@
if (getline (&line, &linelen, f) == -1) {
/* Show non-diff lines if excluding, or if
- * in verbose mode. */
- if (mode == mode_filter && (pat_exclude || verbose))
+ * in verbose mode, and if --clean isn't specified. */
+ if (mode == mode_filter && (pat_exclude || verbose)
+ && !clean_comments)
fputs (header[0], stdout);
free (names[0]);
goto eof;
@@ -930,8 +933,9 @@
if (strncmp (line, is_context ? "--- " : "+++ ", 4)) {
/* Show non-diff lines if excluding, or if
- * in verbose mode. */
- if (mode == mode_filter && (pat_exclude || verbose))
+ * in verbose mode, and if --clean isn't specified. */
+ if (mode == mode_filter && (pat_exclude || verbose)
+ && !clean_comments)
fputs (header[0], stdout);
free (names[0]);
free (header[0]);
@@ -1030,6 +1034,8 @@
" show matching hunks or file-level diffs (grepdiff)\n"
" --remove-timestamps (filterdiff, grepdiff)\n"
" don't show timestamps from output (filterdiff, grepdiff)\n"
+" -c, --clean (filterdiff)\n"
+" remove all comments (non-diff lines) from output (filterdiff)\n"
" -z decompress .gz and .bz2 files\n"
" -n show line numbers (lsdiff, grepdiff)\n"
" --number-files (lsdiff, grepdiff)\n"
@@ -1256,10 +1262,11 @@
{"no-filename", 0, 0, 'h'},
{"empty-files-as-absent", 0, 0, 'E'},
{"number-files", 0, 0, 1000 + 'n'},
+ {"clean", 0, 0, 'c'},
{0, 0, 0, 0}
};
char *end;
- int c = getopt_long (argc, argv, "vp:i:I:x:X:zns#:Ef:Hh",
+ int c = getopt_long (argc, argv, "vp:i:I:x:X:zns#:Ef:Hhc",
long_options, NULL);
if (c == -1)
break;
@@ -1390,6 +1397,9 @@
case 1000 + 'r':
removing_timestamp = 1;
break;
+ case 'c':
+ clean_comments = 1;
+ break;
default:
syntax(1);
}
@@ -1420,6 +1430,11 @@
error (EXIT_FAILURE, 0, "--as-numbered-lines is "
"inappropriate in this context");
+ if (mode == mode_filter &&
+ verbose && clean_comments)
+ error (EXIT_FAILURE, 0, "can't use --verbose and "
+ "--clean options simultaneously");
+
if (mode == mode_grep && !regex_file_specified) {
int err;