]> git.donarmstrong.com Git - debbugs.git/blobdiff - bin/debbugs-loadsql
use get_src_pkg_id when loading versions
[debbugs.git] / bin / debbugs-loadsql
index b5d91187739a5489904ae1878a2e4c510dd13dd2..302d3d649f8d0880be1d5af7091d00af14c8b0b7 100755 (executable)
@@ -132,7 +132,7 @@ Display this manual.
 use vars qw($DEBUG);
 
 use Debbugs::Common (qw(checkpid lockpid get_hashname getparsedaddrs getbugcomponent make_list getsourcemaintainers),
-                    qw(hash_slice));
+                    qw(hash_slice open_compressed_file),);
 use Debbugs::Config qw(:config);
 use Debbugs::Status qw(read_bug split_status_fields);
 use Debbugs::Log;
@@ -299,7 +299,7 @@ sub add_bugs {
                       next;
                    }
                    my $rs = $s->resultset('Bug')->search({id=>$bug})->single();
-                   next if defined $rs and $stat->mtime < $rs->last_modified()->epoch();
+                   next if defined $rs and $stat->mtime <= $rs->last_modified()->epoch();
                    push @bugs_to_update, $bug;
                   }
                } else {
@@ -307,7 +307,7 @@ sub add_bugs {
                }
                eval {
                  $s->txn_do(sub {
-                              for my $bug (@bugs) {
+                              for my $bug (@bugs_to_update) {
                                 load_bug(db => $s,
                                          bug => $bug,
                                          tags => \%tags,
@@ -351,19 +351,20 @@ sub add_versions {
             my $sp;
             if (not defined $src_pkgs{$versions[$i][0]}) {
                 $src_pkgs{$versions[$i][0]} =
-                    $s->resultset('SrcPkg')->find_or_create({pkg => $versions[$i][0]});
+                    $s->resultset('SrcPkg')->
+                   get_src_pkg_id($versions[$i][0]);
             }
             $sp = $src_pkgs{$versions[$i][0]};
             # There's probably something wrong if the source package
             # doesn't exist, but we'll skip it for now
             next unless defined $sp;
-            my $sv = $s->resultset('SrcVer')->find({src_pkg=>$sp->id(),
+            my $sv = $s->resultset('SrcVer')->find({src_pkg=>$sp,
                                                     ver => $versions[$i][1],
                                                    });
             if (defined $ancestor_sv and defined $sv and not defined $sv->based_on()) {
-                $sv->update({based_on => $ancestor_sv->id()})
+                $sv->update({based_on => $ancestor_sv})
             }
-            $ancestor_sv = $sv;
+            $ancestor_sv = $sv->id();
         }
         $p->update() if $p;
     }
@@ -376,63 +377,54 @@ sub add_debinfo {
     my @files = @{$argv};
     if (not @files) {
        {
-           if ($opts->{0}) {
-               local $/ = "\0";
-           }
+          local $/ = "\n";
+           local $/ = "\0" if $opts->{0};
            while (<STDIN>) {
+              s/\n$// unless $opts->{0};
+              s/\0$// if $opts->{0};
                push @files, $_;
            }
        }
     }
     return unless @files;
     my $s = db_connect($options);
-    my %arch;
     $p->target(scalar @files) if $p;
-    for my $file (@files) {
-        my $fh = IO::File->new($file,'r') or
-            die "Unable to open $file for reading: $!";
-        my $f_stat = stat($file);
-        while (<$fh>) {
-            chomp;
-            next unless length $_;
-            my ($binname, $binver, $binarch, $srcname, $srcver) = split;
-            # if $srcver is not defined, this is probably a broken
-            # .debinfo file [they were causing #686106, see commit
-            # 49c85ab8 in dak.] Basically, $binarch didn't get put into
-            # the file, so we'll fudge it from the filename.
-            if (not defined $srcver) {
-                ($srcname,$srcver) = ($binarch,$srcname);
-                ($binarch) = $file =~ /_([^\.]+)\.debinfo/;
-            }
-            my $sp = $s->resultset('SrcPkg')->find_or_create({pkg => $srcname});
-            # update the creation date if the data we have is earlier
-            my $ct_date = DateTime->from_epoch(epoch => $f_stat->ctime);
-            if ($ct_date < $sp->creation) {
-                $sp->creation($ct_date);
-                $sp->last_modified(DateTime->now);
-                $sp->update;
-            }
-            my $sv = $s->resultset('SrcVer')->find_or_create({src_pkg =>$sp->id(),
-                                                              ver => $srcver});
-            if (not defined $sv->upload_date() or $ct_date < $sv->upload_date()) {
-                $sv->upload_date($ct_date);
-                $sv->update;
-            }
-            my $arch;
-            if (defined $arch{$binarch}) {
-                $arch = $arch{$binarch};
-            } else {
-                $arch = $s->resultset('Arch')->find_or_create({arch => $binarch});
-                $arch{$binarch} = $arch;
-            }
-            my $bp = $s->resultset('BinPkg')->find_or_create({pkg => $binname});
-            $s->resultset('BinVer')->find_or_create({bin_pkg => $bp->id(),
-                                                     src_ver => $sv->id(),
-                                                     arch    => $arch->id(),
-                                                     ver        => $binver,
-                                                    });
-        }
-        $p->update() if $p;
+    my $it = natatime 100, @files;
+    while (my @v = $it->()) {
+       my %cache;
+       my @debinfos;
+       for my $file (@v) {
+           my $fh = IO::File->new($file,'r') or
+               die "Unable to open $file for reading: $!";
+           my $f_stat = stat($file);
+           my $ct_date = DateTime->from_epoch(epoch => $f_stat->ctime);
+           while (<$fh>) {
+               chomp;
+               next unless length $_;
+               my ($binname, $binver, $binarch, $srcname, $srcver) = split;
+               # if $srcver is not defined, this is probably a broken
+               # .debinfo file [they were causing #686106, see commit
+               # 49c85ab8 in dak.] Basically, $binarch didn't get put into
+               # the file, so we'll fudge it from the filename.
+               if (not defined $srcver) {
+                   ($srcname,$srcver) = ($binarch,$srcname);
+                   ($binarch) = $file =~ /_([^\.]+)\.debinfo/;
+               }
+               if (not defined $srcver) {
+                   print STDERR "malformed debinfo (no srcver): $file\n";
+                   next;
+               }
+               push @debinfos,
+                   [$binname,$binver,$binarch,$srcname,$srcver,$ct_date];
+           }
+       }
+       $s->txn_do(
+           sub {
+               for my $di (@debinfos) {
+                   Debbugs::DB::Load::load_debinfo($s,@{$di}[0..5],\%cache);
+               }
+           });
+       $p->update($p->last_update()+@v) if $p;
     }
     $p->remove() if $p;
 }
@@ -569,7 +561,7 @@ sub add_logs {
                   }
                   if ($options{quick}) {
                       my $rs = $s->resultset('Bug')->search({bug=>$bug})->single();
-                      next if defined $rs and $stat->mtime < $rs->last_modified()->epoch();
+                      next if defined $rs and $stat->mtime <= $rs->last_modified()->epoch();
                   }
                   eval {
                       load_bug_log(db => $s,
@@ -692,27 +684,6 @@ sub db_connect {
         die "Unable to connect to database: ";
 }
 
-sub open_compressed_file {
-    my ($file) = @_;
-    my $fh;
-    my $mode = '<:encoding(UTF-8)';
-    my @opts;
-    if ($file =~ /\.gz$/) {
-       $mode = '-|:encoding(UTF-8)';
-       push @opts,'gzip','-dc';
-    }
-    if ($file =~ /\.xz$/) {
-       $mode = '-|:encoding(UTF-8)';
-       push @opts,'xz','-dc';
-    }
-    if ($file =~ /\.bz2$/) {
-       $mode = '-|:encoding(UTF-8)';
-       push @opts,'bzip2','-dc';
-    }
-    open($fh,$mode,@opts,$file);
-    return $fh;
-}
-
 sub read_release_file {
     my ($file) = @_;
     # parse release