Repository navigation
Conversation
Ifdef output of two identical files is the file itself, as with GNU diff. Skip the identical-contents and same-file shortcuts for -D, and skip the same-file shortcut for -y too, which also prints the lines.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
Note: |
diff -D NAMEprints nothing for two identical files. GNU diff prints the file itself, since the merged output of two identical files is just their common lines:The same happens when one file is passed twice (
diff -D X a a), and also for-yin that case. GNU prints the lines for both, while we returned early.compare_fileshas two shortcuts that return before any output: one for the same file (or- -), and one for identical contents. The identical-contents one already made an exception for-y(and-e, for its missing-newline warning). This adds-Dto it, and limits the same-file shortcut to formats that don't print the lines of identical files.- -keeps the shortcut, since stdin can only be read once.I checked these against GNU diff 3.12 and the output and exit status match byte for byte:
-D Xwith identical files, the same file twice, files without a trailing newline, empty files, and identical binary files (with and without-a)-D Xwith--briefand with-s, and differing files-ywith the same file twice, and-e,-u,-s,-qwith the same file twiceThe new tests
no_differences_ifdefandsame_file_prints_linesfail on main and pass with this change.cargo testpasses, andcargo fmt --checkandcargo clippy -- -D warningsare clean.I used Claude Code (Opus 5.5) to help investigate and draft this change; I reproduced the bug and checked the fix myself.