GNU bug report logs - #31577
Using -S / --starting-file causes diff to miss some files

Previous Next

Package: diffutils;

Reported by: Maxim Baz <lists.gnu <at> maximbaz.com>

Date: Thu, 24 May 2018 08:25:02 UTC

Severity: normal

To reply to this bug, email your comments to 31577 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-diffutils <at> gnu.org:
bug#31577; Package diffutils. (Thu, 24 May 2018 08:25:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Maxim Baz <lists.gnu <at> maximbaz.com>:
New bug report received and forwarded. Copy sent to bug-diffutils <at> gnu.org. (Thu, 24 May 2018 08:25:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Maxim Baz <lists.gnu <at> maximbaz.com>
To: bug-diffutils <at> gnu.org
Subject: Using -S / --starting-file causes diff to miss some files
Date: Thu, 24 May 2018 01:56:06 +0200
Hello,

The manual describes -S option as "start with FILE when comparing directories". My intuition is that this should behave like -O option in git-diff [1]: show differences in FILE first, then show differences in all other files. However, it appears that diff behaves in a different (and quite weird) way: it first composes an ordered list of files to compare, then cuts off the beginning of this list until FILE, and only then starts comparing the remaining files. This is extremely unintuitive and I consider this a bug (and if happens to be "by design", then I propose a new feature request for -O option 🙂)


Specific example:

Create file structure as below, all files in the directory "one" should have word "one" as the contents, all files in the directory "two" should word "two" as the contents (so all files are different).

❯ tree -a
.
├── one
│   ├── dir
│   │   └── file
│   ├── .hidden-dir
│   │   └── file
│   ├── .hidden-file
│   └── zfile
└── two
    ├── dir
    │   └── file
    ├── .hidden-dir
    │   └── file
    ├── .hidden-file
    └── zfile

6 directories, 8 files

❯ diff -ur one two | grep '+++' | wc -l
4

❯ diff -ur -S zfile one two | grep '+++' | wc -l
1

❯ diff -ur -S zfile one two                     
diff --color --unified -ur -S zfile one/zfile two/zfile
--- one/zfile   2018-05-24 01:23:49.237899164 +0200
+++ two/zfile   2018-05-24 01:24:58.260920662 +0200
@@ -1 +1 @@
-one
+two


I expect both diff calls to output differences in 4 files, only the second call to print differences in the file "zfile" first.


[1]: https://git-scm.com/docs/git-diff#git-diff--Oltorderfilegt



Regards,
Maxim Baz




This bug report was last modified 7 years and 22 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.