From 8a3f4d70e4093a649574cc7705161b36184ce898 Mon Sep 17 00:00:00 2001 From: Andreas Gruenbacher Date: Fri, 27 Mar 2009 23:05:40 +0100 Subject: [PATCH] Enforce simple backup mode and compute the backup file name if -B, -Y, or -z is used This fixes the case where -B or -Y is combined with -z (bug 25968). --- ChangeLog | 12 ++++++ Makefile.in | 4 +- common.h | 1 + patch.c | 2 +- patch.man | 35 ++++++++++----- tests/backup-prefix-suffix | 88 ++++++++++++++++++++++++++++++++++++++ util.c | 32 +++++++++----- 7 files changed, 151 insertions(+), 23 deletions(-) create mode 100644 tests/backup-prefix-suffix diff --git a/ChangeLog b/ChangeLog index 2c0aaea..eb7aa74 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,18 @@ * util.h (append_to_file): Update definition. * Makefile.in: Remove timespec.h and m4/timespec.m4. + * common.h (origsuff): New variable. + * patch.c (main): Remember when -z was used. + * util.c (contains_slash): New function. + (move_file): Enforce simple backup mode and compute the backup file + name here if -B, -Y, or -z is used. Fix the case where -B or -Y is + combined with -z. + * patch.man: Document this change. + * tests/backup-prefix-suffix: New test case. + * Makefile.in (TESTS): Add test case. + +2009-03-25 Andreas Gruenbacher + * patch.c (main): Avoid replacing files when nothing has changed. * tests/unmodified-files: New test case. * Makefile.in (TESTS): Add test case. diff --git a/Makefile.in b/Makefile.in index 19d85f1..4719448 100644 --- a/Makefile.in +++ b/Makefile.in @@ -90,8 +90,8 @@ MISC = AUTHORS COPYING ChangeLog INSTALL Makefile.in NEWS README VERSION \ aclocal.m4 config.hin configure configure.ac install-sh \ mkinstalldirs patch.man stdbool_.h tests/test-lib.sh \ update-version.sh -TESTS = tests/corrupt-reject-files tests/crlf-handling \ - tests/global-reject-files tests/need-filename \ +TESTS = tests/backup-prefix-suffix tests/corrupt-reject-files \ + tests/crlf-handling tests/global-reject-files tests/need-filename \ tests/no-newline-triggers-assert tests/preserve-c-function-names \ tests/preserve-mode-and-timestamp tests/reject-format \ tests/remember-backup-files tests/remember-reject-files \ diff --git a/common.h b/common.h index d633dcb..1efbabb 100644 --- a/common.h +++ b/common.h @@ -123,6 +123,7 @@ XTERN bool posixly_correct; XTERN char const *origprae; XTERN char const *origbase; +XTERN char const *origsuff; XTERN char const * volatile TMPINNAME; XTERN char const * volatile TMPOUTNAME; diff --git a/patch.c b/patch.c index b18f5bc..801ac0a 100644 --- a/patch.c +++ b/patch.c @@ -775,7 +775,7 @@ get_some_switches (void) case_z: if (!*optarg) fatal ("backup suffix is empty"); - simple_backup_suffix = savestr (optarg); + origsuff = savestr (optarg); break; case 'Z': set_utc = true; diff --git a/patch.man b/patch.man index 4c5dff7..6326f26 100644 --- a/patch.man +++ b/patch.man @@ -280,9 +280,15 @@ This is the default if is conforming to \s-1POSIX\s0. .TP \fB\-B\fP \fIpref\fP or \fB\*=prefix=\fP\fIpref\fP -Prefix +Use the +.B simple +method to determine backup file names (see the +.BI "\-V " method +or +.BI "\*=version\-control " method +option), and append .I pref -to a file name when generating its simple backup file name. +to a file name when generating its backup file name. For example, with .B "\-B\ /junk/" the simple backup file name for @@ -665,9 +671,15 @@ Set internal debugging flags of interest only to patchers. .TP \fB\-Y\fP \fIpref\fP or \fB\*=basename\-prefix=\fP\fIpref\fP -Prefix +Use the +.B simple +method to determine backup file names (see the +.BI "\-V " method +or +.BI "\*=version\-control " method +option), and prefix .I pref -to the basename of a file name when generating its simple backup file name. +to the basename of a file name when generating its backup file name. For example, with .B "\-Y\ .del/" the simple backup file name for @@ -676,18 +688,21 @@ is .BR src/patch/.del/util.c . .TP \fB\-z\fP \fIsuffix\fP or \fB\*=suffix=\fP\fIsuffix\fP -Use +Use the +.B simple +method to determine backup file names (see the +.BI "\-V " method +or +.BI "\*=version\-control " method +option), and use .I suffix -as the simple backup suffix. +as the suffix. For example, with .B "\-z\ -" -the simple backup file name for +the backup file name for .B src/patch/util.c is .BR src/patch/util.c- . -The backup suffix may also be specified by the -.B SIMPLE_BACKUP_SUFFIX -environment variable, which is overridden by this option. .TP \fB\-Z\fP or \fB\*=set\-utc\fP Set the modification and access times of patched files from time stamps diff --git a/tests/backup-prefix-suffix b/tests/backup-prefix-suffix new file mode 100644 index 0000000..27eab5b --- /dev/null +++ b/tests/backup-prefix-suffix @@ -0,0 +1,88 @@ +# Copyright (C) 2009 Free Software Foundation, Inc. +# +# Copying and distribution of this file, with or without modification, +# in any medium, are permitted without royalty provided the copyright +# notice and this notice are preserved. + +. $srcdir/test-lib.sh + +require_cat +use_local_patch +use_tmpdir + +# ============================================================== + +cat > ab.diff < f +check 'patch -b -p1 < ab.diff' < f +check 'patch -b -B prefix. -p1 < ab.diff' < f +check 'patch -b -z .suffix -p1 < ab.diff' < f +check 'patch -b -B prefix. -z .suffix -p1 < ab.diff' < f +check 'patch -b -p1 < ab.diff' < f +check 'patch -b -p1 < ab.diff' < f +check 'patch -b -p1 < ab.diff' <