diff --git a/NEWS b/NEWS index 28d0e91..42afed7 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +* When a file isn't being deleted because the file contents don't match the + patch, the resulting message is now "Not deleting file ... as content + differs from patch" instead of "File ... is not empty after patch; not + deleting". +* Function names in hunks (from diff -p) are now preserved in reject files. + Changes in version 2.7.1: * Two critical bug fixes in the "diff --git" format support. diff --git a/configure.ac b/configure.ac index dc837d6..f078469 100644 --- a/configure.ac +++ b/configure.ac @@ -33,7 +33,7 @@ AM_CONDITIONAL([ENABLE_MERGE], [test "$enableval" != no]) AM_CONDITIONAL([ALPHA_VERSION], [[echo "$PACKAGE_VERSION" | grep -- "-[0-9a-f][0-9a-f]*\\(-dirty\\)\\?$" >/dev/null]]) -AM_INIT_AUTOMAKE([1.11.2 -Wall -Werror gnu dist-bzip2 dist-xz color-tests parallel-tests]) +AM_INIT_AUTOMAKE([1.11.2 -Wall gnu dist-bzip2 dist-xz color-tests parallel-tests]) AM_SILENT_RULES([yes]) AC_CONFIG_HEADER([config.h:config.hin]) diff --git a/patch.man b/patch.man index c5cc5c4..2c9def5 100644 --- a/patch.man +++ b/patch.man @@ -1,14 +1,10 @@ .\" patch man page -.de Id -.ds Dt \\$4 -.. .ds = \-\^\- .de Sp .if t .sp .3 .if n .sp .. -.TH PATCH 1 \*(Dt GNU -.ta 3n +.TH PATCH 1 "" GNU .SH NAME patch \- apply a diff file to an original .SH SYNOPSIS @@ -241,7 +237,9 @@ asks for confirmation before proceeding. The upshot of all this is that you should be able to say, while in a news interface, something like the following: .Sp - \fB| patch \-d /usr/src/local/blurfl\fP +.RS +\fB| patch \-d /usr/src/local/blurfl\fP +.RE .Sp and patch a file in the .B blurfl @@ -445,8 +443,8 @@ This option implies \fB\*=forward\fP and does not take the Interpret the patch file as a normal diff. .TP \fB\-N\fP or \fB\*=forward\fP -Ignore patches that seem to be reversed or already applied. It is only checked if -the first hunk of a patch can be reversed. +When a patch does not apply, patch usually checks if the patch looks like it +has been reversed. The \fB\*=forward\fP option prevents that. See also .BR \-R . .TP @@ -470,7 +468,9 @@ you keep your files in a different directory than the person who sent out the patch. For example, supposing the file name in the patch file was .Sp - \fB/u/howard/src/blurfl/blurfl.c\fP +.RS +\fB/u/howard/src/blurfl/blurfl.c\fP +.RE .Sp setting .B \-p0 @@ -478,13 +478,17 @@ gives the entire file name unmodified, .B \-p1 gives .Sp - \fBu/howard/src/blurfl/blurfl.c\fP +.RS +\fBu/howard/src/blurfl/blurfl.c\fP +.RE .Sp without the leading slash, .B \-p4 gives .Sp - \fBblurfl/blurfl.c\fP +.RS +\fBblurfl/blurfl.c\fP +.RE .Sp and not specifying .B \-p @@ -876,7 +880,9 @@ or option. Here is an example command, using Bourne shell syntax: .Sp - \fBLC_ALL=C TZ=UTC0 diff \-Naur gcc\-2.7 gcc\-2.8\fP +.RS +\fBLC_ALL=C TZ=UTC0 diff \-Naur gcc\-2.7 gcc\-2.8\fP +.RE .PP Tell your recipients how to apply the patch by telling them which directory to @@ -925,14 +931,16 @@ If the recipient is supposed to use the .BI \-p N option, do not send output that looks like this: .Sp -.ft B +.RS +.ft CW .ne 3 - diff \-Naur v2.0.29/prog/README prog/README +diff \-Naur v2.0.29/prog/README prog/README .br - \-\^\-\^\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997 +\-\^\-\^\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997 .br - +\^+\^+ prog/README Mon Mar 17 14:58:22 1997 ++\^+\^+ prog/README Mon Mar 17 14:58:22 1997 .ft +.RE .Sp because the two file names have different numbers of slashes, and different versions of @@ -940,14 +948,16 @@ and different versions of interpret the file names differently. To avoid confusion, send output that looks like this instead: .Sp -.ft B +.RS +.ft CW .ne 3 - diff \-Naur v2.0.29/prog/README v2.0.30/prog/README +diff \-Naur v2.0.29/prog/README v2.0.30/prog/README .br - \-\^\-\^\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997 +\-\^\-\^\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997 .br - +\^+\^+ v2.0.30/prog/README Mon Mar 17 14:58:22 1997 ++\^+\^+ v2.0.30/prog/README Mon Mar 17 14:58:22 1997 .ft +.RE .Sp .PP Avoid sending patches that compare backup file names like diff --git a/src/patch.c b/src/patch.c index 828943b..12028a9 100644 --- a/src/patch.c +++ b/src/patch.c @@ -150,6 +150,10 @@ main (int argc, char **argv) else if ((version_control = getenv ("VERSION_CONTROL"))) version_control_context = "$VERSION_CONTROL"; + init_backup_hash_table (); + init_files_to_delete (); + init_files_to_output (); + /* parse switches */ Argc = argc; Argv = argv; @@ -162,10 +166,6 @@ main (int argc, char **argv) if (make_backups | backup_if_mismatch) backup_type = get_version (version_control_context, version_control); - init_backup_hash_table (); - init_files_to_delete (); - init_files_to_output (); - init_output (&outstate); if (outfile) outstate.ofp = open_outfile (outfile); @@ -519,7 +519,7 @@ main (int argc, char **argv) mismatch = true; somefailed = true; if (verbosity != SILENT) - say ("File %s is not empty after patch; not deleting\n", + say ("Not deleting file %s as content differs from patch\n", quotearg (outname)); } @@ -646,8 +646,8 @@ main (int argc, char **argv) if (outstate.ofp && (ferror (outstate.ofp) || fclose (outstate.ofp) != 0)) write_fatal (); output_files (NULL); - delete_files (); cleanup (); + delete_files (); if (somefailed) exit (1); return 0; @@ -762,7 +762,7 @@ static char const *const option_help[] = "", " -D NAME --ifdef=NAME Make merged if-then-else output using NAME.", #ifdef ENABLE_MERGE -" -m --merge Merge using conflict markers instead of creating reject files.", +" --merge Merge using conflict markers instead of creating reject files.", #endif " -E --remove-empty-files Remove output files that are empty after patching.", "", @@ -1237,6 +1237,7 @@ abort_hunk_unified (bool header, bool reverse) lin old = 1; lin lastline = pch_ptrn_lines (); lin new = lastline + 1; + char const *c_function = pch_c_function(); if (header) { @@ -1251,7 +1252,7 @@ abort_hunk_unified (bool header, bool reverse) print_unidiff_range (rejfp, pch_first () + out_offset, lastline); fprintf (rejfp, " +"); print_unidiff_range (rejfp, pch_newfirst () + out_offset, pch_repl_lines ()); - fprintf (rejfp, " @@\n"); + fprintf (rejfp, " @@%s\n", c_function ? c_function : ""); while (pch_char (new) == '=' || pch_char (new) == '\n') new++; diff --git a/src/util.c b/src/util.c index 1cc1a68..0af6013 100644 --- a/src/util.c +++ b/src/util.c @@ -1599,7 +1599,7 @@ make_tempfile (char const **name, char letter, char const *real_name, int try_makedirs_errno = ENOENT; char *template; - if (real_name) + if (real_name && ! dry_run) { char *dirname, *basename; diff --git a/tests/Makefile.am b/tests/Makefile.am index 02fc6de..cfc4f37 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -20,6 +20,7 @@ TESTS = \ asymmetric-hunks \ backup-prefix-suffix \ bad-filenames \ + bad-usage \ concat-git-diff \ copy-rename \ corrupt-reject-files \ @@ -49,6 +50,7 @@ TESTS = \ reject-format \ remember-backup-files \ remember-reject-files \ + remove-directories \ symlinks \ unmodified-files diff --git a/tests/bad-usage b/tests/bad-usage new file mode 100644 index 0000000..022eeda --- /dev/null +++ b/tests/bad-usage @@ -0,0 +1,18 @@ +# Copyright (C) 2009, 2011-2012 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 + +# ============================================================== + +check 'patch -px || echo "status: $?"' < target -cat > p.diff < p.diff < f.diff < f.diff < dir/file +cat > apatch <