Bug 250015 - diff -purw fails with 'error: conflicting output format options.'
Summary: diff -purw fails with 'error: conflicting output format options.'
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Kyle Evans
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-30 20:43 UTC by Ed Maste
Modified: 2023-12-25 15:03 UTC (History)
5 users (show)

See Also:
kevans: mfc-stable12?
kevans: mfc-stable11-


Attachments
git(1) diff against base diff (941 bytes, patch)
2020-10-03 20:41 UTC, Kyle Evans
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer freebsd_triage 2020-09-30 20:43:32 UTC
My finger memory wants to use diff -purw -- show C functions, unified 3 line, recursive, ignore whitespace -- but this now produces an error:

$ diff -purw foo bar
error: conflicting output format options.
Comment 1 Kyle Evans freebsd_committer freebsd_triage 2020-10-03 20:08:35 UTC
(In reply to Ed Maste from comment #0)

Hmm... this is unfortunate. -p sets the format to context, which is incompatible with -u. I note that the following is what GNU diff appears to do:

kevans91:~/grep$ diff -p A B
*** A	2020-10-03 15:02:53.072790765 -0500
--- B	2020-10-03 15:03:00.652785502 -0500
***************
*** 1,7 ****
  A
  B
! C
! D
  E
  F
  G
--- 1,7 ----
  A
  B
! X
! Y
  E
  F
  G
kevans91:~/grep$ diff -pu A B
--- A	2020-10-03 15:02:53.072790765 -0500
+++ B	2020-10-03 15:03:00.652785502 -0500
@@ -1,7 +1,7 @@
 A
 B
-C
-D
+X
+Y
 E
 F
 G
kevans91:~/grep$ diff -up A B
--- A	2020-10-03 15:02:53.072790765 -0500
+++ B	2020-10-03 15:03:00.652785502 -0500
@@ -1,7 +1,7 @@
 A
 B
-C
-D
+X
+Y
 E
 F
 G

I suspect the answer here is that we should leave the diff_format as D_UNSET, then after all option processing default it to D_CONTEXT if it's still unset and D_PROTOTYPE is set. CC'ing bapt@ to get a second opinion.

I also note that GNU diff doesn't appear to check the format at all for -p, so we should probably stop that as well:

kevans91:~/grep$ diff -qp A B
Files A and B differ
kevans91:~/grep$ diff -pq A B
Files A and B differ
Comment 2 Kyle Evans freebsd_committer freebsd_triage 2020-10-03 20:41:35 UTC
Created attachment 218502 [details]
git(1) diff against base diff
Comment 3 Ed Maste freebsd_committer freebsd_triage 2020-10-05 12:47:34 UTC
(In reply to Kyle Evans from comment #2)
Patch LGTM
Comment 4 Ed Maste freebsd_committer freebsd_triage 2020-10-25 18:24:31 UTC
ping
Comment 5 commit-hook freebsd_committer freebsd_triage 2020-10-27 12:27:34 UTC
A commit references this bug:

Author: kevans
Date: Tue Oct 27 12:27:26 UTC 2020
New revision: 367076
URL: https://svnweb.freebsd.org/changeset/base/367076

Log:
  diff: don't force the format to 'context' with -p immediately

  Instead, leave the fomat as unspecified (if it hasn't been) and use the
  -p flag as a hint to 'context' if no other formatting option is specified.

  This fixes `diff -purw`, used frequently by emaste, and matches the behavior
  of its GNU counterpart.

  PR:		250015
  Reviewed by:	emaste
  MFC after:	1 week

Changes:
  head/usr.bin/diff/diff.c
Comment 6 Olli Hauer freebsd_committer freebsd_triage 2020-11-04 05:53:50 UTC
Seems this is not the only regression on 12.2.

The combination of the -n -u flags (-n -r -u) are also complaining with
  error: conflicting output format options.

Using this combination in many scripts on many systems, 
My quick workaround was to build diff from the 12.1 sources.
Comment 7 Kyle Evans freebsd_committer freebsd_triage 2020-11-04 12:39:31 UTC
Considering backing out the patch in question from stable/ and 12.2 S "too invasive"
Comment 8 fehmi noyan isi 2020-11-13 09:27:54 UTC
The conflicting output error must have been introduced by the bug report below

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=243975
Comment 9 commit-hook freebsd_committer freebsd_triage 2020-11-14 01:00:43 UTC
A commit references this bug:

Author: kevans
Date: Sat Nov 14 00:59:55 UTC 2020
New revision: 367656
URL: https://svnweb.freebsd.org/changeset/base/367656

Log:
  MFC r367076: diff: don't force the format to 'context' with -p immediately

  Instead, leave the fomat as unspecified (if it hasn't been) and use the
  -p flag as a hint to 'context' if no other formatting option is specified.

  This fixes `diff -purw`, used frequently by emaste, and matches the behavior
  of its GNU counterpart.

  PR:		250015

Changes:
_U  stable/12/
  stable/12/usr.bin/diff/diff.c
Comment 10 Mark Linimon freebsd_committer freebsd_triage 2023-12-25 15:03:08 UTC
^Triage: committed back in 2020.  The mfc-stable* flags' values are now OBE.