Re: 2.1.131: some quality thoughts

Matthias Urlichs (smurf@noris.de)
25 Dec 1998 17:45:25 +0100


Andrea Arcangeli <andrea@e-mind.com> writes:
> If somebody is going to fix CVS please fix also `cvs diff` in order to
> produce patch that can be applyed even if the CVS module is structured in
> subdirectories...

It does supply proper Index: lines, so a quick fix to patch(1) to optionally
prefer the file name from Index: is probably easieest. Besides, it's been
done before. ;-)

Index: base.5/pch.c
--- base.5/pch.c Thu, 04 Dec 1997 09:52:04 +0100 smurf (gnu_patch/6_pch.c 1.1.1.4 444)
+++ noris.5/pch.c Fri, 23 Jan 1998 09:01:52 +0100 smurf (gnu_patch/6_pch.c 1.1.1.5 664)
@@ -469,6 +469,8 @@
if either the old and new names are both absent
or posixly_correct is nonzero.
Consider the file names to be in the order (old, new, index).
+ If 'preferindex' is set, use (index) if it's set, otherwise
+ use (old, new).
- If some named files exist, use the first one if posixly_correct
is nonzero, the best one otherwise.
- If patch_get is nonzero, and no named files exist,
@@ -487,12 +489,27 @@
{
enum nametype i0 = NONE;

- if (! posixly_correct && (name[OLD] || name[NEW]) && name[INDEX])
+ if (name[INDEX])
{
- free (name[INDEX]);
- name[INDEX] = 0;
+ if (preferindex)
+ {
+ if (name[OLD])
+ {
+ free (name[OLD]);
+ name[OLD] = 0;
+ }
+ if (name[NEW])
+ {
+ free (name[NEW]);
+ name[NEW] = 0;
+ }
+ }
+ else if (! posixly_correct && (name[OLD] || name[NEW]))
+ {
+ free (name[INDEX]);
+ name[INDEX] = 0;
+ }
}
-
for (i = OLD; i <= INDEX; i++)
if (name[i])
{
Index: base.5/patch.man
--- base.5/patch.man Thu, 04 Dec 1997 09:52:04 +0100 smurf (gnu_patch/8_patch.man 1.1.1.4 444)
+++ noris.5/patch.man Fri, 23 Jan 1998 09:01:52 +0100 smurf (gnu_patch/8_patch.man 1.1.1.5 664)
@@ -371,6 +371,20 @@
.BR \- ,
read from standard input, the default.
.TP
+\fB\-I\fP or \fB\*=prefer\-index\fP
+Prefer the file name from the "Index:" header within the patch if it's
+present, i.e. totally ignore the "old" and "new" file names.
+.Sp
+This option is useful if the patch file was generated by emitting an
+.IR Index:
+line with the correct file name and then feeding two temporary
+files to
+.I diff
+since old versions of
+.I diff
+cannot easily be convinced to replace the file names in the header of the
+patch.
+.TP
\fB\-l\fP or \fB\*=ignore\-whitespace\fP
Match patterns loosely, in case tabs or spaces
have been munged in your files.
Index: base.5/patch.c
--- base.5/patch.c Thu, 04 Dec 1997 09:52:04 +0100 smurf (gnu_patch/9_patch.c 1.1.1.4 444)
+++ noris.5/patch.c Fri, 23 Jan 1998 09:01:52 +0100 smurf (gnu_patch/9_patch.c 1.1.1.5 664)
@@ -458,7 +458,7 @@
skip_rest_of_patch = FALSE;
}

-static char const shortopts[] = "bB:cd:D:eEfF:g:i:lnNo:p:r:RstTuvV:x:Y:z:Z";
+static char const shortopts[] = "bB:cd:D:eEfF:g:i:IlnNo:p:r:RstTuvV:x:Y:z:Z";
static struct option const longopts[] =
{
{"backup", no_argument, NULL, 'b'},
@@ -472,6 +472,7 @@
{"fuzz", required_argument, NULL, 'F'},
{"get", no_argument, NULL, 'g'},
{"input", required_argument, NULL, 'i'},
+ {"prefer-index", no_argument, NULL, 'I'},
{"ignore-whitespace", no_argument, NULL, 'l'},
{"normal", no_argument, NULL, 'n'},
{"forward", no_argument, NULL, 'N'},
@@ -504,6 +505,7 @@
"Input options:",
"",
" -p NUM --strip=NUM Strip NUM leading components from file names.",
+" -I --prefer-index Prefer the Index: header for file names.",
" -F LINES --fuzz LINES Set the fuzz factor to LINES for inexact matching.",
" -l --ignore-whitespace Ignore white space changes between patch and input.",
"",
@@ -652,6 +654,9 @@
break;
case 'i':
patchname = savestr (optarg);
+ break;
+ case 'I':
+ preferindex = TRUE;
break;
case 'l':
canonicalize = TRUE;
Index: base.5/common.h
--- base.5/common.h Thu, 04 Dec 1997 09:51:38 +0100 smurf (gnu_patch/18_common.h 1.1.1.3 444)
+++ noris.5/common.h Fri, 23 Jan 1998 09:01:52 +0100 smurf (gnu_patch/18_common.h 1.1.1.5 664)
@@ -171,6 +171,7 @@
XTERN bool force;
XTERN bool batch;
XTERN bool noreverse;
+XTERN bool preferindex;
XTERN int reverse;
XTERN enum { DEFAULT_VERBOSITY, SILENT, VERBOSE } verbosity;
XTERN bool skip_rest_of_patch;
@@ -242,8 +243,10 @@
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
+#ifndef __GLIBC__
#ifndef lseek
off_t lseek ();
+#endif
#endif
#ifndef SEEK_SET
#define SEEK_SET 0

-- 
Matthias Urlichs  |  noris network GmbH   |   smurf@noris.de  |  ICQ: 20193661
The quote was selected randomly. Really.    |      http://www.noris.de/~smurf/
-- 
The only people with a right to complain about what I do for a living are
vegetarian nudists.
                                       - Ken Bates, fur trapper -

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/