X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=faster-dupemerge;h=6223ab0adc2d7cacb4dee7e7c4f4e71a2aa3a1d4;hb=95742bfa9d5a1f33ce77689f0b2fb93bdf888e85;hp=82483a22999bc9f71e999f7b37998470bd77edd3;hpb=c95c3458bb3128236b12b7f5a952089ab1667501;p=dupemerge diff --git a/faster-dupemerge b/faster-dupemerge index 82483a2..6223ab0 100755 --- a/faster-dupemerge +++ b/faster-dupemerge @@ -238,7 +238,7 @@ my @find_command = ('find', @directories, @extra_find_opts, '-type', 'f'); my $printf_string = '%s ' . ($collapse_access ? '0 0 0 ' : '%U %G %m ') . ($collapse_timestamp ? '0 ' : '%T@ ') . - '%i %p\0'; + '%D:%i %p\0'; push(@find_command, '!', '-empty') unless $collapse_zero; push(@find_command, '-printf', $printf_string); @@ -305,14 +305,14 @@ sub merge_files { } print STDERR "Merging...\n" if $debug; - foreach my $candidate (@candidate_list) { + foreach my $candidate (sort @candidate_list) { print STDERR "\tDigesting candidate $candidate\n" if $debug; my $ok = 0; my $digest; hash_file: - foreach my $filename (keys(%{$inode_to_file_name{$candidate}})) { + foreach my $filename (sort keys(%{$inode_to_file_name{$candidate}})) { print STDERR "\t\tDigesting file $filename\n" if $debug; if ((-l $filename) || ! -f _) { warn "Bogon file " . tick_quote($filename); @@ -342,8 +342,8 @@ hash_file: link_start: until ($finished) { - my @incumbent_names = keys(%{$inode_to_file_name{$incumbent}}); - my @candidate_names = keys(%{$inode_to_file_name{$candidate}}); + my @incumbent_names = sort keys(%{$inode_to_file_name{$incumbent}}); + my @candidate_names = sort 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 $candidate:", join("\n\t\t\t", '', @candidate_names), "\n" if $debug; @@ -441,6 +441,12 @@ candidate_file: my $link_done = 0; my ($from_file, $to_file, $from_inode, $to_inode, $from_nlink, $to_nlink); + + # If the candidate has more links than incumbent, replace incumbent with candidate. + # If the incumbent has more links than candidate, replace candidate with incumbent. + # If the link counts are equal, we saw incumbent first, so keep the incumbent. + # "We saw incumbent first" is significant because we explicitly sort the inodes. + # Thank Johannes Niess for this idea. if ($candidate_nlink > $incumbent_nlink) { $from_file = $candidate_file; $to_file = $incumbent_file; @@ -538,7 +544,7 @@ end_merge: } while () { - my ($weak_key, $inode, $name) = m/^(\d+ \d+ \d+ \d+ -?\d+) (\d+) (.+)\0$/so; + my ($weak_key, $inode, $name) = m/^(\d+ \d+ \d+ \d+ -?\d+) (\d+:\d+) (.+)\0$/so; die "read error: $!\nLast input line was '$_'" unless defined($name); print STDERR "weak_key=$weak_key inode=$inode name=$name\n" if $debug;