diff options
| author | Roman Borisov <ext-roman.borisov@nokia.com> | 2011-03-27 23:24:09 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-03-27 23:24:09 +0200 |
| commit | 95f5c52e6f823c710be807fb86c8b2fafec8a334 (patch) | |
| tree | 61005a2708d0b7171b3c7a2b8566339ee5f51dc3 | |
| parent | 1f4447b2d439e6f11d95746bb5f611c353305859 (diff) | |
| download | busybox-w32-95f5c52e6f823c710be807fb86c8b2fafec8a334.tar.gz busybox-w32-95f5c52e6f823c710be807fb86c8b2fafec8a334.tar.bz2 busybox-w32-95f5c52e6f823c710be807fb86c8b2fafec8a334.zip | |
diff: optimize diffing of files with the same metadata
Signed-off-by: Roman Borisov <ext-roman.borisov@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | editors/diff.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/editors/diff.c b/editors/diff.c index ca4a4eae7..3719bb49f 100644 --- a/editors/diff.c +++ b/editors/diff.c | |||
| @@ -952,6 +952,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))) | 952 | 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"); | 953 | bb_error_msg_and_die("can't compare stdin to a directory"); |
| 954 | 954 | ||
| 955 | /* Compare metadata to check if the files are the same physical file. | ||
| 956 | * | ||
| 957 | * Comment from diffutils source says: | ||
| 958 | * POSIX says that two files are identical if st_ino and st_dev are | ||
| 959 | * the same, but many file systems incorrectly assign the same (device, | ||
| 960 | * inode) pair to two distinct files, including: | ||
| 961 | * GNU/Linux NFS servers that export all local file systems as a | ||
| 962 | * single NFS file system, if a local device number (st_dev) exceeds | ||
| 963 | * 255, or if a local inode number (st_ino) exceeds 16777215. | ||
| 964 | */ | ||
| 965 | if (ENABLE_DESKTOP | ||
| 966 | && stb[0].st_ino == stb[1].st_ino | ||
| 967 | && stb[0].st_dev == stb[1].st_dev | ||
| 968 | && stb[0].st_size == stb[1].st_size | ||
| 969 | && stb[0].st_mtime == stb[1].st_mtime | ||
| 970 | && stb[0].st_ctime == stb[1].st_ctime | ||
| 971 | && stb[0].st_mode == stb[1].st_mode | ||
| 972 | && stb[0].st_nlink == stb[1].st_nlink | ||
| 973 | && stb[0].st_uid == stb[1].st_uid | ||
| 974 | && stb[0].st_gid == stb[1].st_gid | ||
| 975 | ) { | ||
| 976 | /* files are physically the same; no need to compare them */ | ||
| 977 | return STATUS_SAME; | ||
| 978 | } | ||
| 979 | |||
| 955 | if (S_ISDIR(stb[0].st_mode) && S_ISDIR(stb[1].st_mode)) { | 980 | if (S_ISDIR(stb[0].st_mode) && S_ISDIR(stb[1].st_mode)) { |
| 956 | #if ENABLE_FEATURE_DIFF_DIR | 981 | #if ENABLE_FEATURE_DIFF_DIR |
| 957 | diffdir(file, s_start); | 982 | diffdir(file, s_start); |
