* src/version.c: Put the Free Software Foundation copyright first.
* tests/read-only-files: Skip when run as superuser: even files
without write permissions would be writable.
* src/util.c (create_backup): Document patch's backup file logic.
(create_backup, create_backup_copy): Add a flag to remember the backup
file; use when a patch deletes a file.
(move_file, copy_file): Better error messages.
* tests/Makefile.am (TESTS): Remove remember-backup-files-2.
* tests/remember-backup-files: Add tests from remember-backup-files-2.
* tests/symlinks: Add a symlink backup file test.
* tests/test-lib.sh: Flag tests with missing pre-requirements as
SKIPped instead of PASSed. Do not use GNU diff extensions, but
still require a diff that understands "-u".
* tests: Do not unnecessarily require GNU diff in a lot of tests.
Make the sed utility optional.
* src/pch.c (maybe_reverse): Allow to create and delete empty files.
(sha1_says_nonexistent): New function for recognizing the sha1
checksums of nonexistent and empty files.
(skip_hex_digits): New helper function for skipping [0-9a-z].
(intuit_diff_type): Parse the sha1 checksums in index lines.
* tests/Makefile.am (XFAIL_TESTS): Remove empty-files.
* src/pch.c (intuit_diff_type): Fix a bug where the reversed-patch
check would wrongly pick the last name instead of the best name.
* src/create-delete: Add test cases for that.
* src/pch.c (fetchmode): Document that the "diff --git" format does
not store file permissions of symlinks.
* src/util.c (set_file_attributes): Since we don't have symlink file
permissions, don't try to set them even on systems where we could.
* src/Makefile.am (patch_LDADD): Add $(LIB_CLOCK_GETTIME) here, after
libpatch.a, so that clock_gettime is properly resolved on systems on
which the library order matters.
* src/patch.c (main): Refuse to patch read-only files, or at least warn
when patching such files with --force or --batch.
* patch.man: Document the changed behavior.
* tests/read-only-files: Split read-only file test case off from
tests/remember-backup-files.
* tests/Makefile.am: Add new test case.
* src/patch.c (main): Convert outname into a char const *.
* src/util.ch (create_backup, move_file, removedirs): Take char const *
filenames.
* src/util.c (makedirs): Take a char const * filename.
(makedirs, removedirs): Take char const * filenames. Create and
modify a copy of the filename.
* src/pch.c (p_copy, p_rename): New variables.
(pch_copy, pch_rename): New functions.
(intuit_diff_type): Parse the "copy from", "copy to", "rename from",
and "rename to" headers.
* src/util.c (fetchname): Return the fetched name per reference (after
freeing the previous name if any). Also free the previous timestamp
string if any.
* src/patch.c (main): When a git diff includes a file mode change,
change to the new mode.
* src/util.c (set_file_attributes): Add a mode parameter.
* tests/file-modes: New test case.
* tests/Makefile.am (TESTS): Add test case.
* src/pch.c (p_mode): New variable.
(fetchmode, pch_mode): New functions.
(intuit_diff_type): Recognize git diffs which contain no hunks.
Parse and store the file modes in the "index", "old mode",
"new mode", "deleted file mode", and "new file mode" headers.
* src/util.c (copy_file): Require the mode parameter to include the
file type. Use that to decide whether to copy a regular file or a
symlink.
(create_backup): Refuse to back up files which are neither a regular
file nor a symlink.
(move_file): Add support for turning a temporary output file into a
symlink.
* src/patch.c (move_file, copy_file): Pass down the file type.
* src/pch.h (prefix_components): Do not follow symlinks.
* src/inp.c (get_input_file): Add a mode parameter specifying the
input file type (which can be either S_IFREG or S_IFLNK). The file
type must match this mode parameter; for symbolic links, the --get
option is not supported.
(scan_input): Abort when plan_a() cannot handle a symbolic link.
Say when patching a symbolic link instead of a regular file.
(plan_a): Add support for reading symbolic links.
* src/patch.c: For now, always tell get_input_file() to read regular
files.
* bootstrap.conf: Use the gnulib readlink module.
* src/util.h (enum file_attributes): New type.
(set_file_attributes): New function.
* src/util.c (set_file_attributes): Move the code for setting file
attributes here from create_backup_copy() and make it usable from
patch.c as well. Make it symlink safe. In addition, also preserve
the file owner when permitted.
(create_backup_copy): Use set_file_attributes().
* src/patch.c (main): Use set_file_attributes().
* bootstrap.conf: Use the gnulib lchmod module.
* src/inp.c (get_input_file), src/pch.c (there_is_another_patch,
intuit_diff_type): Use lstat instead of stat. This causes patch to
refuse patching symlinks (get_input_file() will refuse to read them).
* src/util.c (create_backup): Refuse to create backups of symlinks.
* tests/symlinks: New test case.
* tests/Makefile.am (TESTS): Add test case.
* bootstrap.conf: Use the gnulib lstat module.
* src/pch.c (get_input_file): If an input file is not a regular file,
only skip the patch instead of aborting.
* src/patch.c (main): If get_input_file() fails, skip the patch.
* bootstrap.conf: Use the gnulib fcntl-h and sys_stat modules.
* src/common.h: Remove the declarations provided by gnulib sys_stat.
Always include fcntl.h (and depend on gnulib fcntl-h).
* src/util.h: Remove duplicate include of <timespec.h>.
* configure.ac: Remove obsolete checks for fcntl.h and utime.h.
* src/inp.c, src/patch.c, src/pch.c, src/util.c: Stop declaring
local variables as "register" all over the place: a decent compiler
will do a good enough job of place variables into registers where it
makes sense.
* src/pch.c (intuit_diff_type): Parse filenames in "diff --git" lines.
* src/util.c (parse_name): New helper function for parsing unquoted or
quoted filenames.
* src/util.h (parse_name): Declare.
(skip_spaces): New helper function for skipping spaces in a string.
* src/util.c (parse_c_string): New function.
(fetchname): Add support for quoted filenames.
* tests/quoted-filenames: New test case.
* tests/Makefile.am (TESTS): Add test case.