diff --git a/ChangeLog b/ChangeLog index 95cb6e3..babc161 100644 --- a/ChangeLog +++ b/ChangeLog @@ -33,6 +33,13 @@ (ok_to_reverse): Use vsay() here instead of fprintf() to ensure flushing. + * pch.c (there_is_another_patch): Move the "patch would create" test + here from intuit_diff_type() after asking for the filename to patch. + * inp.c (get_input_file): No need to report when the file is missing; + this is done in there_is_another_patch() already. + * patch.c (main): No need to report when a patch attempts to create + an exiting file, either. + 2009-03-25 Andreas Gruenbacher * patch.c (main): Avoid replacing files when nothing has changed. diff --git a/Makefile.in b/Makefile.in index 37ac817..0c0807e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -91,12 +91,12 @@ MISC = AUTHORS COPYING ChangeLog INSTALL Makefile.in NEWS README VERSION \ mkinstalldirs patch.man stdbool_.h tests/test-lib.sh \ update-version.sh TESTS = tests/backup-prefix-suffix tests/corrupt-reject-files \ - tests/crlf-handling tests/global-reject-files \ - tests/munged-context-format 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 \ - tests/unmodified-files + tests/create-delete tests/crlf-handling \ + tests/global-reject-files tests/munged-context-format \ + 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 tests/unmodified-files DISTFILES = $(MISC) $(SRCS) $(HDRS) $(M4FILES) \ pc/chdirsaf.c pc/djgpp/config.sed pc/djgpp/configure.bat \ pc/djgpp/configure.sed pc/djgpp/README diff --git a/inp.c b/inp.c index acc7818..3f6febf 100644 --- a/inp.c +++ b/inp.c @@ -145,7 +145,7 @@ get_input_file (char const *filename, char const *outname) char *getbuf; if (inerrno == -1) - inerrno = stat (inname, &instat) == 0 ? 0 : errno; + inerrno = stat (filename, &instat) == 0 ? 0 : errno; /* Perhaps look for RCS or SCCS versions. */ if (patch_get @@ -196,7 +196,7 @@ get_input_file (char const *filename, char const *outname) if (diffbuf) free (diffbuf); - } else if (inerrno && !pch_says_nonexistent (reverse)) + } else if (inerrno && inerrno != ENOENT) { errno = inerrno; pfatal ("Can't find file %s", quotearg (filename)); diff --git a/patch.c b/patch.c index 801ac0a..7f7844f 100644 --- a/patch.c +++ b/patch.c @@ -301,11 +301,6 @@ main (int argc, char **argv) else if (!where || (where == 1 && pch_says_nonexistent (reverse) == 2 && instat.st_size)) { - - if (where) - say ("Patch attempted to create file %s, which already exists.\n", - quotearg (inname)); - abort_hunk (! failed, reverse); failed++; if (verbosity != SILENT) diff --git a/pch.c b/pch.c index 3131b08..7b139ba 100644 --- a/pch.c +++ b/pch.c @@ -198,6 +198,8 @@ grow_hunkmax (void) bool there_is_another_patch (bool need_header) { + bool is_empty; + if (p_base != 0 && p_base >= p_filesize) { if (verbosity == VERBOSE) say ("done\n"); @@ -285,6 +287,20 @@ there_is_another_patch (bool need_header) } } } + is_empty = inerrno || instat.st_size == 0; + if ((! is_empty) < p_says_nonexistent[reverse ^ is_empty]) + { + reverse ^= ok_to_reverse + ("The next patch%s would %s the file %s,\nwhich %s!", + reverse ? ", when reversed," : "", + (inerrno ? "delete" + : instat.st_size == 0 ? "empty out" + : "create"), + quotearg (inname), + (inerrno ? "does not exist" + : instat.st_size == 0 ? "is already empty" + : "already exists")); + } return true; } @@ -600,8 +616,6 @@ intuit_diff_type (bool need_header) if (! posixly_correct) { - bool is_empty; - i = best_name (p_name, stat_errno); if (i == NONE && patch_get) @@ -644,23 +658,6 @@ intuit_diff_type (bool need_header) } } - is_empty = i == NONE || st[i].st_size == 0; - if ((! is_empty) < p_says_nonexistent[reverse ^ is_empty]) - { - assert (i0 != NONE); - reverse ^= - ok_to_reverse - ("The next patch%s would %s the file %s,\nwhich %s!", - reverse ? ", when reversed," : "", - (i == NONE ? "delete" - : st[i].st_size == 0 ? "empty out" - : "create"), - quotearg (p_name[i == NONE || st[i].st_size == 0 ? i0 : i]), - (i == NONE ? "does not exist" - : st[i].st_size == 0 ? "is already empty" - : "already exists")); - } - if (i == NONE && p_says_nonexistent[reverse]) { int newdirs[3]; diff --git a/tests/create-delete b/tests/create-delete new file mode 100644 index 0000000..842a0a6 --- /dev/null +++ b/tests/create-delete @@ -0,0 +1,80 @@ +# 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 +require_diff +use_local_patch +use_tmpdir + +# ============================================================== + +# Bug #25970: intuit_diff_type: Assertion `i0 != NONE' failed. + +cat > f.diff < f +check 'patch -f -p1 < f.diff || echo "Status: $?"' < f +diff -u /dev/null f > f.diff + +check 'patch -f < f.diff || echo "Status: $?"' < f.diff +rm f +check 'patch -f f < f.diff || echo "Status: $?"' < f.orig +rm -f f +touch f +diff -u f.orig f > f.diff +check 'patch -f < f.diff || echo "Status: $?"' <