+
+ my $lastpath = my $lastcasepath = my $lastfile = "";
+ my %matches = ();
+ while (<MERGED>) {
+ print "Doing line ".($NR/1000000)."M (out of approx. 20M)\n"
+ if $NR % 1000000 == 0;
+ chomp;
+ my @line = split m/\0/o, $_;
+ my $revpath = shift @line;
+ my $casepath = shift @line;
+ if ($revpath ne $lastpath) {
+ # Wrap: Do useful stuff with this ($lastpath, @matches)
+ if ($lastpath ne "") {
+ my @matches;
+ while (my ($k, $v) = each %matches) {
+ push @matches, join("\0", $k, @$v);
+ }
+ $reverse_path_db{$lastpath} = join "\1", @matches;
+ %matches = ();
+ }
+ $lastpath =~ s,/.*,,o;
+ if ($lastfile ne $lastpath) {
+ $lastfile = $lastpath;
+ print FILENAMES (reverse $lastfile)."\n";
+ }
+ #
+ $lastpath = $revpath;
+ $lastcasepath = $casepath;
+ $matches{$casepath} = \@line;
+ next;
+# } elsif ($lastcasepath ne "" and $casepath ne $lastcasepath) {
+# warn reverse($revpath)." has more than one casepath: $casepath $lastcasepath\n";
+ }
+ push @{$matches{$casepath}}, @line;
+ }
+ # Note: do useful stuff here too, for out last entry. Maybe prevent this by
+ # adding a fake ultimate entry?
+ {
+ my @matches;
+ while (my ($k, $v) = each %matches) {
+ push @matches, join("\0", $k, @$v);
+ }
+ $reverse_path_db{$lastpath} = join "\1", @matches;
+ }
+
+ untie %reverse_path_db;
+ close FILENAMES;
+ close MERGED;
+
+ activate("$DBDIR/filenames_$suite.txt");
+ activate("$DBDIR/reverse_$suite.db");