Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
3 changes: 3 additions & 0 deletions lib/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@
/fseterr.h
/stdio-consolesafe.c
/stdio-impl.h
/memeq.c
/stdcountof.in.h
/streq.c
3 changes: 3 additions & 0 deletions m4/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@
/eealloc.m4
/locale-fr.m4
/wchar_t.m4
/memeq.m4
/stdcountof_h.m4
/streq.m4
2 changes: 1 addition & 1 deletion m4/gnulib-cache.m4
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 13 additions & 1 deletion src/interdiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -2009,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,
Expand All @@ -2019,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++;
}
Expand Down Expand Up @@ -2260,7 +2265,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);
Expand Down Expand Up @@ -2333,6 +2341,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;
Expand Down Expand Up @@ -2412,6 +2421,9 @@ main (int argc, char *argv[])
case 1000 + 'D':
debug = 1;
break;
case 1000 + 'E':
err_no_commute = 1;
break;
default:
syntax(1);
}
Expand Down
36 changes: 36 additions & 0 deletions tests/flip-err-no-commute1/run-test
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions tests/flip-err-no-commute2/run-test
Original file line number Diff line number Diff line change
@@ -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