Allow --skip-hash and --skip-compare to be specified together
authorZygo Blaxell <zblaxell@waya.furryterror.org>
Sat, 9 Jan 2010 04:09:27 +0000 (23:09 -0500)
committerZygo Blaxell <zblaxell@waya.furryterror.org>
Sat, 9 Jan 2010 04:09:27 +0000 (23:09 -0500)
Since --skip-hash is now a threshold parameter which applies to some
files and not others, it makes sense to allow --skip-compare to be
specified at the same time.

--skip-compare is respected for files smaller than the --skip-hash
threshold, since such files will always be hashed.  --skip-compare is
ignored for files larger than or equal to the --skip-hash threshold
since such files will never be hashed.

faster-dupemerge

index 14360dc8c802d83c89132fe5780b7070fd0896f0..bc3a5afcbc180802af38153d471144ab5e31e6f4 100755 (executable)
@@ -86,6 +86,7 @@ my $collapse_access = 0;
 my $collapse_timestamp = 0;
 my $collapse_zero = 0;
 my $skip_compares = 0;
+my $skip_compare_preference = 0;
 my $skip_hashes = 0;
 my $skip_hashes_threshold = 0;
 my $progress = 0;
@@ -184,7 +185,7 @@ while ($#ARGV >= 0) {
        } elsif ($arg eq '--zeros') {
                $collapse_zero = 1;
        } elsif ($arg eq '--trust' || $arg eq '--skip-compare') {
-               $skip_compares = 1;
+               $skip_compare_preference = 1;
        } elsif ($arg =~ /^--skip-hash(?:=(\d+)([KkMmGgTt]?))?$/os) {
                my ($quantity, $unit) = ($1, $2);
                $unit ||= '_';
@@ -200,7 +201,8 @@ while ($#ARGV >= 0) {
                        t => 1000*1000*1000*1000,
                        T => 1024*1024*1024*1024,
                );
-               $skip_hashes = $skip_hashes_threshold = $quantity * $scale{$unit};
+               $skip_hashes = 0;
+               $skip_hashes_threshold = $quantity * $scale{$unit};
        } elsif ($arg eq '--progress') {
                $progress = 1;
        } elsif ($arg eq '--verbose') {
@@ -239,10 +241,6 @@ while ($#ARGV >= 0) {
        }
 }
 
-if ($skip_hashes && $skip_compares) {
-       die "Cannot skip both hashes and compares.\n";
-}
-
 @directories or usage;
 
 if (defined($lock_file) && !$dry_run) {
@@ -597,7 +595,13 @@ while (<FIND>) {
 
        print STDERR "weak_key=$weak_key inode=$inode name=$name\n" if $debug;
 
-       $skip_hashes = $size >= $skip_hashes_threshold;
+       if ($size >= $skip_hashes_threshold) {
+               $skip_hashes = 1;
+               $skip_compares = 0;
+       } else {
+               $skip_hashes = 0;
+               $skip_compares = $skip_compare_preference;
+       }
 
        $input_links++;
        merge_files if $weak_key ne $current_key;