From 906bb3b74772d4b1bd39f051d21bfabfec13963c Mon Sep 17 00:00:00 2001 From: Thomas Kolar Date: Tue, 2 Jun 2026 12:49:13 +0200 Subject: [PATCH 1/6] 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 170db3a30689a3c95bd7cbbdf3bf91ff8c92a3d2 Mon Sep 17 00:00:00 2001 From: Thomas Kolar Date: Tue, 2 Jun 2026 12:48:11 +0200 Subject: [PATCH 2/6] 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 0c08b0e6..63245d11 100644 --- a/Makefile.am +++ b/Makefile.am @@ -395,6 +395,8 @@ TESTS = tests/newline1/run-test \ tests/flip18/run-test \ tests/flip19/run-test \ tests/flip20/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 0ffdc9b4ec1e701336e461b9e42e8bc8cf4d7f75 Mon Sep 17 00:00:00 2001 From: Thomas Kolar Date: Tue, 2 Jun 2026 12:50:37 +0200 Subject: [PATCH 3/6] 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 a3c1ecb7..2e5baae5 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; @@ -2269,7 +2270,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); @@ -2342,6 +2346,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; @@ -2421,6 +2426,9 @@ main (int argc, char *argv[]) case 1000 + 'D': debug = 1; break; + case 1000 + 'E': + err_no_commute = 1; + break; default: syntax(1); } From c90cc791b86c41d4068bb91681248df6af0f961f Mon Sep 17 00:00:00 2001 From: Thomas Kolar Date: Tue, 2 Jun 2026 12:51:42 +0200 Subject: [PATCH 4/6] 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 2e5baae5..d154ec8e 100644 --- a/src/interdiff.c +++ b/src/interdiff.c @@ -2019,6 +2019,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, @@ -2029,6 +2031,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++; } From 2b3549e51a5830d9b27bb5816e0eb85ea20e6a5b Mon Sep 17 00:00:00 2001 From: Thomas Kolar Date: Fri, 23 Oct 2026 01:01:20 +0200 Subject: [PATCH 5/6] change: rename --err-no-commute to --fail-on-conflict, as requested during review --- src/interdiff.c | 4 ++-- tests/flip-err-no-commute1/run-test | 6 +++--- tests/flip-err-no-commute2/run-test | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/interdiff.c b/src/interdiff.c index d154ec8e..441796ac 100644 --- a/src/interdiff.c +++ b/src/interdiff.c @@ -2275,7 +2275,7 @@ syntax (int err) " don't revert it\n" " --in-place (flipdiff) Write the output to the original input\n" " files\n" -" --err-no-commute\n" +" --fail-on-conflict\n" " (flipdiff) If the patches don't commute, exit with an\n" " error\n"; @@ -2350,7 +2350,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'}, + {"fail-on-conflict", 0, 0, 1000 + 'E'}, {0, 0, 0, 0} }; char *end; diff --git a/tests/flip-err-no-commute1/run-test b/tests/flip-err-no-commute1/run-test index 9c3036a0..aa56d337 100755 --- a/tests/flip-err-no-commute1/run-test +++ b/tests/flip-err-no-commute1/run-test @@ -5,8 +5,8 @@ . ${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, +# Like flip15, but with --fail-on-conflict. +# When a line is touched by both patches and --fail-on-conflict is passed, # we must quit with an error, and not make any changes. cat << EOF > file.orig @@ -29,7 +29,7 @@ ${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 +! ${FLIPDIFF} --fail-on-conflict patch1 patch2 > patch-flipped 2>errors || exit 1 [ -s errors ] || exit 1 ! [ -s patch-flipped ] || exit 1 diff --git a/tests/flip-err-no-commute2/run-test b/tests/flip-err-no-commute2/run-test index 24125273..ca35c980 100755 --- a/tests/flip-err-no-commute2/run-test +++ b/tests/flip-err-no-commute2/run-test @@ -1,7 +1,7 @@ #!/bin/sh # This is a flipdiff(1) testcase. -# Like flip1, but with --err-no-commute. +# Like flip1, but with --fail-on-conflict. # Test that we error because the patches don't commute. @@ -29,7 +29,7 @@ EOF ${DIFF} -u file.orig file > patch2 -! ${FLIPDIFF} --err-no-commute patch1 patch2 > patch-flipped 2>errors || exit 1 +! ${FLIPDIFF} --fail-on-conflict patch1 patch2 > patch-flipped 2>errors || exit 1 [ -s errors ] || exit 1 ! [ -s patch-flipped ] || exit 1 From 6e61d5a596158740fc42e97daa04fb49f96c2585 Mon Sep 17 00:00:00 2001 From: Thomas Kolar Date: Fri, 23 Oct 2026 01:05:38 +0200 Subject: [PATCH 6/6] change: rename tests for --fail-on-conflict following rename --- Makefile.am | 4 ++-- .../{flip-err-no-commute1 => flip-fail-on-conflict1}/run-test | 0 .../{flip-err-no-commute2 => flip-fail-on-conflict2}/run-test | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename tests/{flip-err-no-commute1 => flip-fail-on-conflict1}/run-test (100%) rename tests/{flip-err-no-commute2 => flip-fail-on-conflict2}/run-test (100%) diff --git a/Makefile.am b/Makefile.am index 63245d11..0ad39445 100644 --- a/Makefile.am +++ b/Makefile.am @@ -395,8 +395,8 @@ TESTS = tests/newline1/run-test \ tests/flip18/run-test \ tests/flip19/run-test \ tests/flip20/run-test \ - tests/flip-err-no-commute1/run-test \ - tests/flip-err-no-commute2/run-test \ + tests/flip-fail-on-conflict1/run-test \ + tests/flip-fail-on-conflict2/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-fail-on-conflict1/run-test similarity index 100% rename from tests/flip-err-no-commute1/run-test rename to tests/flip-fail-on-conflict1/run-test diff --git a/tests/flip-err-no-commute2/run-test b/tests/flip-fail-on-conflict2/run-test similarity index 100% rename from tests/flip-err-no-commute2/run-test rename to tests/flip-fail-on-conflict2/run-test