2009-12-30  Andreas Gruenbacher  <agruen@suse.de>

	* patch.man: Clarify the description of the -F / --fuzz option.

	* NEWS: Version 2.6.1 released.

2009-12-29  Andreas Gruenbacher  <agruen@suse.de>

	* src/patch.c (longopts, get_some_switches): Add an optional argument
	to the --merge option to choose the output formats for conflicts.
	* patch.man: Document the new optional argument of --merge.
	* src/merge.c (merge_hunk): Implement diff3-style conflicts.
	* src/common.h (conflict_style): This global variable determines the
	output format for conflicts.
	* tests/merge: Add test cases for the diff3 output format.

	* patch.man: Try to improve the documentation of patch's CRLF handling
	behavior.

2009-12-28  Andreas Gruenbacher  <agruen@suse.de>

	* tests/create-delete: Clean up a syntactic glitch.

	* src/pch.c: When the input files to diff have CRLF line endings, the
	'<' and '>' lines of normal-style diffs will have CRLF endings even
	when the patch itself has not been CRLF mangled.  Do not assume a
	mangled patch in this case.
	* tests/crlf-handling: Update test case to cover this case.

	* configure.ac (gl_FUNC_STRNDUP, gl_FUNC_STRNLEN): Add here.
	* gl/m4/strndup.m4 (gl_HEADER_STRING_H_DEFAULTS): Don't use gnulib's
	strings.h replacement for now, it is too complicated to add right now.
	* gl/lib/xstrndup.c: Instead of using gl_HEADER_STRING_H_DEFAULTS,
	declare strndup here on systems which don't have it.
	* gl/lib/strndup.c: Instead of using gl_HEADER_STRING_H_DEFAULTS,
	declare strnlen here on systems which don't have it.
	* gl/lib/strnlen.c: Import from gnulib.

	* Makefile.in (getopt.h, GETOPT_H): Generate getopt.h in the top-level
	directory if needed.
	(stdbool.h, STDBOOL_H): Likewise -- this should fix stdbool.h
	generation on platforms which don't provide this header.
	(argmatch.$(OBJEXT)): Add missing $(STDBOOL_H) dependency.

	* install-sh: Make executable.

2009-12-22  Andreas Gruenbacher  <agruen@suse.de>

	* src/version.c (copyright_string): Add year 2009.

	* src/pch.c (intuit_diff_type): Add some clarifying comments.

	* src/pch.c (intuit_diff_type): Fix regression introduced after patch
	2.5.9: when none of the filenames in the old, new, and index headers
	exists, patch chose the wrong filename (bug 28367).
	(maybe_reverse): Return if the patch looks reversed, not if this
	function toggled the reverse flag.
	* tests/filename-choice: New test case.
	* Makefile.in (TESTS): Add test case.

2009-11-24  Bert Wesarg <bert.wesarg@googlemail.com>

	* configure.ac: It looks like the . command does not pass the
	arguments to the update-version.sh script [on some platforms].  Invoke
	with sh instead.

2009-11-21  Peter Breitenlohner <peb@mppmu.mpg.de>

	* Makefile.in: Make the test suite work for a VPATH build.

2009-11-14  Andreas Gruenbacher  <agruen@suse.de>

	* update-version.sh: Platform compatibility fixes.

2009-11-12  Andreas Gruenbacher  <agruen@suse.de>

	* NEWS: Version 2.6 released.

2009-10-27  Andreas Gruenbacher  <agruen@suse.de>

	* patch.man: Fix typo (reported by Vytautas Šaltenis).

	* src/merge.c: Clarify the message when (part of) a hunk cannot be
	merged.
	* tests/merge: Adapt the test case.

2009-09-04  Andreas Gruenbacher  <agruen@suse.de>

	* Makefile.in (LIBSRCS, LIBHDRS, LIBM4FILES): Add the gnulib which
	were imported on 2009-06-05 here as well.

	* src/partime.c (main): Try to preserve the owning group of patched
	files.

2009-07-19  Andreas Gruenbacher  <agruen@suse.de>

	* gl/lib/full-write.c, gl/lib/safe-write.c, gl/lib/full-write.h,
	gl/lib/safe-write.h, gl/m4/safe-write.m4, gl/m4/ssize_t.m4:
	Import full_write() and its prerequesites from gnulib.
	* Makefile.in (LIBSRCS, LIBHDRS, LIBM4FILES): Add new files.
	Add new dependencies.
	* configure.ac (gl_SAFE_WRITE): Needef for full_write().
	* src/util.c: Include full-write.h.
	(copy_to_fd): use full_write() instead of write().

	* src/partime.c: The -m option hasn't been officially allocated yet.
	Use only the long form for now (--merge).

2009-06-15  Andreas Gruenbacher  <agruen@suse.de>

	* src/util.c (move_file): Don't fail when removing nonexistent
	files: this condition is already checked in maybe_reverse().

2009-06-05  Andreas Gruenbacher  <agruen@suse.de>

	* gl/lib/getopt_int.h, gl/lib/strndup.c, gl/m4/strndup.m4: Add
	some missing gnulib files.
	* Makefile.in (GETOPT_H): Include subdirectory (gl/lib/) when
	using the gnulib version.

	* src/patch.c: When sending output to stdout, use dup2 to redirect
	messages to stderr; simply assigning stderr to stdout doesn't work on
	some platforms.
	* gl/lib/dup2.c, gl/m4/dup2.m4: Import from gnulib.

	* gl/lib/rename.c, gl/m4/rename.m4: Import from gnulib for platforms
	like Mingw.

2009-05-12  Andreas Gruenbacher  <agruen@suse.de>

	* src/merge.c (locate_merge): Make sure to return a line number
	bigger than last_frozen_line.

	* src/patch.c (explicit_inname): New variable.
	(get_some_switches): Set to true when the filename to patch has been
	specified on the command line.
	(reinitialize_almost_everything): Do not reset the input filename
	between patches when it has been specified on the command line.
	* tests/inname: New test case.
	* Makefile.in: Add test case.

2009-04-11  Vincent Legoll <vincent.legoll@gmail.com>

	* src/patch.c (main): Always set patch_get to 0 unless PATCH_GET is
	set.
	* patch.man: Update accordingly.

2009-04-11  Andreas Gruenbacher  <agruen@suse.de>

	* update-version.sh, configure.ac, Makefile.in: Portability
	improvements.

2009-04-08  Andreas Gruenbacher  <agruen@suse.de>

	* src/patch.c (create_output_file): Add support for sending output
	to standard output.
	(main): Allow -o -.  Remove redundant check.
	* patch.man: Document the new use of -o.

	* src/pch.c (there_is_another_patch): Allow special characters in
	filenames read interactively.

	* src/util.c (fetchname): Don't forget to NUL terminate ptimestr.

2009-04-07  Andreas Gruenbacher  <agruen@suse.de>

	* src/util.c (file_id_hasher): Adapt to Gnulib type change.
	* Makefile.in: Fix out-of-tree builds.
	(dist): Optionally also create bzip2 and xz tarballs.
	* NEWS: Update.

	* patch.man: Replace "systems like DOS" with "Windows". Spelling.

	Preserve timestamps in reject files.
	* src/pch.c (p_timestr): New variable.
	(intuit_diff_type): Set p_timestr here through fetchname().
	(pch_timestr): New function.
	* src/pch.h (pch_timestr): Declare.
	* src/util.c (fetchname): Return the timestamp as string when asked to.
	* src/util.h (fetchname): Update declaration.
	* tests/preserve-c-function-names, tests/reject-format: Update.

2009-04-06  Andreas Gruenbacher  <agruen@suse.de>

	Fix the "patch would create" fix from 2009-03-28.
	* src/pch.c (maybe_reverse): New function.
	(intuit_diff_type): Move the check back here from
	there_is_another_patch(), but compute it using maybe_reverse().  If
	an input file name has been specified, do this check here as well.
	* src/patch.c (main): Only set outname if we are not skipping the
	patch.
	* src/inp.c (get_input_file): We may get here without a file to read
	as well now; don't abort in this case.
	* tests/create-delete: Add test cases covering the previously-broken
	code paths.

	* Makefile.in (MISC): Add config.guess and config.sub.

	* src/partime.c (parse_pattern_letter): Fix for timestamps with
	seconds > 59.5 from Christian Franke.

2009-04-05  Andreas Gruenbacher  <agruen@suse.de>

	* util.c (create_backup): We also need to create base directories
	with a --prefix without slashes and a filename with slashes. A
	--suffix cannot contain slashes, though.
	* merge.c (merge_hunk): Add missing outstate->zero_output = false.

	Move all source and header files into src/.
	* Makefile.in, tests/test-lib.sh, configure.ac: Update accordingly.
	Move all Gnulib files below gl/, and all other source and header
	files into src/.
	* Makefile.in, tests/test-lib.sh, configure.ac, autogen.sh: Update
	accordingly.
	* m4/st_mtim.m4: Remove (obsolete since 2009-03-28).

	Update to the latest version of Gnulib.
	* config.guess, config.sub, gl/lib/getopt.hin, gl/lib/mbrtowc.c,
	gl/lib/stripslash.c, gl/lib/verify.h, gl/lib/xstrndup.c,
	gl/lib/xstrndup.h, gl/m4/argmatch.m4, gl/m4/double-slash-root.m4,
	gl/m4/gettext.m4, gl/m4/inline.m4, gl/m4/minmax.m4,
	gl/m4/xstrndup.m4: New files.
	* gl/lib/argmatch.c, gl/lib/argmatch.h, gl/lib/backupfile.c,
	gl/lib/backupfile.h, gl/lib/basename.c, gl/lib/dirname.c,
	gl/lib/dirname.h, gl/lib/error.c, gl/lib/error.h, gl/lib/exitfail.c,
	gl/lib/exitfail.h, gl/lib/getopt.c, gl/lib/getopt1.c, gl/lib/gettext.h,
	gl/lib/hash.c, gl/lib/hash.h, gl/lib/malloc.c, gl/lib/memchr.c,
	gl/lib/quote.c, gl/lib/quote.h, gl/lib/quotearg.c, gl/lib/quotearg.h,
	gl/lib/realloc.c, gl/lib/strcasecmp.c, gl/lib/strncasecmp.c,
	gl/lib/unlocked-io.h, gl/lib/xalloc.h, gl/lib/xmalloc.c: Modified.
	* gl/m4/backupfile.m4, gl/m4/d-ino.m4, gl/m4/dirname.m4, gl/m4/dos.m4,
	gl/m4/error.m4, gl/m4/exitfail.m4, gl/m4/extensions.m4,
	gl/m4/getopt.m4, gl/m4/hash.m4, gl/m4/malloc.m4, gl/m4/mbrtowc.m4,
	gl/m4/mbstate_t.m4, gl/m4/memchr.m4, gl/m4/onceonly.m4, gl/m4/quote.m4,
	gl/m4/quotearg.m4, gl/m4/realloc.m4, gl/m4/stdbool.m4,
	gl/m4/unlocked-io.m4, gl/m4/utimbuf.m4, gl/m4/xalloc.m4: Likewise.
	* install-sh, mkinstalldirs: Likewise.
	* gl/lib/stdbool.hin: Renamed from gl/lib/stdbool_.h.
	* gl/lib/getopt.h: Removed (should be generated).
	* gl/lib/addext.c: Removed from Gnulib.

	Replace memory_fatal() with xalloc_die().  The FILESYSTEM_PREFIX_LEN()
	macro has been renamed to FILE_SYSTEM_PREFIX_LEN().
	* src/patch.c (main): Remove xalloc_fail_func (replaced by
	xalloc_die()).  Work around the missing addext() with
	find_backup_file_name() plus hacks.
	* src/util.c (create_backup, version_controller): The new versions of
	base_name() and dir_name() return malloc'ed buffers.  Adapt.
	* src/util.h: Replace memory_fatal() with xalloc_die().
	* src/pch.c: Don't leak memory with strlen (base_name (...)).

	* src/util.c (create_file): Add to_dir_known_to_exist argument and
	try to create parent directories when set and the create failed with
	ENOENT.
	(copy_file, create_backup_copy): Pass the new to_dir_known_to_exist
	argument through.
	(create_backup): Don't assume the target directory exists when making
	a backup copy.
	* src/util.h (create_file, copy_file): Change the declarations.
	* src/patch.c, src/pch.c, src/inp.c: In the calls to create_file() and
	copy_file(), assume the parent directory exists.
	* tests/unmodified-files: Test the create_backup() fix.

	* src/util.c (create_backup): The new dir_name() and base_name()
	functions are really counter productive.  Remove them and the bugs
	that keepeing them here as introduced.
	* tests/backup-prefix-suffix: Add more regression tests.

	* src/patch.c (locate_hunk): Revert to the original asymmetric hunk
	behavior (but only anchor hunks starting at line 0 to the start of the
	file): there is not enough reason to change the historic behavior.
	* src/merge.c (locate_merge): Add similar asymmetric hunk check here.
	* tests/asymmetric-hunks: Update accordingly.
	* patch.man: Document the asymmetric hunk behavior.
	* NEWS: Update.

	Copyright notice updates.
	* README, AUTHORS: Updates.

	* patch.man: Document that merging can be slow.
	* tests/test-lib.sh: Also unset QUOTING_STYLE.

2009-04-04  Andreas Gruenbacher  <agruen@suse.de>

	* pch.c (another_hunk): Add (back) the line number ranges to the
	debug output.
	* merge.c (merge_hunk): Likewise.
	(locate_merge): Add a note about the algorithm's requirements.
	* util.c (create_backup): Split from move_file.  New LEAVE_ORIGINAL
	argument for copying instead of renaming.  Don't fail when rename
	fails with errno == EXDEV; copy and unlink in that case instead.
	(copy_file): Add debug message.
	* util.h: Move including <utime.h> etc. here from patch.c.
	(create_backup): Declare.
	* patch.c (main): Create backup files even for files which did not
	actually change; some users of patch rely on the presence of backup
	files when patch says "patching file".
	* tests/unmodified-files: Test the patch.c change.  (The EXDEV fix in
	create_mackup() was tested manually.)
	* util.c (copy_to_fd, ask): The read() return type is ssize_t.

2009-04-03  Andreas Gruenbacher  <agruen@suse.de>

	* patch.man: Document the -m or --merge option.  Some minor other
	changes.
	* NEWS: Document the asymmetric hunk behavior and the -m or --merge
	option.
	* merge.c (locate_merge): Include the number of changes in the debug
	message.
	(print_linerange): New function.
	(merge_result): No longer print line offsets: without exact matches,
	line numbers are less meaningful.  Output the entire messages here.
	(merge_hunk): Be silent when merging exact matches unless in
	--verbose mode.
	* tests/merge: Add another interesting test case.

	* tests/test-lib.sh: Add have_ed function for checking if ed is
	available.
	* tests/crlf-handling, tests/need-filename: Check for ed and skip the
	ed related tests if we don't have it.
	* tests/merge: Use sed instead of ed: sed is more readily available.

	* patch.c (locate_hunk): If a hunk starts at a line > 1, it obviously
	is not from the start of the file.
	* tests/asymmetric-hunks: Add tests for all possible cases.

2009-04-02  Andreas Gruenbacher  <agruen@suse.de>

	* patch.c (locate_hunk): Revert the assymmetric hunk fix from
	2009-03-29.  Instead, allow such hunks to apply only when no
	more context remains.

	* patch.c (main): Restructure to get rid of some code duplication.
	(copy_till, similar): Export these functions.
	* common.h (struct outstate, in_offset, out_offset,
	last_frozen_line): Move here from patch.c.
	(apply_hunk, copy_till, similar): Declare here.

	Simple merge support:
	* configure.ac (ENABLE_MERGE): New --disable-merge option.
	* patch.c (merge): New variable.
	(main): New -m and --merge options.  When in merge mode, don't try
	to reverse patches, and don't try to apply with fuzz.
	* common.h (merge_hunk): Declare function.
	* merge.c: New file containing all the merge code.
	* tests/merge: New test case.
	* Makefile.in (SRCS): Add merge.c.
	(OBJS): Add merge.$(OBJEXT) when merge support is enabled.
	(TESTS): Add test case.
	(COMPILE): Define ENABLE_MERGE when merge support is enabled.

	Locate hunks to merge more intelligently:
	* bestmatch.h: Shortest Edit Sequence algorithm.
	* merge.c (locate_merge, count_fuzz_lines): New functions.
	(merge_hunk): Replace simple guessing with locate_merge().
	* Makefile.in (HDRS): Add bestmatch.h.
	* tests/merge: Only minor improvements up to now.

	* diffseq.h: New file (Gnulib compareseq algorithm).
	* minmax.h: New file (Gnulib MIN and MAX macros).
	* Makefile.in (HDRS): Add diffseq.h and minmax.h.

	* COPYING: Update to GPL version 3 because of diffseq.h.

	* diffseq.h: When an EQUAL_IDX macro is defined, use that instead
	of EQUAL.  This macro takes vector indexes instead of elements as
	arguments.

	Better merge support:
	* patch.c, common.h (apply_hunk): Make static again.
	* merge.c (compute_changes): New function for computing the
	difference between lines in a hunk and lines in the input file.
	(merge_result): We may have more than one result per hunk now.
	(merge_hunk): Merge the hunk with the compute_changes() result.
	* tests/merge: Better results now.

	* merge.c: Add license header.

	* merge.c (locate_merge): The number of changes allowed permits a
	higher maximum merge position (max_where).
	* tests/merge: Add a test for this case.

	* merge.c (merge_hunk): Add two missing checks that were leading into
	failed assertions.
	* tests/merge: Add test cases for each of these checks.

	* Makefile.in (install, uninstall): DESTDIR specifies a prefix to
	the root directory to install into.
	(installdirs): Merge with install.

2009-04-01  Andreas Gruenbacher  <agruen@suse.de>

	* tests/test-lib.sh: When $GDB is set, run patch in gdbserver
	for debugging.
	* pch.c (another_hunk): Make the debug output easier to read.

2009-03-31  Andreas Gruenbacher  <agruen@suse.de>

	* patch.c: Split last_offset into in_offset and out_offset and
	count line numbers properly.
	* tests/line-numbers: Without the fixes, this test case goes
	horribly wrong.
	* Makefile.in (TESTS): Add test case.

2009-03-30  Jim Meyering  <meyering@redhat.com>

	tests: accommodate ls' "alternate access control method" indicator
	ls can output an additional byte after a file's permissions string,
	e.g., rather than "rwxr--r-- ..." it can output "rwxr--r--+ ..."
	or "rwxr--r--. ..." to indicate the presence of an ACL.
	* tests/create-delete: Adjust sed filter to accommodate that.
	* tests/preserve-mode-and-timestamp: Likewise.

2009-03-30  Andreas Gruenbacher  <agruen@suse.de>

	* tests/test-lib.sh: Unset environment variables that influence
	the behavior of patch.
	* util.c (move_file): Add debug message when files have been seen
	already.  Fix leftover "empty uneadable" debug message.

	* patch.c (main): Print newline earlier.
	* util.c (copy_file): Add debug message.

2009-03-29  Andreas Gruenbacher  <agruen@suse.de>

	* patch.c (locate_hunk): Hunks that have fewer or more lines of
	context at the beginning than at the end can match anywhere; the
	assumption that this can only occur at the beginning or end of the
	file is wrong. Remove those checks.
	* tests/asymmetric-hunks: New test case.
	* Makefile.in (TESTS): Add test case.

	* util.c (move_file): Create backup files of nonexisting files with
	the default mode instead of mode 0: files with mode 0 cause too many
	problems with applications which do not expect unreadable files.
	* tests/create-delete: Test for this.

	* Makefile.in (BROKEN_TESTS): Test cases which fail.

2009-03-28  Andreas Gruenbacher  <agruen@suse.de>

	* pch.c (intuit_diff_type): Rename need_filename argument to
	need_header.  Omit superfluous "missing header" warnings.

	When remembering files including timestamps, we need to update the
	timestamps after appending to a file.  This causes problems on some
	systems where the timestamps returned by fstat() after appending are
	not up to date, yes.  We only remember timestamps as a compatibility
	hack with non-POSIX systems that do not have unique inode numbers;
	drop this hack instead.
	* timespec.h, m4/timespec.m4: Remove.
	* util.c: Remove timespec.h and all uses of struct timespec.
	(append_to_file): Remove REMEMBER argument; no need to update known
	files anymore.
	* util.h (append_to_file): Update definition.
	* Makefile.in: Remove timespec.h and m4/timespec.m4.

	* common.h (origsuff): New variable.
	* patch.c (main): Remember when -z was used.
	* util.c (contains_slash): New function.
	(move_file): Enforce simple backup mode and compute the backup file
	name here if -B, -Y, or -z is used.  Fix the case where -B or -Y is
	combined with -z.
	* patch.man: Document this change.
	* tests/backup-prefix-suffix: New test case.
	* Makefile.in (TESTS): Add test case.

	* tests/munged-context-format: New test case.
	* Makefile.in (TESTS): Add test case.

	* util.c (vsay): New function for use in say(), etc.
	(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  <agruen@suse.de>

	* patch.c (main): Avoid replacing files when nothing has changed.
	* 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
	Index lines in reject files as well.
	* tests/reject-format: Test this change.

	* configure.ac (TEST_SHELL): New substitution.
	* Makefile.in (TEST_SHELL): New variable.
	(HAVE__BOOL): New variable.
	(hash.$(OBJEXT)): Add $(STDBOOL_H) dependency.
	* tests/test-lib.sh: Use expr for arithmetic operations. Check for
	working "echo -n" and BASH_LINENO.  Replace printf with echo.
	* tests/preserve-mode-and-timestamp: Ignore leading "+" in ls output.
	* tests: Remove !shebang line from tests and make them non-executable.
	Replace printf with echo.

2009-03-23  Andreas Gruenbacher  <agruen@suse.de>

	* patch.c (intuit_diff_type): When looking for an ed or normal
	patch, don't look for filename headers.  (Those formats don't
	have any.)
	* pch.c (there_is_another_patch): Don't suggest to use -p with
	normal format diffs for the same reason.

2009-03-22  Andreas Gruenbacher  <agruen@suse.de>

	* NEWS: Update for alpha release.

	* patch.c (main): Always initialize the known files table.
	Move new reject files into place; append to known ones.
	* util.c (file_already_seen): Export.
	(move_file): Remember all files, not only backup files.
	(append_to_file): When asked to remember a file, remember
	the state *after* appending. (The timestamps will change!)
	* tests/remember-reject-files: New test case.
	* Makefile.in (TESTS): Add test case.

	* common.h (no_strip_trailing_cr): New variable.
	* patch.c: Use no_strip_trailing_cr.  Option --binary no longer
	a no-op on POSIX systems.
	* patch.man: Document change of --binary.
	* pch.c (there_is_another_patch): Check no_strip_trailing_cr.
	* tests/crlf-handling: Add --binary tests here.

	* patch.c (apply_hunk): Use fputs() in simple fprintf()
	situations.

	* patch.c (main): Require filename in patch if none specified on
	the command line and posixly_correct is false.
	* pch.c (intuit_diff_type): While we still don't have a filename,
	don't look for hunks.
	(there_is_another_patch): Pass need_filename through.
	* tests/need-filename: New test case.
	* Makefile.in (TESTS): Add test case.

	* pch.c (intuit_diff_type): Check for garbage after what looks
	like a normal format command.
	* tests/normal-garbage: New test case.
	* Makefile.in (TESTS): Add test case.

	* Makefile.in (bindir): Define as @bindir@.
	(DISTFILES_CLEAN): Move DISTFILES here which must not be remade by
	the dist target.
	(MISC): Add missing tests/test-lib.sh and update-version.sh.
	(check, $(TESTS)): Make each test depend on all so that they can be
	run individually.
	(maintainer-clean): Also remove patch-*.tar.gz and patch-*.tar.gz.sig.
	(dist): Add PV directory level.  Add reminder to self how to upload.
	* configure.ac: Silence "missing datarootdir" warning.

	* tests/crlf-handling: Add test for "diff -p" context with a CRLF
	ine ending.

2009-03-21  Andreas Gruenbacher  <agruen@suse.de>

	* patch.c (main): With -r, instead of moving the global reject
	file into place, copy the first reject into the file, and
	append all the rest.  Discard rejects with -r -.
	* patch.man: Document the latter.
	* util.c (copy_to_fd): New function.
	(copy_file): Use that.
	(append_to_file): New function.
	* util.h (append_to_file): Add function declaration.
	* tests/global-reject-files: New test case.
	* Makefile.in (TESTS): Add test case.

	* patch.man: Minor fix.

	* pch.c (another_hunk, pch_swap): Always add the '^' hunk end
	marker: apply_hunk() and abort_hunk_unified() rely on it.
	(pch_char): Explain when this returns '\n'.
	* util.c: Remove unused include <version.h>.

2009-03-20  Andreas Gruenbacher  <agruen@suse.de>

	* patch.c: New option --reject-format=FORMAT.
	(abort_hunk_context): Rename from abort_hunk().
	(abort_hunk_unified, abort_hunk, mangled_patch,
	print_unidiff_range): New functions.
	* patch.man: Document this.
	* pch.c, pch.h (pch_normalize): New function.
	* tests/reject-format: New test case.
	* Makefile.in (TESTS): Add test case.
	* tests/preserve-c-function-names: Update.

	* pch.c (p_name): New variable.
	(intuit_diff_type): Save the old, new, and index filenames.
	(pch_char): Return either of the saved filenames.
	* pch.h: Move enum nametype here from pch.c.  Declare pch_name().
	* patch.c (abort_hunk, abort_hunk_unified, abort_hunk_context):
	New HEADER and REVERSE arguments.
	(print_header_line): New function.
	(abort_hunk_unified, abort_hunk_context): Use it.
	* tests/corrupt-reject-files, tests/preserve-c-function-names,
	tests/reject-format: Update.

	* patch.c (main): No longer set reject file modes to the modes of the
	files they are assiciated with: the previous behavior is inconsistent
	with global reject files (-r), which are not associated with any
	particular file.
	* tests/preserve-mode-and-timestamp: New test case.
	* Makefile.in (TESTS): Add test case.

	* Makefile.in (DISTFILES): Add the files from DISTFILES_M4,
	DISTFILES_PC, DISTFILES_PC_DJGPP.
	(DISTFILES_M4, DISTFILES_PC, DISTFILES_PC_DJGPP): Remove.
	(distclean): Also remove config.hin~ and autom4te.cache/.
	(maintainer-clean): Also remove aclocal.m4, config.hin, configure.
	(dist): Make work for DISTFILES in subdirectories.  Normalize and
	sort DISTFILES.

	* Makefile.in (MISC): Add VERSION.
	(FORCE): New target.
	(VERSION): Recompute automatically from repository.
	(configure): Depend on VERSION.  Regenerate with --force: autoconf
	does not recognize the dependency between VERSION and ocnfigure.
	(config.hin): Regenerate with --force.
	(maintainer-clean): Also remove VERSION.
	* configure.ac: Compute PACKAGE_VERSION from repository.
	* update-version.sh: New file.

	* README-alpha: New file.
	* Makefile.in (dist): Add README-alpha when appropriate.

	* Makefile.in (M4FILES): Rename from ACINCLUDE_INPUTS.
	(aclocal.m4): Recompute with aclocal.

	* tests/test-lib.sh: Add library for simple test scripts.
	* tests/crlf-handling, tests/remember-backup-files: New test cases.
	* Makefile.in (TESTS): New variable.  Add test cases.
	(check): Replace the dummy test target with running all TESTS.

	* pch.c, pch.h (pch_c_function): New function.
	* pch.c (p_c_function): New variable.
	(another_hunk): Preserve the "diff -p" output.
	* patch.c (abort_hunk): Use pch_c_function().
	* tests/preserve-c-function-names: New test case.
	* Makefile.in (TESTS): Add test case.

	* util.c (savebuf): Return NULL if size == 0.
	* pch.c (another_hunk): Check size for size != 0 before checking
	savebuf()'s return value.
	* tests/no-newline-triggers-assert: New test case.
	* Makefile.in (TESTS): Add test case.

	* tests/corrupt-reject-files: new test case for Jim Meyering's
	2007-08-26 fix.
	* Makefile.in (TESTS): Add test case.

2009-03-19  Andreas Gruenbacher  <agruen@suse.de>

	Imported from Paul Eggert's working directory:
	* exitfail.c, exitfail, m4/exitfail.m4: Import from gnulib.
	* hash.c, hash.h, m4/hash.m4: Likewise.
	* m4/extensions.m4: Likewise.
	* timespec.h, m4/timespec.m4: Likewise.
	* m4/st_mtim.m4: New file.
	* configure.ac: Update.
	* common.h: Include <limits.h> unconditionally.  Include <stdint.h>
	if we have it.
	* inp.c (plan_b, ifetch): Remove unnecessary casts.
	* maketime.c, partime.c: Include <limits.h>, <stdlib.h>, <time.h>
	unconditionally.  Convert from K&R to ANSI C.
	* maketime.h, partime.h: Convert from K&R to ANSI C.
	* pch.c (p_indent, pget_line, intuit_diff_type): Use size_t for
	indents.
	* util.c: Assume we have vfprintf().
	(NUM_SIGS): Cast to int in.
	(fatal_exit_handler): Replace obsolescent AC_RETSIGTYPE.
	* Various files: Update copyright notices.

2007-08-26  Jim Meyering  <jim@meyering.net>

	* pch.c (another_hunk): Avoid an off-by-one error that would
	result in NUL bytes in .rej files.

2004-07-21  Paul Eggert  <eggert@twinsun.com>

	* Makefile.in (SRCS): Move hash.c here from LIBSRCS.
	(exitfail.$(OBJEXT), patch.$(OBJEXT), xmalloc.$(OBJEXT)):
	Depend on exitfail.h.
	(hash.$(OBJEXT), util.$(OBJEXT)): Depend on hash.h.
	* util.c: Whitespace cleanup in file_id.

2004-07-19  Stepan Kasal  <kasal@ucw.cz>

	* pch.c (get_ed_command_letter): Allow commands without address.

2003-11-10  Manu B  <manubee@users.sourceforge.net>

	Trivial change to port to mingw, which declares mkdir in unistd.h.
	* m4/mkdir.m4 (PATCH_FUNC_MKDIR_TAKES_ONE_ARG): Include unistd.h.
	* common.h (mkdir): Define after including unistd.h.

2003-09-11  Paul Eggert  <eggert@twinsun.com>

	* pch.c (do_ed_script): Adjust to copy_file signature change.

	* Makefile.in (STDBOOL_H): New macro.  All uses of @STDBOOL_H@ changed.
	(SRCS): Add exitfail.c.
	(OBJS): Add exitfail.$(OBJEXT).
	(HDRS): Add exitfail.h.
	(stdbool.h): Use $@, as gnulib now suggests.
	(ACINCLUDE_INPUTS): Add exitfail.m4, extensions.m4.
	* common.h: Include <string.h>, <stdlib.h> unconditionally.
	* configure.ac (gl_USE_SYSTEM_EXTENSIONS): Use this instead
	of AC_GNU_SOURCE.
	(gl_EXITFAIL): Add.
	* patch.c: Include exitfail.h.
	(main): Set exit_failure, not xalloc_exit_failure.

	* inp.c (get_input_file): Clear cs if dry run.

	* util.c (fetchname): Handle missing timestamps better.

	* Makefile.in (LIBSRCS): Add hash.c.
	(OBJS): Add hash.$(OBJEXT).
	(HDRS): Add hash.h.
	(MISC): Add timespec.h.
	(ACINCLUDE_INPUTS): Add hash.m4, st_mtim.m4, timespec.m4
	(util.$(OBJEXT): Depend on timespec.h.
	* configure.ac (gl_HASH, gl_TIMESPEC): Add.
	* patch.c (spew_output): New output arg, to contain status of output
	file.
	(main): Use it to get status of output file, and pass this to
	move_file as needed.  Initialize hash table.
	* util.c (file_id): New type.
	(file_id_hasher, file_id_comparator, init_backup_hash_table,
	insert_file, file_already_seen): New functions.
	(file_id_table): New var.
	(move_file): New arg FROMST; all uses changed.
	Do not backup a file that's already been patched.
	Keep track of files that have been patched.
	(copy_file): New arg TOST; all uses changed.
	* util.h (copy_file, move_file): Adjust decls as per above.
	(init_backup_hash_table): New decl.


2003-07-05  Paul Eggert  <eggert@twinsun.com>

	* Makefile.in (check): Add a trivial check that "patch --help" works.
	From a suggestion by Ed Avis.

2003-07-02  Paul Eggert  <eggert@twinsun.com>

	* pch.c (intuit_diff_type): If a unified-diff header line contains
	trailing CR, strip CR from each body line.  This corrects a bug
	introduced in the 2003-05-18 patch.  Bug reported by Andreas
	Gruenbacher.

	* mkdir.c, rmdir.c, m4/rmdir.m4: Remove; we no longer
	need to worry about ancient hosts that lack these functions.

	* addext.c, backupfile.c, backupfile.h, dirname.h, m4/backupfile.m4,
	m4/onceonly.m4, m4/quote.m4, malloc.c, quote,c, quote.h, realloc.c,
	strcasecmp.c, xalloc.h, xmalloc.c: Sync with gnulib.
	* stdbool_.h: Renamed from stdbool.h.in; all uses changed.
	This renaming is imported from gnulib.
	* m4/strcase.m4: New file, imported from gnulib.

	* Makefile.in (LIBSRCS): Remove mkdir.c and rmdir.c.
	(stdbool.h): Put output into temporary file and then rename it;
	this change is imported from gnulib.
	(mostlyclean): Clean stdbool.h-t too.
	(ACINCLUDE_INPUTS): Remove rmdir.m4.  Add strcase.m4.
	* configure.ac (gl_FUNC_RMDIR): Remove.
	(jm_PREREQ_ADDEXT): Remove; now down by gl_BACKUPFILE.
	(gl_STRCASE, gl_XALLOC): Add.
	(AC_REPLACE_FUNCS): Remove mkdir, strcasecmp.

2003-05-20  Paul Eggert  <eggert@twinsun.com>

	* NEWS, configure.ac (AC_INIT): Version 2.5.9 released.

	* Makefile.in (HDRS): Add gettext.h.

	Use bool, not int, for booleans.

	* pch.c (pch_says_nonexistent): Returns int, not bool.

	* configure.ac: Add AM_STDBOOL_H.

	* Makefile.in (MISC): Add stdbool.h.in.
	(stdbool.h): New rule.
	(ACINCLUDE_INPUTS): Add stdbool.m4.
	(mostlyclean): Remove stdbool.h.
	(COMMON): New macro; use it instead of common.h for dependencies.

	* common.h: Include <stdbool.h>.
	Remove TRUE, FALSE, bool.  All uses changed to standard names.

	* common.h (reverse, set_time, set_utc):
	Use bool, not int, for booleans.
	* pch.c (p_strip_trailing_cr, p_pass_comments_through,
	prefix_components, pget_line, re_patch,
	there_is_another_patch, intuit_diff_type, scan_linenum,
	another_hunk, pget_line, pch_timestamp): Likewise.
	* inp.h (ifetch): Likewise.
	* util.c (move_file, version_controller, version_get, ok_to_reverse,
	set_signals): Likewise.
	* inp.c (report_revision, get_input_file, plan_a, plan_b, ifetch):
	Likewise.
	* util.h (ok_to_reverse, version_controller, version_get,
	move_file, set_signals): Likewise.
	* pch.h (another_hunk, pch_says_nonexistent, pch_timestamp):
	Likewise.
	* patch.c (struct outstate, numeric_string, make_backups,
	backup_if_mismatch, remove_empty_files,
	reverse_flag_specified, main, reinitialize_almost_everything,
	get_some_switches, apply_hunk, init_output, copy_till):
	Likewise.

2003-05-18  Paul Eggert  <eggert@twinsun.com>

	* pch.c (p_pass_comments_through): New var.
	(pget_line): Accept new arg for pass_comments_through.
	All callers changed.
	(there_is_another_patch): Do not suggest -p for ed diffs.
	(intuit_diff_type): Check ed command for correct syntax.
	Do not set p_strip_trailing_cr merely because a -p line contains a CR.
	(get_ed_command_letter): New function.
	(do_ed_script): Use it.  Do not treat '#' data lines as comments in ed
	scripts.

	* util.c (move_file):
	Don't assume that when 'rename(A,B)' succeeds then A no
	longer exists.  This is not true of POSIX 1003.1-2001 rename when A
	and B are links to the same file.
	(fetchname): Fix test for file names with internal spaces.

	* version.c: Don't include patchlevel.h.
	(version): Use PACKAGE_NAME and PACKAGE_VERSION instead of obsolete
	PROGRAM_NAME and PATCH_VERSION.
	(copyright_string): Bump to 2003.

	* common.h (FILESYSTEM_PREFIX_LEN, ISSLASH):
	Remove; now done by 'configure'.
	(PROGRAM_NAME): Remove; now done by 'configure' as PACKAGE_NAME.

	* patch.c: Do not include <exitfail.h>.
	(main): Set xalloc_exit_failure, not exit_failure.
	Add "&& !skip_rest_of_patch" when deciding to continue ed scripts.
	(option_help): Use PACKAGE_BUGREPORT rather than hardcoding.

	* configure.ac (AC_PREREQ): Bump to 2.57.
	(AC_GNU_SOURCE): Add, early on.
	(gl_BACKUPFILE, gl_DIRNAME, gl_ERROR, gl_FUNC_MEMCHR, gl_FUNC_RMDIR,
	gl_GETOPT, gl_PREREQ_XMALLOC, gl_QUOTE, gl_QUOTEARG): Add.
	(jm_PREREQ_ADDEXT): Add, with definition.
	(jm_PREREQ_DIRNAME, jm_PREREQ_ERROR, jm_PREREQ_MEMCHR,
	jm_PREREQ_QUOTEARG): Remove.
	(AC_REPLACE_FUNCS): Remove memchr, rename, rmdir).
	(jm_FUNC_GLIBC_UNLOCKED_IO, jm_AC_DOS): Add.
	(jm_CHECK_TYPE_STRUCT_DIRENT_D_INO): Do not call directly.
	(AC_OUTPUT): Use new style, with AC_CONFIG_FILES.

	Update to current CVS gnulib.

	* exitfail.c, exitfail.h, patchlevel.h, rename.c, m4/c-bs-a.m4,
	m4/jm-glibc-io.m4, m4/prereq.m4: Remove.
	* m4/backupfile.m4, m4/dirname.m4, m4/dos.m4, m4/getopt.m4,
	m4/memchr.m4, m4/onceonly.m4, m4/quote.m4, m4/quotearg.m4,
	m4/rmdir.m4, m4/unlocked-io.m4, m4/xalloc.m4: New files.
	* Makefile.in (LIBSRCS): Move error.c here from SRCS.
	Remove rename.c.
	(OBJS): Remove error.$(OBJEXT).
	(HDRS): Remove exitfail.h, patchlevel.h.
	(ACINCLUDE_INPUTS): Remove c-bs-a.m4, jm-glibc-io.m4, prereq.m4.
	Add backupfile.m4, dirname.m4, dos.m4, getopt.m4, memchr.m4,
	onceonly.m4, quote.m4, quotearg.m4, rmdir.m4, unlocked-io.m4,
	xalloc.m4.
	(patchlevel.h): Remove.  All uses removed.
	(argmatch.$(OBJEXT), error.$(OBJEXT), quotesys.$(OBJEXT)),
	xmalloc.$(OBJEXT)): Depend on gettext.h.
	(dirname.$(OBJEXT), quote.$(OBJEXT), strncasecmp.$(OBJEXT)): New rules.
	(patch.$(OBJEXT), xmalloc.$(OBJEXT)): Remove exitfail.h.
	(rename.$(OBJEXT)): Remove.
	(version.$(OBJEXT)): Remove util.h.
	(xmalloc.$(OBJEXT)): Add error.h.

2002-11-23  Paul Eggert  <eggert@twinsun.com>

	* patch.c (main): Don't check for zero-sized file after 'ed'
	when skipping patch.  From Michael Fedrowitz.

2002-06-03  Paul Eggert  <eggert@twinsun.com>

	* configure.ac (AC_OUTPUT): Use new form, with AC_CONFIG_FILES,
	instead of obsolescent form.  Patch from Art Haas.

	* pch.c (intuit_diff_type): Do not warn about trailing white space
	after Prereq: word.  Bug reported by Mike Castle.

2002-06-02  Paul Eggert  <eggert@twinsun.com>

	* NEWS, configure.ac (AC_INIT): Version 2.5.8 released.

	* README: POSIX.2 -> POSIX.
	* inp.c (report_revision): Don't modify 'revision', since
	it gets freed later.  Bug reported by Mike Castle.

2002-05-30  Paul Eggert  <eggert@twinsun.com>

	* NEWS, configure.ac (AC_INIT): Version 2.5.7 released.

	* Makefile.in (MISC): Remove README-alpha.
	(patchlevel.h): Depend on configure, not configure.ac.

	* INSTALL: Upgrade to Autoconf 2.53 version.

2002-05-28  Paul Eggert  <eggert@twinsun.com>

	* patch.c (end_defined, apply_hunk): Output #endif without
	the comment, as POSIX 1003.1-2001 requires.

	* pch.c (there_is_another_patch): Flush stderr after perror.

	* NEWS, configure.ac (AC_INIT): Version 2.5.6 released.

	* strcasecmp.c, strncasecmp.c: New files, taken from fileutils.
	* config.guess, config.sub: Remove.
	* Makefile.in (LIBSRCS): Add strcasecmp.c, strncasecmp.c.
	(MISC): Remove config.guess, config.sub.

	The code already assumes C89 or better, so remove K&R stuff.
	* common.h (volatile): Remove.
	(GENERIC_OBJECT): Remove; all uses changed to 'void'.
	(PARAMS): Remove; all uses changed to prototypes.
	* configure.ac (AC_PROG_CC_STDC): Add.
	* util.c (vararg_start): Remove.  All uses changed to va_start.
	Always include <stdarg.h>.

	* configure.ac (AC_CANONICAL_HOST): Remove.
	(AC_REPLACE_FUNCS): Add strncasecmp.
	(AC_CHECK_DECLS): Add mktemp.

	* patch.c (main): Remove useless prototype decl.
	(mktemp): Don't declare if HAVE_DECL_MKTEMP || defined mktemp.
	(make_temp): Now accepts char, not int.

2002-05-26  Paul Eggert  <eggert@twinsun.com>

	* patch.c (not_defined): Prepend newline.  All uses changed.
	(apply_hunk): Fix bug: -D was outputting #ifdef when it should
	have been outputting #ifndef.  Bug report and partial fix by
	Jason Short.

	* pch.c (intuit_diff_type): When reading an ed diff, don't use
	indent and trailing-CR-ness of "." line; instead, use that of the
	command.  Bug reported by Anthony Towns; partial fix by Michael
	Fedrowitz.
	(intuit_diff_type): If the index line exists, don't report a
	missing header.  Fix by Chip Salzenberg.

2002-05-26  Alessandro Rubini  <rubini@gnu.org>

	* patch.c (locate_hunk): Fixed updating of last_offset.

2002-05-25  Paul Eggert  <eggert@twinsun.com>

	* NEWS, README: Diffutils doc is up to date now.
	Bug reporting address is now <bug-patch@gnu.org>.
	* README: Describe '--disable-largefile'.

	* NEWS-alpha, dirname.c, dirname.h, exitfail.c, exitfail.h,
	quote.c, quote.h, unlocked-io.h: New files, taken from diffutils
	and fileutils.

	* argmatch.c: [STDC_HEADERS]: Include stdlib.h, for 'exit'.

	* addext.c, argmatch.c, argmatch.h, backupfile.c, basename.c:
	Update from diffutils and fileutils.

	* ansi2knr.1, ansi2knr.c: Remove.

	* common.h: HAVE_SETMODE && O_BINARY -> HAVE_SETMODE_DOS.
	* patch.c (usage): Likewise.
	* pch.c (open_patch_file): Likewise.

	* configure.ac: Renamed from configure.in.  Add copyright notice.
	(AC_PREREQ): Bump to 2.53.
	(AC_INIT): Use 2.5x style.
	(AC_CONFIG_SRCDIR): Add.
	(PACKAGE, VERSION): Remove.
	(AC_C_PROTOTYPES): Use this instead of AM_C_PROTOTYPES.
	(jm_CHECK_TYPE_STRUCT_UTIMBUF): Use this instead of jm_STRUCT_UTIMBUF.
	(jm_PREREQ_ADDEXT, jm_PREREQ_DIRNAME, jm_PREREQ_ERROR,
	jm_PREREQ_MEMCHR, jm_PREREQ_QUOTEARG): Add.
	(AC_CHECK_DECLS): Add free, getenv, malloc.
[--snip--]
