[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-diffutils] [PATCH] added 2 options to diff
From: |
Ehud Karni |
Subject: |
[bug-diffutils] [PATCH] added 2 options to diff |
Date: |
Tue, 7 Sep 2010 11:20:04 +0300 |
[ I already sent this to the group, but got no response ]
I added the following enhancements to diff:
1. Option to compare file by size only - it can save a lot of time
on directories with a lot of large files (e.g. movies).
This option is set with -Z (for siZe).
2. Define that files with different time stamp are different. This
option is especially useful when the 1st option (-Z) is used.
This option is set with -M (for Modification time).
I use these options for over 2 years now, and it is very useful
for comparing directories and directory trees.
The patch below (against the diffutils-2.9 sources) does this
and fix the help of diff (and the man page created by help2man),
but the help.info should be fixed too (which I don't know how do).
Ehud.
diff -c ~/diffutils-2.9/src/diff.h-org ~/diffutils-2.9/src/diff.h
*** ~/diffutils-2.9/src/diff.h-org Thu Feb 11 11:05:57 2010
--- ~/diffutils-2.9/src/diff.h Tue Feb 16 15:05:20 2010
***************
*** 138,143 ****
--- 138,139 ----
/* Say only whether files differ, not how (-q). */
XTERN bool brief;
+ /* Check by size only, do not compare files content */
+ XTERN bool check_size_only;
+
+ /* Report files as differ when their modify times are different */
+ XTERN bool check_modify_time;
+
/* Expand tabs in the output so the text lines up properly
despite the characters added to the front of each line (-t). */
XTERN bool expand_tabs;
diff -c ~/diffutils-2.9/src/diff.c-org ~/diffutils-2.9/src/diff.c
*** ~/diffutils-2.9/src/diff.c-org Thu Feb 11 11:39:17 2010
--- ~/diffutils-2.9/src/diff.c Tue Feb 16 15:01:19 2010
***************
*** 106,109 ****
static bool report_identical_files;
=0C
static char const shortopts[] =3D
! "0123456789abBcC:dD:eEfF:hHiI:lL:nNpPqrsS:tTuU:vwW:x:X:y";
/* Values for long options that do not have single-letter equivalents. =
*/
enum
--- 106,109 ----
static bool report_identical_files;
=0C
static char const shortopts[] =3D
! "0123456789abBcC:dD:eEfF:hHiI:lL:nMNpPqrsS:tTuU:vwW:x:X:yZ";
/* Values for long options that do not have single-letter equivalents. =
*/
enum
***************
*** 160,165 ****
--- 160,167 ----
{"binary", 0, 0, BINARY_OPTION},
{"brief", 0, 0, 'q'},
{"changed-group-format", 1, 0, CHANGED_GROUP_FORMAT_OPTION},
+ {"check-size-only", 0, 0, 'Z'},
+ {"check-modify-time", 0, 0, 'M'},
{"context", 2, 0, 'C'},
{"ed", 0, 0, 'e'},
{"exclude", 1, 0, 'x'},
***************
*** 431,436 ****
--- 433,434 ----
fatal ("too many file label options");
break;
+ case 'M':
+ check_modify_time =3D 1;
+ break;
+
case 'n':
specify_style (OUTPUT_RCS);
break;
***************
*** 514,519 ****
--- 520,521 ----
}
break;
+ case 'Z':
+ check_size_only =3D 1;
+ break;
+
case BINARY_OPTION:
#if O_BINARY
binary =3D true;
***************
*** 712,717 ****
--- 722,722 ----
: (output_style !=3D OUTPUT_SDIFF) | suppress_common_lines);
files_can_be_treated_as_binary =3D
+ check_size_only |
(brief & binary
& ~ (ignore_blank_lines | ignore_case | strip_trailing_cr
| (ignore_regexp_list.regexps || ignore_white_space)));
***************
*** 856,861 ****
--- 867,874 ----
N_("--binary Read and write data in binary mode."),
#endif
N_("-a --text Treat all files as text."),
+ N_("-Z --check-size-only Compare by size only, Ignore byte differe=
nce."),
+ N_("-M --check-modify-time Consider different modify time as differ=
ent."),
"",
N_("-c -C NUM --context[=3DNUM] Output NUM (default 3) lines of co=
pied context.\n\
-u -U NUM --unified[=3DNUM] Output NUM (default 3) lines of unified =
context.\n\
diff -c ~/diffutils-2.9/src/analyze.c-org ~/diffutils-2.9/src/analyze.c
*** ~/diffutils-2.9/src/analyze.c-org Thu Feb 11 11:05:57 2010
--- ~/diffutils-2.9/src/analyze.c Tue Feb 16 15:11:27 2010
***************
*** 490,495 ****
--- 490,491 ----
else if (cmp->file[0].desc =3D=3D cmp->file[1].desc)
changes =3D 0;
+ /* if different modify time - files differ */
+ else if (check_modify_time
+ && cmp->file[0].stat.st_mtime !=3D cmp->file[1].stat.st_mtime)
+ changes =3D 1;
+
+ /* if check size only - already checked */
+ else if (check_size_only)
+ changes =3D 0;
+
else
/* Scan both files, a buffer at a time, looking for a difference. */
{
***************
*** 629,634 ****
--- 638,639 ----
else
changes =3D (script !=3D 0);
+ /* if different modify time - files differ */
+ if (check_modify_time &&
+ cmp->file[0].stat.st_mtime !=3D cmp->file[1].stat.st_mtime)
+ changes =3D 1;
+
if (brief)
changes =3D briefly_report (changes, cmp->file);
else
--
Ehud Karni Tel: +972-3-7966-561 /"\
Mivtach - Simon Fax: +972-3-7976-561 \ / ASCII Ribbon Campaign
Insurance agencies (USA) voice mail and X Against HTML Mail
http://www.mvs.co.il FAX: 1-815-5509341 / \
GnuPG: 98EA398D <http://www.keyserver.net/> Better Safe Than Sorry
- [bug-diffutils] [PATCH] added 2 options to diff,
Ehud Karni <=