From 19947785bf0837edceacfce3fa643fa6e28fcd84 Mon Sep 17 00:00:00 2001 From: Andreas Gruenbacher Date: Wed, 25 Mar 2009 23:03:42 +0100 Subject: [PATCH] When applying an empty patch to a file and -o is given, copy the input file to the output file --- ChangeLog | 4 ++++ patch.c | 13 ++++++++++--- tests/unmodified-files | 21 +++++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2c9c031..2c0aaea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,10 @@ * tests/unmodified-files: New test case. * Makefile.in (TESTS): Add test case. + * patch.c (main): New apply_empty_patch variable. When applying an + empty patch to a file and -o is given, copy the input file to the + output file. + 2009-03-24 Andreas Gruenbacher * patch.c (abort_hunk_unified, abort_hunk_context): Preserve diff --git a/patch.c b/patch.c index 24a4665..b18f5bc 100644 --- a/patch.c +++ b/patch.c @@ -123,6 +123,7 @@ main (int argc, char **argv) struct stat outst; char numbuf[LINENUM_LENGTH_BOUND + 1]; bool written_to_rejname = false; + bool apply_empty_patch = false; exit_failure = 2; program_name = argv[0]; @@ -178,10 +179,17 @@ main (int argc, char **argv) /* Make sure we clean up in case of disaster. */ set_signals (false); + if (inname && outfile) + { + apply_empty_patch = true; + inerrno = -1; + } for ( open_patch_file (patchname); - there_is_another_patch (! (inname || posixly_correct)); - reinitialize_almost_everything() + there_is_another_patch (! (inname || posixly_correct)) + || apply_empty_patch; + reinitialize_almost_everything(), + apply_empty_patch = false ) { /* for each patch in patch file */ int hunk = 0; int failed = 0; @@ -343,7 +351,6 @@ main (int argc, char **argv) } /* Finish spewing out the new file. */ - assert (hunk); if (! spew_output (&outstate, &outst)) { say ("Skipping patch.\n"); diff --git a/tests/unmodified-files b/tests/unmodified-files index ae71d3e..7e0f109 100644 --- a/tests/unmodified-files +++ b/tests/unmodified-files @@ -37,3 +37,24 @@ Status: 1 EOF ncheck 'test a -ef a.first' + +# ============================================================== + +# When applying an empty patch to a file with -o, copy the input file. + +cat > a.diff < a + +check 'patch -o b a < a.diff' <