From 63b115b8646cc6b9819fadef8c69f8987906a5cd Mon Sep 17 00:00:00 2001 From: Thomas Kolar Date: Tue, 2 Jun 2026 12:49:13 +0200 Subject: [PATCH 1/4] chore: update project --- lib/.gitignore | 3 +++ m4/.gitignore | 3 +++ m4/gnulib-cache.m4 | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/.gitignore b/lib/.gitignore index 60917124..d0be4ef0 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -68,3 +68,6 @@ /fseterr.h /stdio-consolesafe.c /stdio-impl.h +/memeq.c +/stdcountof.in.h +/streq.c diff --git a/m4/.gitignore b/m4/.gitignore index 02c65204..299ac0bb 100644 --- a/m4/.gitignore +++ b/m4/.gitignore @@ -71,3 +71,6 @@ /eealloc.m4 /locale-fr.m4 /wchar_t.m4 +/memeq.m4 +/stdcountof_h.m4 +/streq.m4 diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4 index 5e48b052..7be8e9d3 100644 --- a/m4/gnulib-cache.m4 +++ b/m4/gnulib-cache.m4 @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2025 Free Software Foundation, Inc. +# Copyright (C) 2002-2026 Free Software Foundation, Inc. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by From 06998270829c0ad6cdeb3c6e4aa18805e9a5bd92 Mon Sep 17 00:00:00 2001 From: Thomas Kolar Date: Tue, 2 Jun 2026 12:48:11 +0200 Subject: [PATCH 2/4] test: add two failing tests for (not yet implemented) --err-no-commute --- Makefile.am | 2 ++ tests/flip-err-no-commute1/run-test | 36 +++++++++++++++++++++++++++++ tests/flip-err-no-commute2/run-test | 36 +++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100755 tests/flip-err-no-commute1/run-test create mode 100755 tests/flip-err-no-commute2/run-test diff --git a/Makefile.am b/Makefile.am index 7d8960cf..d112465c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -394,6 +394,8 @@ TESTS = tests/newline1/run-test \ tests/flip17/run-test \ tests/flip18/run-test \ tests/flip19/run-test \ + tests/flip-err-no-commute1/run-test \ + tests/flip-err-no-commute2/run-test \ tests/unline1/run-test \ tests/nul0/run-test \ tests/nul1/run-test \ diff --git a/tests/flip-err-no-commute1/run-test b/tests/flip-err-no-commute1/run-test new file mode 100755 index 00000000..9c3036a0 --- /dev/null +++ b/tests/flip-err-no-commute1/run-test @@ -0,0 +1,36 @@ +#!/bin/sh + +# This is a flipdiff(1) testcase. + + +. ${top_srcdir-.}/tests/common.sh + +# Like flip15, but with --err-no-commute. +# When a line is touched by both patches and --err-no-commute is passed, +# we must quit with an error, and not make any changes. + +cat << EOF > file.orig +int a; +EOF + +cat << EOF > file +int a, b; +EOF + +${DIFF} -u file.orig file > patch1 + +mv -f file file.orig +cat << EOF > file +ssize_t a, b; +EOF + +${DIFF} -u file.orig file > patch2 + +cp patch1 patch1.orig +cp patch2 patch2.orig + +! ${FLIPDIFF} --err-no-commute patch1 patch2 > patch-flipped 2>errors || exit 1 +[ -s errors ] || exit 1 +! [ -s patch-flipped ] || exit 1 + +exit 0 diff --git a/tests/flip-err-no-commute2/run-test b/tests/flip-err-no-commute2/run-test new file mode 100755 index 00000000..24125273 --- /dev/null +++ b/tests/flip-err-no-commute2/run-test @@ -0,0 +1,36 @@ +#!/bin/sh + +# This is a flipdiff(1) testcase. +# Like flip1, but with --err-no-commute. +# Test that we error because the patches don't commute. + + +. ${top_srcdir-.}/tests/common.sh + +cat << EOF > file.orig +a +b +c +EOF + +cat << EOF > file +a +d +c +EOF + +${DIFF} -u file.orig file > patch1 + +mv -f file file.orig +cat << EOF > file +a +c +EOF + +${DIFF} -u file.orig file > patch2 + +! ${FLIPDIFF} --err-no-commute patch1 patch2 > patch-flipped 2>errors || exit 1 +[ -s errors ] || exit 1 +! [ -s patch-flipped ] || exit 1 + +exit 0 From f4d9198a37c65f275fdcc2e5aac72de9600a6f11 Mon Sep 17 00:00:00 2001 From: Thomas Kolar Date: Tue, 2 Jun 2026 12:50:37 +0200 Subject: [PATCH 3/4] prepare: add --err-no-commute option without implementation --- src/interdiff.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/interdiff.c b/src/interdiff.c index 96f5a92a..3af236cf 100644 --- a/src/interdiff.c +++ b/src/interdiff.c @@ -122,6 +122,7 @@ static int no_revert_omitted = 0; static int use_colors = 0; static int color_option_specified = 0; static int debug = 0; +static int err_no_commute = 0; static struct patlist *pat_drop_context = NULL; @@ -2260,7 +2261,10 @@ syntax (int err) " (interdiff) When a patch from patch1 is not in patch2,\n" " don't revert it\n" " --in-place (flipdiff) Write the output to the original input\n" -" files\n"; +" files\n" +" --err-no-commute\n" +" (flipdiff) If the patches don't commute, exit with an\n" +" error\n"; fprintf (err ? stderr : stdout, syntax_str, progname, progname); exit (err); @@ -2333,6 +2337,7 @@ main (int argc, char *argv[]) {"color", 2, 0, 1000 + 'c'}, {"decompress", 0, 0, 'z'}, {"quiet", 0, 0, 'q'}, + {"err-no-commute", 0, 0, 1000 + 'E'}, {0, 0, 0, 0} }; char *end; @@ -2412,6 +2417,9 @@ main (int argc, char *argv[]) case 1000 + 'D': debug = 1; break; + case 1000 + 'E': + err_no_commute = 1; + break; default: syntax(1); } From f431477d1f20ba8bbb5b37fc50c9a942c286998e Mon Sep 17 00:00:00 2001 From: Thomas Kolar Date: Tue, 2 Jun 2026 12:51:42 +0200 Subject: [PATCH 4/4] feat: implement --err-no-commute option --- src/interdiff.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/interdiff.c b/src/interdiff.c index 3af236cf..d6ad8936 100644 --- a/src/interdiff.c +++ b/src/interdiff.c @@ -2010,6 +2010,8 @@ flipdiff (FILE *p1, FILE *p2, FILE *flip1, FILE *flip2) at += this_offset; remove_line (&intermediate, line + 1, at); this_offset--; + } else if (err_no_commute) { + error (EXIT_FAILURE, 0, "patches don't commute!"); } } else if (line[0] == '-') { if (!patch2_removes_line (linenum, offsets, @@ -2020,6 +2022,8 @@ flipdiff (FILE *p1, FILE *p2, FILE *flip1, FILE *flip2) at += this_offset; insert_line (&intermediate, line + 1, (size_t) got - 1, at); + } else if (err_no_commute) { + error (EXIT_FAILURE, 0, "patches don't commute!"); } this_offset++; }