Properly handle cases where multiple files have the same hash
authorroot <root@f049ffa3-53c0-42dd-8896-c8778eaba0c5>
Sun, 26 Nov 2006 22:05:51 +0000 (22:05 +0000)
committerZygo Blaxell <zblaxell@waya.furryterror.org>
Sat, 9 Jan 2010 02:21:21 +0000 (21:21 -0500)
(e.g. because --skip-hash is used).  This version now generates all N^2
combinations of comparisons.

git-svn-id: svn+ssh://svn.furryterror.org/r/trunk/mokona/zblaxell@6218 a5e33b96-951a-0410-ae88-c0fe16d076bb

git-svn-id: file:///root/SVN@4 f049ffa3-53c0-42dd-8896-c8778eaba0c5

git-svn-id: file:///root/SVN@10 f049ffa3-53c0-42dd-8896-c8778eaba0c5

faster-dupemerge

index 82483a22999bc9f71e999f7b37998470bd77edd3..ae9102c9e457ccc189bbca5baa9e19510d04e8c2 100755 (executable)
@@ -333,8 +333,9 @@ hash_file:
                if ($ok) {
                        print STDERR "\t\tDigest is $digest\n" if $debug;
 
-                       my $incumbent = $hash_to_inode{$digest};
-                       if (defined($incumbent)) {
+                       my $incumbent_list = ($hash_to_inode{$digest} ||= []);
+                       my $incumbent_matched = 0;
+                       for my $incumbent (@$incumbent_list) {
                                print STDERR "\t\tInodes $incumbent and $candidate have same hash\n" if $debug;
 
                                my $finished = 0;
@@ -344,7 +345,7 @@ link_start:
                                until ($finished) {
                                        my @incumbent_names = keys(%{$inode_to_file_name{$incumbent}});
                                        my @candidate_names = keys(%{$inode_to_file_name{$candidate}});
-                                       print STDERR "\t\tLinks to $incumbent:",   join("\n\t\t\t", '', @incumbent_names),   "\n" if $debug;
+                                       print STDERR "\t\tLinks to $incumbent:", join("\n\t\t\t", '', @incumbent_names), "\n" if $debug;
                                        print STDERR "\t\tLinks to $candidate:", join("\n\t\t\t", '', @candidate_names), "\n" if $debug;
 
 incumbent_file:
@@ -411,6 +412,7 @@ candidate_file:
                                                                                print STDERR "$quoted_incumbent_file and $quoted_candidate_file have same hash but do not compare equal!\n" unless $skip_hashes;
                                                                        } else {
                                                                                $identical = 1;
+                                                                               $incumbent_matched = 1;
                                                                        }
                                                                        $compare_count++;
                                                                        $compare_bytes += $incumbent_size;
@@ -487,13 +489,9 @@ candidate_file:
                                                                        # My random number generator chooses the incumbent's size.
 
                                                                        if ($link_done) {
-                                                                               # Since we're in a dry run, the filesystem doesn't change.
-                                                                               # Our notion of what the filesystem should look like should not change either.
                                                                                delete $inode_to_file_name{$to_inode}->{$to_file};
-                                                                               unless ($dry_run) {
-                                                                                       $inode_to_file_name{$from_inode}->{$to_file} = undef;
-                                                                                       $hash_to_inode{$digest} = $from_inode;
-                                                                               }
+                                                                               $inode_to_file_name{$from_inode}->{$to_file} = undef;
+                                                                               $hash_to_inode{$digest} = [ $from_inode ];
 
                                                                                $hard_links++;
                                                                                if ($to_nlink == 1) {
@@ -521,9 +519,10 @@ candidate_file:
                                        }
                                        $finished = 1;
                                }
-                       } else {
+                       }
+                       unless ($incumbent_matched) {
                                print STDERR "\t\tNew hash entered\n" if $debug;
-                               $hash_to_inode{$digest} = $candidate;
+                               push(@$incumbent_list, $candidate);
                        }
                } else {
                        warn "No digests found for inode $candidate\n";