429 Commits

Author SHA1 Message Date
Andreas Gruenbacher
ad76f67285 tests/read-only-files: Replace the superuser test
* tests/read-only-files: Remove the superuser test, and instead try
out if a read-only file can be written to.
2010-05-04 22:12:00 +02:00
Andreas Gruenbacher
9dbdc0e748 Create temporary test directories in builddir
* tests/test-lib.sh: Create temporary directories in builddir; this
removes the need to do it safely: some systems do not have mktemp -d.
2010-05-04 21:46:12 +02:00
Andreas Gruenbacher
80cfee88e6 Remove $(TEST_SHELL) and use $(SHELL) instead.
* configure.ac, tests/Makefile: Remove $(TEST_SHELL) and use $(SHELL)
instead.
2010-05-04 18:58:13 +02:00
Andreas Gruenbacher
4ded52f912 Additional minor fixes based on Eric Blake's suggestions
* 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.
2010-05-04 18:37:06 +02:00
Eric Blake
bcf08ba042 build: silence some cygwin warnings
* src/pch.c (includes): Add <io.h> for setmode.
(intuit_diff_type): Avoid 8-bit problems.
* src/util.c (parse_name): Likewise.
* src/util.h (skip_spaces): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2010-05-04 18:36:56 +02:00
Andreas Gruenbacher
481768b9d7 Fix backup file detection for deleted files
* 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.
2010-05-04 18:08:53 +02:00
Andreas Gruenbacher
dbb26b7e99 Some test suite fixes and improvements
* 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.
2010-05-04 04:07:45 +02:00
Andreas Gruenbacher
1b2ed3de07 Remove left-over debugging code
* src/pch.c (intuit_diff_type): Remove left-over debugging code.
2010-05-04 03:03:23 +02:00
Andreas Gruenbacher
4e1404fe82 Allow to create and delete empty files
* 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.
2010-05-04 00:02:03 +02:00
Andreas Gruenbacher
8462be2ed0 Minor cosmetic changes 2010-05-03 22:04:13 +02:00
Andreas Gruenbacher
a93dea1dce Stick to the best name in the reversed-patch check
* 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.
2010-05-03 21:58:40 +02:00
Andreas Gruenbacher
76aa1070c8 Do not try to set file permissions of symlinks
* 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.
2010-05-03 12:20:00 +02:00
Andreas Gruenbacher
0e952c6d34 Improve the symlink backup file tests
* tests/symlinks: Improve the backup file tests.
2010-05-03 11:06:35 +02:00
Andreas Gruenbacher
0403787317 Add two test cases which are currently broken
* Removing an empty file does not work as expected.
* Deleted files are not being remembered correctly.
* Symlinks are not being remembered, either.
2010-05-03 00:15:32 +02:00
Andreas Gruenbacher
0c837fd075 Fix the linker library order
* 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.
2010-05-02 15:52:21 +02:00
Andreas Gruenbacher
47622c1e46 * NEWS: Update.
* gnulib: Update to latest.
* bootstrap: Update from gnulib.
2010-05-02 12:43:45 +02:00
Andreas Gruenbacher
cabd1add57 Refuse to patch read-only files
* 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.
2010-05-02 12:40:35 +02:00
Andreas Gruenbacher
9e39d9c995 git diffs: Support file copies and renames
* src/patch.c (main): Support git diffs which copy or rename files.
* tests/copy-rename: New test case.
* tests/Makefile.am (TESTS): Add test case.
2010-05-02 11:44:03 +02:00
Andreas Gruenbacher
502d77b81b Do not modify the string arguments of makedirs and removedirs
* 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.
2010-05-02 11:44:03 +02:00
Andreas Gruenbacher
5f3b6a06a1 git diffs: Parse copy and rename headers
* 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.
2010-05-02 11:44:03 +02:00
Andreas Gruenbacher
b68294e3e1 git diffs: Support file mode changes
* 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.
2010-05-02 11:44:03 +02:00
Andreas Gruenbacher
f9db7450fa git diffs: Support symlinks
* src/patch.c (main): Support git symlink diffs.
* tests/symlinks: Add git symlink diff test cases.
2010-05-02 11:44:00 +02:00
Andreas Gruenbacher
12fdbd5cec Pass up the file type and check for consistent types
* src/pch.c (intuit_diff_type, there_is_another_patch): Pass up the
file type.
* src/patch.c (main): Check for consistent file types.
2010-05-02 11:42:28 +02:00
Andreas Gruenbacher
a41a918fe7 Skip reversed patches check when file types are inconsistent
* src/pch.c (intuit_diff_type): Only check for reversed patches when
the input file type matches the patch file type.
2010-05-02 11:42:28 +02:00
Andreas Gruenbacher
53fdc8e340 git diffs: Parse file modes
* 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.
2010-05-02 11:42:28 +02:00
Andreas Gruenbacher
dc0a3e09a8 Add support for writing symlinks
* 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.
2010-05-02 11:42:24 +02:00
Andreas Gruenbacher
7f35c90cf7 Add support for reading 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.
2010-05-02 11:38:31 +02:00
Andreas Gruenbacher
ba67864c2a Set file attributes only in a single place
* 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.
2010-04-29 02:20:43 +02:00
Andreas Gruenbacher
cd0ea8e786 Remove test which is always true
* src/util.c (move_file): Remove test which is always true.
2010-04-29 02:17:22 +02:00
Andreas Gruenbacher
b610c25e84 Update bootstrap script
* bootstrap: Update from gnulib.
2010-04-27 23:09:13 +02:00
Andreas Gruenbacher
baaa92c25d TESTS_ENVIRONMENT portability fix
* tests/Makefile.am (TESTS_ENVIRONMENT): Portability fix.
2010-04-27 23:07:01 +02:00
Andreas Gruenbacher
444decd3f2 Fix an off-by-one error causing an out-of-bounds array access
* src/bestmatch.h (bestmatch): Fix an off-by-one error causing an
out-of-bounds array access.
2010-04-27 12:38:16 +02:00
Andreas Gruenbacher
cfe068672d Remove leftovers from when patch was still using utimbuf()
* configure.ac (gl_CHECK_TYPE_STRUCT_UTIMBUF), m4/utimbuf.m4: Remove;
utimbuf is no longer used.
2010-04-27 12:38:16 +02:00
Andreas Gruenbacher
9807e6160f Include backupfile.h in util.h
* src/util.h: Include <backupfile.h> here and not in each C file
individually; this avoids a warning in merge.c with some compilers.
2010-04-27 12:38:15 +02:00
Andreas Gruenbacher
133f2820b3 Do not redefine __attribute__ when it is already defined
* src/common.h: Do not redefine __attribute__ when it is already
defined.
2010-04-27 12:38:15 +02:00
Andreas Gruenbacher
69f5ebc2d2 Do not use grep -q 2010-04-27 12:38:15 +02:00
Daniel Richard G
7e98397ab2 Portability fixes
* src/common.h (enum diff): Remove the trailing comma.
* src/patch.c (main): Do not use non-constant expressions in an array
initializer.
2010-04-27 12:38:15 +02:00
Daniel Richard G
d7020ed1a9 Portability: do not use variable-length arrays
* src/bestmatch.h: Do not use variable-length arrays.
2010-04-27 12:38:15 +02:00
Andreas Gruenbacher
e3cfef7f99 Refuse to patch symlinks
* 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.
2010-04-27 12:38:15 +02:00
Andreas Gruenbacher
f558fff533 Only check for reversed patches when the input file is patchable
* src/pch.c (intuit_diff_type): Only check for reversed patches when
the input file is patchable in the first place.
2010-04-27 12:38:15 +02:00
Andreas Gruenbacher
3aceaac307 If an input file is not a regular file, only skip the patch
* 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.
2010-04-27 12:38:15 +02:00
Andreas Gruenbacher
a11bfc85e5 Use the gnulib fcntl-h and sys_stat modules
* 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.
2010-04-27 12:38:15 +02:00
Andreas Gruenbacher
37f7c8faec Do not declare variables as "volatile" unnecessarily
* src/common.h, src/patch.c, src/util.c, src/util.h: Do not declare
variables as "volatile" unnecessarily.
2010-04-27 12:38:15 +02:00
Andreas Gruenbacher
de38f4acfb Do no declare local variables as "register" unnecessarily
* 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.
2010-04-27 12:38:02 +02:00
Andreas Gruenbacher
3288f660a0 Document the recent changes
* patch.man: Describe the fixed behavior of --set-time and --set-utc
for timestamps that include time zones.
* NEWS: Update.
2010-04-23 21:43:45 +02:00
Andreas Gruenbacher
310f4c406a Complain when fed git binary patches
* src/common.h (enum diff): New enumeration GIT_BINARY_DIFF.
* src/pch.c (intuit_diff_type): Recognize git binary patches.
* src/patch.c (main): Complain when fed git binary patches.
* tests/git-binary-diff: New test case.
* tests/Makefile.am (TESTS): Add test case.
2010-04-23 21:43:45 +02:00
Andreas Gruenbacher
30a7405dfb Parse filenames in "diff --git" lines
* 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.
2010-04-23 21:43:40 +02:00
Andreas Gruenbacher
3bccc730eb Fix minor potential memory leaks
* src/pch.c (intuit_diff_type): Make sure we don't leak file names
even when fed weird input.
2010-04-23 09:10:43 +02:00
Andreas Gruenbacher
a64a20d0ab Add support for quoted filenames
* 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.
2010-04-23 09:10:35 +02:00
Andreas Gruenbacher
c4f28f6efb Untangle the name and timestamp parsing
* src/util.c (fetchname): Untangle the name and timestamp parsing.
2010-04-22 19:28:19 +02:00