133 Commits

Author SHA1 Message Date
Jim Meyering
bbc1bdb771 maint: update copyright dates 2026-01-02 16:52:26 -08:00
Jim Meyering
d05765a8f1 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2025-04-08 19:41:07 -07:00
Jim Meyering
16681a3cbc version 3.12
* NEWS: Record release date.
2025-04-08 19:37:19 -07:00
Paul Eggert
e9f8e6a439 diff: fix allocation typo leading to crashes
But reported by Nick Smallbone, with one-line fix by
Collin Funk <https://bugs.gnu.org/76613>.
* src/io.c (find_and_hash_each_line): Fix size computation.
2025-02-28 23:14:35 -08:00
Paul Eggert
706116c651 maint: mention bug#76452 in NEWS 2025-02-21 23:10:06 -07:00
Jim Meyering
41034e8398 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2025-02-02 20:52:15 -08:00
Jim Meyering
3f326ae3ea version 3.11
* NEWS: Record release date.
2025-02-02 20:43:43 -08:00
Jim Meyering
ea7c073d2d maint: once again distribute .tar.gz files
* configure.ac: Reenable distribution of gzip-compressed tarballs,
to help reduce the size of the Guix seed, as discussed at
https://lists.gnu.org/r/coreutils/2020-02/msg00042.html and
https://lists.gnu.org/r/sed-devel/2020-01/msg00013.html
* NEWS (Release): Mention this.
Requested by Nicolas Boos
2025-02-02 11:23:56 -08:00
Jim Meyering
d65b41664a maint: update all copyright dates via "make update-copyright" 2025-01-03 09:47:07 -08:00
Jim Meyering
6c88db1f7b maint: make update-copyright 2024-01-05 09:01:59 -08:00
Paul Eggert
774b942f70 diff: go back to C quoting for diff -c/-u headers
Gleb Fotengauer-Malinovskiy reported <https://bugs/gnu/org/66095>
that the recent change to quoting style broke GNU patch.
* src/util.c: Include quotearg.h.
(current_name): New static var, replacing the the old
current_name0 and current_name1.  All uses changed.
(begin_output): Go back to quoting file names for C,
not for the shell, when they contain troublesome characters.
This is not a simple revert, as the revised code handles
multi-byte characters even in non-UTF-8 locales.
* tests/filename-quoting: Revert previous change to this file.
2023-09-20 00:05:00 -07:00
Paul Eggert
632deed390 maint: fix NEWS typos 2023-09-16 13:28:21 -07:00
Paul Eggert
924f297e3e diff: improve util.c multi-byte handling
* bootstrap.conf (gnulib_modules): Add c32isprint.
* src/util.c: Include mcel.h.
(output_1_line): Return immediately on output error.
Scan multi-byte characters and count their widths.
(analyze_hunk): Ignore multi-byte white space too.
2023-09-13 01:23:43 -05:00
Paul Eggert
5d30da7a5b diff: report special file major+minor
* bootstrap.conf (gnulib_modules): Add sys_types,
for MAJOR_IN_MKDEV and MAJOR_IN_SYSMACROS.
* src/diff.c (major, minor): New macros or functions.
Include <sys/mkdev.h> or <sys/sysmacros.h> for them.
(compare_files): Output major and minor device numbers
for special files that differ.
2023-08-14 00:24:02 -07:00
Paul Eggert
69ae797392 cmp,diff,diff3,sdiff: quote more consistently
* lib/diagnose.c, lib/diagnose.h: New files.
* lib/Makefile.am (noinst_HEADERS, libdiffutils_a_SOURCES):
Add them.
* po/POTFILES.in: Add lib/diagnose.c.
* src/analyze.c, src/cmp.c, src/diff3.c, src/dir.c:
* src/sdiff.c, src/util.c:
Include diagnose.h.
* src/analyze.c (briefly_report, diff_2_files):
* src/cmp.c (usage, main, cmp):
* src/diff.c (add_regexp, summarize_regexp_list, main, compare_files):
* src/diff3.c (usage, process_diff, scan_diff_line):
* src/dir.c (diff_dirs):
* src/sdiff.c (usage, ck_fopen, main, edit):
* src/util.c (perror_with_name, begin_output):
Quote file names or regexps with squote.
* src/cmp.c, src/diff.c, src/diff3.c, src/dir.c, src/sdiff.c:
Include quote.h.
* src/cmp.c, src/diff.c, src/diff3.c, src/sdiff.c (try_help):
Remove; now in diagnose.c.
* src/cmp.c (specify_ignore_initial, main, cmp):
* src/diff.c (main, specify_value, specify_colors_style):
* src/diff3.c (main, read_diff):
* src/dir.c (compare_collated):
* src/sdiff.c (check_child_status, main):
* src/util.c (finish_output):
Quote strings with ‘quote’ or ‘quote_n’.
* src/system.h (EXIT_TROUBLE): Remove; now in diagnose.h
and now an enum.
* src/util.c (c_escape_char, c_escape):
Remove, as we now use squote.
* tests/cmp, tests/filename-quoting, tests/invalid-re:
Adjust to match new behavior.
2023-08-08 17:00:19 -07:00
Paul Eggert
b684567824 diff: output symlink contents when they differ
* bootstrap.conf (gnulib_modules): Add quote.
* src/diff.c: Include quote.h.
(compare_files): Print contents of symlinks that differ,
and quote their names and contents.
* src/system.h (symlink_size_ok): Remove.
(stat_size): Don’t worry about symlink sizes.
* tests/no-dereference: Adjust tests to match new behavior.
2023-08-08 17:00:19 -07:00
Paul Eggert
71fd20c222 diff: prefer openat+fstat more often
This closes some more races, by using openat+fstat instead
of fstatat+openat which can get confused by some other process
renaming files in the meantime.  Not all races are closed of course.
* bootstrap.conf (gnulib_modules): Add d-type.
* src/diff.c (errno_encode, errno_decode): Remove, as file
descriptors are no longer portmanteau variables.  All uses removed.
(detype_from_mode): New function.
(dir_p): Use detype, not stat.st_mode.
(compare_files): New args DETYPE0 and DETYPE1.  All uses changed.
Update detype and err as new info arrives.
Adjust to desc's new use (no longer encodes errno).
Do not ignore lseek failures on regular files.
Prefer openat+fstat to fstatat+openat when detype shows that it's safe,
and avoid both fstat and fstatat if detype suffices.
Use ‘error’ with errno value rather than setting error
and then calling perror_with_name.  Coalesce two of these
error diagnostics into one by moving an error check before
the diagnostic is output.  Coalesce two calls to diff_dirs.
Print file type based on detype if available,
in case neither fstat nor fstatat was called.
* src/diff.h (enum detype): New type.
(struct file_data): New slots err, detype.
(NONEXISTENT, UNOPENED): Renumber so that -1 stands for open failed.
* src/dir.c (HAVE_STRUCT_DIRENT_D_TYPE): Default to false.
(dir_read): Return to caller the d_type, if available.
 	(diff_dirs): Pass detype to compare_files.
2023-08-05 11:01:41 -07:00
Paul Eggert
6477dce501 diff: sort multi-byte file names better
* bootstrap.conf (gnulib_modules): Add builtin-expect.
* lib/mbcel-strcasecmp.c: New file.
* lib/Makefile.am (libdiffutils_a_SOURCES): Add it.
* lib/mbcel.h (MBCEL_LEN_MAX, MBCEL_ENCODING_ERROR_SHIFT)
(MBCEL_UCHAR_FITS, MBCEL_UCHAR_EASILY_FITS): New constants.
(_GL_LIKELY): New macro.
(mbcel_scan): Use it.  Simplify NetBSD code.
(mbcel_scant, mbcel_scanz, mbcel_cmp, mbcel_casecmp): New functions.
* src/dir.c (strcasecoll): Move defn here from system.h,
since only dir.c needs it.  Use mbcel_strcasecmp instead
of strcasecmp.
2023-07-21 11:23:53 -07:00
Paul Eggert
6bf2c33ea4 diff: use openat, fstatat when recursive
This should improve performance when doing recursive comparisons.
Currently there is no attempt to avoid file descriptor exhaustion,
just as previously there is no attempt to avoid file names
that provoke ENAMETOOLONG.  Because of this change, ‘diff - A/B’
now works correctly when standard input is a directory.
* .gitignore: Add lib/dirent.h.
* bootstrap.conf (gnulib_modules): Add fdopendir.
* src/diff.c (main): Initialize noparent’s desc to AT_FDCWD.
(compare_files): Use fstatat with parent directory’s file
descriptor and relative name, instead of lstat or stat.
Likewise for openat and open.
* src/diff.h (struct file_data): New member ‘dirstream’.
(struct comparison): The ‘parent’ member is now &noparent (instead
of null) if there is no parent.  All uses changed.
(curr): New toplevel variable, replacing ‘files’.  All uses changed.
* src/dir.c: Include dirname.h, for last_component.
(dir_read): New arg PARENTDIRFD.  Arg DIR is no longer
pointer-to-const since DIR->desc and DIR->dirstream are now
updated.  Use PARENTDIRFD to open the directory via
opendat+fdopendir instead of via opendir.  Update new dirstream
component instead of closing the directory, since it’s now the
caller’s responsibility to close the directory because callers now
want the file descriptor.  All callers changed.
(diff_dirs): First arg CMP is no longer pointer-to-const since
CMP->file is updated by dir_read.  All callers changed.
(find_dir_file_pathname): First arg is now struct file_data *,
not merely a file name.  All callers changed.
* tests/stdin: Test new behavior when stdin is a directory.
2023-07-18 20:07:13 -07:00
Paul Eggert
a542ab269a diff: support multi-byte comparison
* bootstrap.conf (gnulib_modules): Add c32isspace, c32tolower.
* lib/Makefile.am (noinst_HEADERS): Add mbcel.h.
(libdiffutils_a_SOURCES): Add mbcel.c
* lib/mbcel.c, lib/mbcel.h: New files.
* src/io.c: Include mbcel.h, uchar.h.
(hash): 2nd arg is now hash_value, not merely unsigned char,
since the caller might pass a char32_t now.
(find_and_hash_each_line): Support multi-byte input.
* src/util.c: Include mbcel.h, uchar.h.
(lines_differ): New args S1LEN, S2LEN, needed for mbcel_scan.
Caller changed.  Support multi-byte input.
* tests/ignore-case: New file.
* tests/Makefile.am (TESTS): Add it.
* tests/ignore-tab-expansion: Add UTF-8 test.
* tests/init.cfg (require_utf8_locale_): New function.
* tests/side-by-side: Use it.  Add a column-counting test.
2023-07-09 01:19:45 -07:00
Paul Eggert
572249e0fa diff: ignore tabs consistently with expanding them
* src/io.c (find_and_hash_each_line):
* src/util.c (lines_differ):
Treat '\0', '\a', '\b', '\f', '\r', '\v' consistently with how
side.c treats them when expanding them, e.g., backspacing from
column 1 is a no-op when counting tab columns.
* tests/ignore-tab-expansion: New test.
* tests/Makefile.am (TESTS): Add it.
2023-07-05 11:01:34 -07:00
Paul Eggert
8474b6e088 doc: mention bug#64461 in NEWS 2023-07-04 10:45:31 -07:00
Paul Eggert
ef5e8e03a8 cmp: make -bl locale-independent again
* src/cmp.c (sprintc): Use c_isprint, not isprint, fixing a bug I
introduced in 2004.
* tests/cmp: Test for the bug.
2023-06-26 18:51:54 -07:00
Paul Eggert
9c5fcbdc29 cmp: support -n N with huge N
* src/cmp.c (bytes): Use INTMAX_MAX, not -1, for “infinity”.
This simplifies the code and is not a value that can be exhausted
these days.
(main, cmp): Treat very large -n values as “infinity”.
* tests/cmp: Test this.
2023-06-26 11:59:19 -07:00
Jim Meyering
ae55e99195 maint: avoid syntax-check failure
* NEWS (Bug fixes): Move the two new items from the section
for already-relesed 3.10 into the section for the next release.
2023-06-24 18:01:29 -07:00
Paul Eggert
4ee8300b46 cmp: handle huge -i N with regular files
* NEWS: Document this.
* src/cmp.c (specify_ignore_initial):
If the value exceeds TYPE_MAXIMUM (off_t), set the correspnding
ignore_initial value to -1 instead of reporting an error.
(main, cmp, file_position): All uses changed.  Hence a huge value
will always do the right thing with regular files, which cannot
contain more than TYPE_MAXIMUM (off_t) bytes.  There still may be
EOVERFLOW failures reported for non-regular files, though, as
these can be larger.
* tests/cmp: Test cmp -i N when N cannot fit into 64 bits.
2023-06-24 17:42:01 -07:00
Paul Eggert
584986ad18 cmp: work around Linux tmpfs bug
* lib/cmpbuf.c: Include inttypes.h, for TYPE_MAXIMUM.
(block_read): Work around Linux 6.3.8 tmpfs bug.
2023-06-24 17:42:01 -07:00
Paul Eggert
ff1096a0c2 cmp: fix -s bug when comparing /proc files
* NEWS: Mention this.
* src/cmp.c (main, cmp): Do not trust st_size == 0, as it may
be a /proc file.
* tests/brief-vs-stat-zero-kernel-lies: Also test cmp -s.
2023-06-24 17:42:01 -07:00
Jim Meyering
12747f3138 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2023-05-21 01:53:43 -07:00
Jim Meyering
b1a657b85a version 3.10
* NEWS: Record release date.
2023-05-21 01:50:39 -07:00
Carlo Marcelo Arenas Belón
13a05d1e95 gnulib: fix Y2038 bug (again)
AC_SYS_LARGEFILE meaning has changed, need AC_SYS_YEAR2038 as well

* NEWS: mention this
* tests: add test
* bootstrap.conf: add year2038

Copyright-paperwork-exempt: yes
2023-05-13 22:23:57 -07:00
Paul Eggert
ba08fbbb0c diff: fix bug where -D does not work
Problem reported by Robert Webb (bug#61193).
* NEWS: Mention this.
* src/diff.c (main): Omit stray ‘sizeof’.
* tests/ifdef: New test.
* tests/Makefile.am (TESTS): Add it.
2023-02-10 15:44:38 -08:00
Jim Meyering
aa13187f2a maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2023-01-15 13:25:29 -08:00
Jim Meyering
89b587f03f version 3.9
* NEWS: Record release date.
2023-01-15 13:20:24 -08:00
Jim Meyering
47a1f46f08 maint: update copyright dates 2023-01-01 17:19:37 -08:00
Jim Meyering
aec523d3a4 maint: make update-copyright 2022-01-03 11:49:11 -08:00
Paul Eggert
074cbe590b diff: fix timezone bug on Solaris
Problem reported by Vladimir Marek (bug#51228).
* NEWS: Mention this.
* src/context.c (print_context_label): Pass localtz to nstrftime,
instead of always passing 0.
* src/diff.c (main) [!HAVE_TM_GMTOFF]:
Initialize localtz if time_format uses %z.
* src/diff.h (localtz): New decl.
* tests/Makefile.am (TESTS): Add timezone.
* tests/timezone: New test.
2021-10-15 18:54:49 -07:00
Jim Meyering
3065d7421c maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2021-08-01 18:58:42 -07:00
Jim Meyering
42868488c7 version 3.8
* NEWS: Record release date.
2021-08-01 18:55:07 -07:00
Jim Meyering
22fb055cca maint: update all copyright year number ranges
Run "make update-copyright" and then...
* gnulib: Update to latest with copyright year adjusted.
* tests/init.sh: Sync with gnulib to pick up copyright year.
* bootstrap: Likewise.
2021-01-01 17:37:49 -08:00
Jim Meyering
351f87d0c4 maint: update all copyright year number ranges
Run "make update-copyright" and then...
* gnulib: Update to latest with copyright year adjusted.
* tests/init.sh: Sync with gnulib to pick up copyright year.
* bootstrap: Likewise.
2020-01-01 09:33:03 -08:00
Paul Eggert
8d26b1403e diff: don’t mistreat -N in arg as a large number
Problem reported by alec (Bug#35256).
* NEWS: Mention the fix.
* bootstrap.conf (gnulib_modules): Use strtoimax and xstrtoimax,
not strtoumax and strtoumax.
* src/cmp.c (bytes): Now signed, with -1 representing no limit.
All uses changed.
* src/cmp.c (specify_ignore_initial, main):
* src/diff.c (main):
* src/ifdef.c (format_group):
* src/sdiff.c (interact):
Use strtoimax, not strtoumax.
2019-08-27 16:17:08 -07:00
Jim Meyering
badccffea4 maint: convert all TABs to equivalent spaces in indentation
Using this file,

cat > leading-blank.exempt <<\EOF
(\.gitmodules|help2man|pre-commit)$
(?:^|\/)ChangeLog[^/]*$
(?:^|\/)(?:GNU)?[Mm]akefile[^/]*$
\.(?:am|mk)$
EOF

run the following command to convert all non-conforming leading white
space to be all spaces:

git ls-files \
  | pcregrep -vf leading-blank.exempt \
  | xargs pcregrep -l '^ *\t' \
  | xargs perl -MText::Tabs -ni -le \
    '$m=/^( *\t[ \t]*)(.*)/; print $m ? expand($1) . $2 : $_'

Since that changed old NEWS, I also ran "make update-NEWS-hash"
to update the old_NEWS_hash value in cfg.mk.
2019-01-05 22:47:23 -08:00
Paul Eggert
601eceb57c diff: fix cmp, diff3, sdiff with stdin closed
* NEWS: Mention this.
* src/cmp.c, src/diff3.c, src/sdiff.c: Include stdopen.h.
(main): Call stdopen early.
* src/cmp.c (main): Simplify now that we need not worry about
stdin being closed.
* src/diff.c (main): Translate stdopen diagnostic.
2019-01-05 20:02:02 -08:00
Paul Eggert
2c9d956aac diff: remove unportable ‘diff -N - f <&-’ feature
* NEWS: Mention this.
* bootstrap.conf (gnulib_modules): Add stdopen.
* doc/diffutils.texi (Comparing Directories):
Do not document behavior if stdin is closed.
* src/diff.c: Include stdopen.h.
(main): Call stdopen early.
(compare_files) [__hpux]: Remove recently-introduced
special case for HP-UX exec with stdin closed.
* tests/new-file: Remove tests of the removed feature.
2019-01-05 19:20:36 -08:00
Jim Meyering
197d7d492f maint: update all copyright dates via "make update-copyright"
* gnulib: Also update submodule for its copyright updates.
2019-01-01 19:02:28 -08:00
Jim Meyering
70d787ef44 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2018-12-31 17:58:56 -08:00
Jim Meyering
2de623e7a1 version 3.7
* NEWS: Record release date.
2018-12-31 17:56:36 -08:00
Dennis Lambe Jr
aaf0efa70d diff: adjust ANSI escapes for compatibility with less -R
GNU less can display ANSI-colored text with the -R flag, but this
support has some limitations. One of them is that if an escape
sequence starts on one line and ends on a different line, only the
first line will be colored in less.

As a result, when diff creates colored output with multi-line deletes
or adds, less will only color the first line.

This change resets ANSI color to the default at the end of
each line and restarts it at the beginning of the next. It patches
normal and context mode. Side-by-side already worked in my testing.
* src/context.c (print_context_label, pr_context_hunk): As above.
(pr_unidiff_hunk, print_context_header): Likewise.
* src/normal.c (print_normal_hunk): Likewise.
* tests/colors: Adjust existing tests to accommodate this.
* NEWS (Improvements): Mention it.
Proposed in http://bugs.gnu.org/31105
2018-12-30 22:22:10 -08:00
Paul Eggert
f878003953 diff: fix UMR with --strip-trailing-cr
Problem reported by Hongxu Chen (Bug#31935).
* src/io.c (prepare_text): Strip trailing CR before
doing the rest of the analysis.
* NEWS: Mention the fix.
Co-authored-by: Jim Meyering <jim@meyering.net>
2018-12-28 19:08:16 -08:00