If two files to be compared share the same inode, it should
be reasonable to consider them identical.
This gives a substantial speedup when comparing directory
structures with many hardlinked files, e.g. when using
rsnapshot for incremental backup.
Comments? OK?
/Alexander
Index: diffreg.c
===================================================================
RCS file: /cvs/src/usr.bin/diff/diffreg.c,v
retrieving revision 1.93
diff -u -p -r1.93 diffreg.c
--- diffreg.c 28 Jun 2019 13:35:00 -0000 1.93
+++ diffreg.c 31 Aug 2021 23:07:51 -0000
@@ -429,6 +429,10 @@ files_differ(FILE *f1, FILE *f2, int fla
if ((flags & (D_EMPTY1|D_EMPTY2)) || stb1.st_size != stb2.st_size ||
(stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT))
return (1);
+
+ if (stb1.st_dev == stb2.st_dev && stb1.st_ino == stb2.st_ino)
+ return (0);
+
for (;;) {
i = fread(buf1, 1, sizeof(buf1), f1);
j = fread(buf2, 1, sizeof(buf2), f2);