aboutsummaryrefslogtreecommitdiff
path: root/editors/diff.c
diff options
context:
space:
mode:
Diffstat (limited to 'editors/diff.c')
-rw-r--r--editors/diff.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/editors/diff.c b/editors/diff.c
index ca4a4eae7..daa58af9b 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -76,6 +76,28 @@
76 * 6n words for files of length n. 76 * 6n words for files of length n.
77 */ 77 */
78 78
79//usage:#define diff_trivial_usage
80//usage: "[-abBdiNqrTstw] [-L LABEL] [-S FILE] [-U LINES] FILE1 FILE2"
81//usage:#define diff_full_usage "\n\n"
82//usage: "Compare files line by line and output the differences between them.\n"
83//usage: "This implementation supports unified diffs only.\n"
84//usage: "\nOptions:"
85//usage: "\n -a Treat all files as text"
86//usage: "\n -b Ignore changes in the amount of whitespace"
87//usage: "\n -B Ignore changes whose lines are all blank"
88//usage: "\n -d Try hard to find a smaller set of changes"
89//usage: "\n -i Ignore case differences"
90//usage: "\n -L Use LABEL instead of the filename in the unified header"
91//usage: "\n -N Treat absent files as empty"
92//usage: "\n -q Output only whether files differ"
93//usage: "\n -r Recurse"
94//usage: "\n -S Start with FILE when comparing directories"
95//usage: "\n -T Make tabs line up by prefixing a tab when necessary"
96//usage: "\n -s Report when two files are the same"
97//usage: "\n -t Expand tabs to spaces in output"
98//usage: "\n -U Output LINES lines of context"
99//usage: "\n -w Ignore all whitespace"
100
79#include "libbb.h" 101#include "libbb.h"
80 102
81#if 0 103#if 0
@@ -952,6 +974,31 @@ int diff_main(int argc UNUSED_PARAM, char **argv)
952 if (gotstdin && (S_ISDIR(stb[0].st_mode) || S_ISDIR(stb[1].st_mode))) 974 if (gotstdin && (S_ISDIR(stb[0].st_mode) || S_ISDIR(stb[1].st_mode)))
953 bb_error_msg_and_die("can't compare stdin to a directory"); 975 bb_error_msg_and_die("can't compare stdin to a directory");
954 976
977 /* Compare metadata to check if the files are the same physical file.
978 *
979 * Comment from diffutils source says:
980 * POSIX says that two files are identical if st_ino and st_dev are
981 * the same, but many file systems incorrectly assign the same (device,
982 * inode) pair to two distinct files, including:
983 * GNU/Linux NFS servers that export all local file systems as a
984 * single NFS file system, if a local device number (st_dev) exceeds
985 * 255, or if a local inode number (st_ino) exceeds 16777215.
986 */
987 if (ENABLE_DESKTOP
988 && stb[0].st_ino == stb[1].st_ino
989 && stb[0].st_dev == stb[1].st_dev
990 && stb[0].st_size == stb[1].st_size
991 && stb[0].st_mtime == stb[1].st_mtime
992 && stb[0].st_ctime == stb[1].st_ctime
993 && stb[0].st_mode == stb[1].st_mode
994 && stb[0].st_nlink == stb[1].st_nlink
995 && stb[0].st_uid == stb[1].st_uid
996 && stb[0].st_gid == stb[1].st_gid
997 ) {
998 /* files are physically the same; no need to compare them */
999 return STATUS_SAME;
1000 }
1001
955 if (S_ISDIR(stb[0].st_mode) && S_ISDIR(stb[1].st_mode)) { 1002 if (S_ISDIR(stb[0].st_mode) && S_ISDIR(stb[1].st_mode)) {
956#if ENABLE_FEATURE_DIFF_DIR 1003#if ENABLE_FEATURE_DIFF_DIR
957 diffdir(file, s_start); 1004 diffdir(file, s_start);