]> git.donarmstrong.com Git - debbugs.git/blobdiff - migrate/debbugs-makeversions
assume unknown encodings are UTF-8
[debbugs.git] / migrate / debbugs-makeversions
index 67f3e152b8e9237925ff4e79c42fffb2acf76365..fd70f2dcfb6262a3f810effa1334555bc0a41fb1 100755 (executable)
@@ -3,6 +3,12 @@
 # guesswork, based on Version: pseudo-headers and closing mails that look
 # like Debian changelogs. The latter in particular is somewhat heuristic.
 
+# <@aj> Hackin' on the BTS, Feelin' like it'll take forever; Oh you better
+#       hold it's hand, when it dies on names so clever. These are the best
+#       bugs of our life. It's up to archive-slash-69, man we were killin'
+#       time, we were young and resltess, we needed to unwind. I guess
+#       nothin' can last forever - forever, no...
+
 my $config_path = '/etc/debbugs';
 my $lib_path = '/usr/lib/debbugs';
 
@@ -12,9 +18,9 @@ require "$lib_path/errorlib";
 use Debbugs::Log;
 use Debbugs::MIME;
 
-if (@ARGV != 2) {
+if (@ARGV != 1) {
     print <<EOF;
-Usage: $0 db-type versions-directory
+Usage: $0 db-type
 
 EOF
     exit 0;
@@ -75,7 +81,7 @@ sub getbuginfo ($)
                $fv =~ s/;.*//;
                $fv =~ s/ *\(.*\)//;
                # Strip off other random junk at the end of a version.
-               $fv =~ s/ *[A-Za-z].*//;
+               $fv =~ s/ +[A-Za-z].*//;
                $ver = $fv;
            }
        }
@@ -136,43 +142,54 @@ sub mergeinto ($$)
     }
 }
 
-my ($db, $verdb) = @ARGV[0, 1];
-opendir DB, "$gSpoolDir/$db" or die "Can't opendir $db: $!";
-unless (-d $verdb) {
-    mkdir $verdb or die "Can't mkdir $verdb: $!";
-}
+chdir $gSpoolDir or die "Can't chdir $gSpoolDir: $!";
+
+my $db = $ARGV[0];
+opendir DB, $db or die "Can't opendir $db: $!";
 
 while (defined(my $dir = readdir DB)) {
-    next if $dir =~ /^\.\.?$/ or not -d "$gSpoolDir/$db/$dir";
-    opendir HASH, "$gSpoolDir/$db/$dir"
-       or die "Can't opendir $gSpoolDir/$db/$dir: $!";
+    next if $dir =~ /^\.\.?$/ or not -d "$db/$dir";
+    opendir HASH, "$db/$dir" or die "Can't opendir $db/$dir: $!";
 
     while (defined(my $file = readdir HASH)) {
        next unless $file =~ /\.log$/;
-       next if -z "$gSpoolDir/$db/$dir/$file";
+       next if -z "$db/$dir/$file";
        (my $bug = $file) =~ s/\..*//;
 
        $bug =~ /(..)$/;
        my $bughash = $1;
-       # For incremental updates.
-       #next if -e "$verdb/$bughash/$bug.versions" and
-       #       (stat "$verdb/$bughash/$bug.versions")[9] >=
-       #           (stat "$gSpoolDir/$db/$dir/$file")[9];
 
        print "Processing $bug ...\n" if $ENV{DEBBUGS_VERBOSE};
 
-       my $status = readbug($bug, $db);
-       next unless defined $status;
+       my ($locks, $status) = lockreadbugmerge($bug, $db);
+       unless (defined $status) {
+           unlockreadbugmerge($locks);
+           next;
+       }
+
+       if (@{$status->{found_versions}} or @{$status->{fixed_versions}}) {
+           unlockreadbugmerge($locks);
+           next;
+       }
+
+       my @merges = ();
+       # Only process the lowest of each set of merged bugs.
+       if (length $status->{mergedwith}) {
+           @merges = sort { $a <=> $b } split ' ', $status->{mergedwith};
+           if ($merges[0] < $bug) {
+               unlockreadbugmerge($locks);
+               next;
+           }
+       }
 
-       my ($found_versions, $fixed_versions) =
-           getbuginfo("$gSpoolDir/$db/$dir/$file");
+       my ($found_versions, $fixed_versions) = getbuginfo("$db/$dir/$file");
 
        if (length $status->{mergedwith}) {
-           for my $merge (split ' ', $status->{mergedwith}) {
+           for my $merge (@merges) {
                $merge =~ /(..)$/;
                my $mergehash = $1;
                my ($mfound, $mfixed) =
-                   getbuginfo("$gSpoolDir/$db/$mergehash/$merge.log");
+                   getbuginfo("$db/$mergehash/$merge.log");
                mergeinto($found_versions, $mfound);
                mergeinto($fixed_versions, $mfixed);
            }
@@ -180,20 +197,20 @@ while (defined(my $dir = readdir DB)) {
 
        @$fixed_versions = () unless length $status->{done};
 
-       for my $out ($bug, (split ' ', $status->{mergedwith})) {
-           $out =~ /(..)$/;
-           my $outhash = $1;
-
-           unless (-d "$verdb/$outhash") {
-               mkdir "$verdb/$outhash" or die "Can't mkdir $verdb/$outhash: $!";
+       for my $out ($bug, @merges) {
+           if ($out != $bug) {
+               filelock("lock/$out");
+           }
+           my $outstatus = readbug($out, $db);
+           $outstatus->{found_versions} = [@$found_versions];
+           $outstatus->{fixed_versions} = [@$fixed_versions];
+           writebug($out, $outstatus, $db, 2, 'disable bughook');
+           if ($out != $bug) {
+               unfilelock();
            }
-
-           open VERSIONS, "> $verdb/$outhash/$out.versions"
-               or die "Can't open $verdb/$outhash/$out.versions: $!";
-           print VERSIONS "Found-in: @$found_versions\n";
-           print VERSIONS "Fixed-in: @$fixed_versions\n";
-           close VERSIONS;
        }
+
+       unlockreadbugmerge($locks);
     }
 
     closedir HASH;