Bug 90960 - diff file1 file2 ... filen directory
Summary: diff file1 file2 ... filen directory
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: diffutils
Version: 7.1
Hardware: i686
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Tim Waugh
QA Contact: Mike McLean
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-05-15 19:40 UTC by John Dalbec
Modified: 2007-04-18 16:53 UTC (History)
0 users

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2003-05-16 10:08:03 UTC
Embargoed:


Attachments (Terms of Use)

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



Note You need to log in before you can comment on or make changes to this bug.