diff -u -U 0 results in diff -U 3

Bug #161189 reported by Herbert Thielen
6
Affects Status Importance Assigned to Milestone
diffutils (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

Up to Ubuntu 07.04, 'diff -u -0' behaved like 'diff -U 0'.

Starting with Ubuntu 07.10, 'diff -0' is not possible anymore. But changing to 'diff -u -U 0' isn't possible, it is behaving like 'diff -U 3' because 'diff -u' now results in 'diff -U 3' and the maximum value of '-U 0' and '-U 3' is used.

Using the maximum value of multiple '-U' options (likewise for '-C') seems to be an old (mis-?)feature accoding to changelog, but at least for me it's somewhat annoying: I'm prefering unified context diff, so up to now I had an alias 'rcsdiff="rcsdiff -u"' (rcsdiff just forwards the 'u' to diff). But sometimes, I just need a smaller context and I was using 'rcsdiff -0' for this, resulting (with my alias) to 'rcsdiff -u -0' - worked quite fine.

This way of using an alias for some default values and overwriting it with additional options isn't possible anymore.

I suggest to remove the behaviour to use the maximum value of multiply given options. Normal Unix tool behaviour, as far as I know, is to use just the last value of an option given multiply, not a minimum or maximum value. Also, this special behaviour isn't documented neither in the diff man page nor in the diff info documentation, it's only mentioned in the changelog somwhere.

The following small patch would allow this:

--- diff.c.orig 2002-03-24 08:35:28.000000000 +0100
+++ diff.c 2007-11-09 14:38:47.000000000 +0100
@@ -327,8 +327,7 @@
              numval = 3;

            specify_style (c == 'U' ? OUTPUT_UNIFIED : OUTPUT_CONTEXT);
- if (context < numval)
- context = numval;
+ context = numval;
            explicit_context = 1;
          }
          break;
@@ -463,8 +462,7 @@

        case 'u':
          specify_style (OUTPUT_UNIFIED);
- if (context < 3)
- context = 3;
+ context = 3;
          break;

        case 'v':

Tags: patch
Revision history for this message
Herbert Thielen (thielen) wrote :

Patch mentioned previously added as attachment for easier access.

Revision history for this message
Shawn Ligocki (sligocki) wrote :

This is still true in 8.10. In fact it seems to be a standard on other linux systems as well. However, SunOS diff appears to use the last -C # instead of the largest.

Changed in diffutils (Ubuntu):
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.