Bug 90960

Summary: diff file1 file2 ... filen directory
Product: [Retired] Red Hat Linux Reporter: John Dalbec <jpdalbec>
Component: diffutilsAssignee: Tim Waugh <twaugh>
Status: CLOSED WONTFIX QA Contact: Mike McLean <mikem>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1Keywords: FutureFeature
Target Milestone: ---   
Target Release: ---   
Hardware: i686   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2003-05-16 10:08:03 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description John Dalbec 2003-05-15 19:40:23 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2)
Gecko/20030208 Netscape/7.02

Description of problem:
Would it be possible to extend the "diff" utility to operate like "mv" and "cp"
in the above situation?  The output should be similar to the output of "diff
directory1 directory2".  The files "file1" ... "filen" should be compared to the
files of the same names in the directory "directory".  Any other files in the
directory "directory" should be ignored.  If POSIX forbids this, could another
utility be created that works like "diff" but has this feature?

Version-Release number of selected component (if applicable):


How reproducible:
Didn't try

Steps to Reproduce:
1. diff file1 file2 directory

    

Actual Results:  error message

Expected Results:  file1 should be compared to directory/`basename file1`.  If
they differ, the equivalent "diff" command should be printed followed by normal
"diff" output.
file2 should be compared to directory/`basename file2`.  If they differ, the
equivalent "diff" command should be printed followed by normal "diff" output.
directory/file3 should be ignored, i.e., no "Only in directory: file3" message
should be printed.

Additional info:

You can sort of do this by copying the requested files and their partners in the
requested directory to temporary directories and then running "diff tmpdir1
tmpdir2" but then the "diff" lines will have tmpdir1 and tmpdir2 instead of the
original locations of the files.  Plus it seems wasteful to do more file copying
than strictly necessary.

Comment 1 Tim Waugh 2003-05-16 10:08:03 UTC
This isn't hard to do in a few lines of shell:

#!/bin/bash
TMPDIR=$(mktemp -d mydiff.XXXXXX) || exit 1
FILES=("$@")
DIR=${FILES[$(($# - 1))]}
unset FILES[$(($# - 1))]
cp -l ${FILES[@]} "$TMPDIR"
diff -ur "$TMPDIR" "$DIR" | \
        filterdiff --strip=1 --addprefix=$(dirname "$DIR/.")/
rm -rf "$TMPDIR"

It's not something we're likely to add to diffutils I'm afraid, since for one
thing it makes the meaning of several of the options much less clear-cut.  Feel
free to discuss it with the upstream maintainer of diffutils of course.

Comment 2 John Dalbec 2003-06-20 19:50:42 UTC
diffutils 2.7.2 has the "--to-file" option which allows
diff file1 file2 file3 --to-file=directory