bug-diffutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-diffutils] Re: diffutils-2.9 released [stable] - enhancements


From: Ehud Karni
Subject: [bug-diffutils] Re: diffutils-2.9 released [stable] - enhancements
Date: Tue, 16 Feb 2010 17:55:26 +0200

On Fri, 12 Feb 2010 21:58:47 Jim Meyering wrote:
>
> This is to announce diffutils-2.9.  I'm calling it stable
> because not much has changed, in spite of the long interval
> since the last release.

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;
  
  static char const shortopts[] =
! "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;
  
  static char const shortopts[] =
! "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 = 1;
+         break;
+
        case 'n':
          specify_style (OUTPUT_RCS);
          break;
***************
*** 514,519 ****
--- 520,521 ----
            }
          break;

+       case 'Z':
+         check_size_only = 1;
+         break;
+
        case BINARY_OPTION:
  #if O_BINARY
          binary = true;
***************
*** 712,717 ****
--- 722,722 ----
       : (output_style != OUTPUT_SDIFF) | suppress_common_lines);

    files_can_be_treated_as_binary =
+     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 difference."),
+   N_("-M  --check-modify-time  Consider different modify time as different."),
    "",
    N_("-c  -C NUM  --context[=NUM]  Output NUM (default 3) lines of copied 
context.\n\
  -u  -U NUM  --unified[=NUM]  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 == cmp->file[1].desc)
        changes = 0;

+       /* if different modify time - files differ */
+       else if (check_modify_time
+              && cmp->file[0].stat.st_mtime != cmp->file[1].stat.st_mtime)
+       changes = 1;
+
+      /* if check size only - already checked */
+       else if (check_size_only)
+       changes = 0;
+
        else
        /* Scan both files, a buffer at a time, looking for a difference.  */
        {
***************
*** 629,634 ****
--- 638,639 ----
        else
        changes = (script != 0);

+       /* if different modify time - files differ */
+       if (check_modify_time &&
+       cmp->file[0].stat.st_mtime != cmp->file[1].stat.st_mtime)
+       changes = 1;
+
        if (brief)
        changes = 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]