When applying an empty patch to a file and -o is given, copy the input file to the output file

This commit is contained in:
Andreas Gruenbacher 2009-03-25 23:03:42 +01:00
parent 17c16b669c
commit 19947785bf
3 changed files with 35 additions and 3 deletions

View File

@ -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 <agruen@suse.de>
* patch.c (abort_hunk_unified, abort_hunk_context): Preserve

13
patch.c
View File

@ -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");

View File

@ -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 <<EOF
EOF
echo three > a
check 'patch -o b a < a.diff' <<EOF
patching file a
EOF
check 'cat b' <<EOF
three
EOF
check 'patch -b -o b a < a.diff' <<EOF
patching file a
EOF