[Collab-qa-commits] r511 - in svnbuildstat/trunk: lib/SvnBuildStat lib/SvnBuildStat/Common script

goneri-guest at alioth.debian.org goneri-guest at alioth.debian.org
Sun Nov 18 23:13:05 UTC 2007


Author: goneri-guest
Date: 2007-11-18 23:13:04 +0000 (Sun, 18 Nov 2007)
New Revision: 511

Added:
   svnbuildstat/trunk/lib/SvnBuildStat/Vcs.pm
Removed:
   svnbuildstat/trunk/lib/SvnBuildStat/Common/Svn.pm
Modified:
   svnbuildstat/trunk/lib/SvnBuildStat/Common.pm
   svnbuildstat/trunk/script/svnbuildstat_update-db-git.pl
   svnbuildstat/trunk/script/svnbuildstat_update-db-svn.pl
   svnbuildstat/trunk/script/svnbuildstat_update-repository.pl
Log:
add an abstraction layer for the vcs access.
Merge script/svnbuildstat_update-db-svn.pl and script/svnbuildstat_update-db-git.pl
the db and repository update seem to be ok with git \o/


Deleted: svnbuildstat/trunk/lib/SvnBuildStat/Common/Svn.pm
===================================================================
--- svnbuildstat/trunk/lib/SvnBuildStat/Common/Svn.pm	2007-11-15 07:26:20 UTC (rev 510)
+++ svnbuildstat/trunk/lib/SvnBuildStat/Common/Svn.pm	2007-11-18 23:13:04 UTC (rev 511)
@@ -1,21 +0,0 @@
-package SvnBuildStat::Common::Svn;
-
-use strict;
-use warnings;
-
-require Exporter;
-
-our @ISA = "Exporter";
-our @EXPORT_OK = qw(getRev);
-
-sub getRev {
-  my $uri = shift;
-
-  foreach (`LC_ALL=C svn info $uri`) {
-    return $1 if /Last Changed Rev:\ (\d+)/;
-  }
-
-  return;
-}
-
-1;

Modified: svnbuildstat/trunk/lib/SvnBuildStat/Common.pm
===================================================================
--- svnbuildstat/trunk/lib/SvnBuildStat/Common.pm	2007-11-15 07:26:20 UTC (rev 510)
+++ svnbuildstat/trunk/lib/SvnBuildStat/Common.pm	2007-11-18 23:13:04 UTC (rev 511)
@@ -6,7 +6,7 @@
 require Exporter;
 
 our @ISA = "Exporter";
-our @EXPORT_OK = qw(mkTarballFromPackage testUrl mkRootdirectoryFromPackage getDataFromDebianFtp parseControl);
+our @EXPORT = qw(mkTarballFromPackage testUrl mkRootdirectoryFromPackage getDataFromDebianFtp parseControl parseChangelog);
 
 sub mkTarballFromPackage {
   my $package = shift;
@@ -50,15 +50,16 @@
   my $svndebrelease = $$package->svndebrelease; 
   $svndebrelease =~ s/^\d+://; # remove the EPOCH
 
-  my $isindebian = 'f';
-  my $tarballuri;
-  my $isnative = 'f';
+  my $ret = {};
+  $ret->{isindebian} = 'f';
+  $ret->{isnative} = 'f';
+  $ret->{tarballuri} = '';
 
   my $ua = LWP::UserAgent->new;
   $ua->agent("SvnBuildStat/0.1 ");
 
   if ($$package->svndebrelease !~ /-[\d+\.]+$/) {
-    $isnative = 't';
+    $ret->{isnative} = 't';
   } else {
     my $debmirror = 'http://ftp.debian.org/debian';
     my $debdiff .= $$package->name."_".$svndebrelease.".diff.gz";
@@ -70,24 +71,24 @@
 	my $debdiffuri = $debmirror.'/pool/'.$section.'/'.$tmp.'/'.$debdiff;
 	my $tmp_tarballuri = $debmirror.'/pool/'.$section.'/'.$tmp.'/'.$tarball;
 	if (testUrl($debdiffuri)) {
-	  $isindebian = 't';
+	  $ret->{isindebian} = 't';
 	}
 	if (testUrl($tmp_tarballuri)) {
-	  $tarballuri = $tmp_tarballuri;
-	  $tarballuri =~ s/^$debmirror/\@DEBMIRROR@/;
+	  $tmp_tarballuri =~ s/^$debmirror/\@DEBMIRROR@/;
+	  $ret->{tarballuri} = $tmp_tarballuri;
 	}
       }
     }
   }
-  return { tarballuri => $tarballuri, isindebian => $isindebian, isnative => $isnative };
+  $ret;
 }
 
 sub parseControl {
-  my @control = @_;
+  my $control = shift;
 
   my $ret = { maintainers => []};
   
-  foreach (@control) {
+  foreach (@$control) {
     $ret->{packagesrc} = $1 if /^Source:\ *(.*)/;
     if (/^(Maintainer|Uploaders):\ *(.*)/) {
       my $tmp = $2;
@@ -115,4 +116,45 @@
   $ret;
 }
 
+sub parseChangelog {
+  my $changelog = shift;
+
+  my $ret;
+
+  return unless (@$changelog);
+  if ($changelog->[0] =~ /^.*\ \((.*)\)/) {
+    $ret->{realsvndebrelease} = $1;
+  }
+
+  foreach (@$changelog) {
+    if (/^\S/ && $ret->{currentchangelogentry}) {
+      # I ignore svn-bp empty template entry
+      if ($ret->{currentchangelogentry} =~ /^.*\n\s\s\*\sNOT RELEASED YET\n\n\s--.*/m) {
+	$ret->{currentchangelogentry} = '';
+      } else {
+	last; 
+      }
+    }
+    $ret->{currentchangelogentry} .= $_;
+  }
+
+  if ($ret->{currentchangelogentry} =~ /^.*\ \((.*)\)/) {
+    $ret->{svndebrelease} = $1; 
+  }
+  # looks for bug closed in the changelog entry
+  # the regex come from the BTS documentation
+  # TODO dpkg-parsechangelog is probably more suitable for the job :D
+  # TODO do not store the bugs inline
+  foreach ($ret->{currentchangelogentry} =~ /closes:\s*(?:bug)?\#\s*\d+(?:,\s*(?:bug)?\#\s*\d+)*/ig) {
+    s/([A-Za-z]|#|:|\s)//g;
+    $ret->{currentpendingbug} .= $_.',' if $_;
+  }
+
+  return $ret;
+}
+
+
+
+
+
 1;

Added: svnbuildstat/trunk/lib/SvnBuildStat/Vcs.pm
===================================================================
--- svnbuildstat/trunk/lib/SvnBuildStat/Vcs.pm	                        (rev 0)
+++ svnbuildstat/trunk/lib/SvnBuildStat/Vcs.pm	2007-11-18 23:13:04 UTC (rev 511)
@@ -0,0 +1,28 @@
+package SvnBuildStat::Vcs;
+
+use Logger::Syslog;
+use SvnBuildStat::Vcs::Git;
+use SvnBuildStat::Vcs::Svn;
+
+sub new {
+    my (undef, $vcs, $uri) = @_;
+
+    return unless $vcs;
+    return unless $uri;
+
+    # TODO rewrite this in a more dynamic way
+    my $return;
+    if ($vcs eq "git") {
+       $ret = new SvnBuildStat::Vcs::Git($uri);
+    } elsif ($vcs eq "svn") {
+       $ret = new SvnBuildStat::Vcs::Svn($uri);
+    } else {
+       debug ("unknow vcs type: $vcs");
+    }
+
+    return $ret;
+
+}
+
+
+1;

Modified: svnbuildstat/trunk/script/svnbuildstat_update-db-git.pl
===================================================================
--- svnbuildstat/trunk/script/svnbuildstat_update-db-git.pl	2007-11-15 07:26:20 UTC (rev 510)
+++ svnbuildstat/trunk/script/svnbuildstat_update-db-git.pl	2007-11-18 23:13:04 UTC (rev 511)
@@ -11,8 +11,10 @@
 use lib '/home/sites/svnbuildstat.debian.net/svnbuildstat/lib';
 use SvnBuildStat::Schema;
 use SvnBuildStat::Config;
+use SvnBuildStat::Common;
 use Logger::Syslog;
 #use SvnBuildStat::Common::Svn;
+use SvnBuildStat::Vcs::Git;
 
 my $config;
 my $schema;
@@ -36,36 +38,26 @@
 
 
   my $tarballonrepository;
+  my $reporoot;
   print "Repository: ".$$repository->name."\n";
-  if (!$$repository->uri =~ /ssh:\/\/([\w\.-]+)(\/.+)$/) {
-    info ("can't parse ".$$repository->name." uri");
-    return;
-  }
-#  my $repohost = $1; harcoded for the moment
-  my $reporoot = $2;
+  my $git = new SvnBuildStat::Vcs::Git($$repository->uri);
 
-  my $lastchange = `ssh goneri-guest\@alioth.debian.org GIT_DIR=$reporoot git log --pretty=oneline -n1`;
-  if (!$lastchange || $lastchange =~ /^(\w+)/) {
-    info ("can't git log for ".$$repository->uri);
-    return;
-  }
-  my $rev = $1;
+  my $rev = $git->getCurrentRev();
 
   if ($$repository->vcsrev eq $rev && $$repository->lastcheck) { 
-    debug ("no need to refresh");
+    debug ("no need to refresh this repository");
     return;
   }
 
-  GIT_DIR=/srv/git.debian.org/git/kernel/klibc-old.git/ git show HEAD:debian/changelog
-  foreach my $uri (@uri) {
-    # look for packages
-    $poolImportPkg->add($repository,$uri,$tarballonrepository) or die "Fucked\n";
-  }
+#  GIT_DIR=/srv/git.debian.org/git/kernel/klibc-old.git/ git show HEAD:debian/changelog
+  my $changelog = SvnBuildStat::Common::parseChangelog($git->getChangelog());
+  
+use Data::Dumper;
+print Dumper($changelog);
+#  $$repository->vcsrev($rev);
+#  $$repository->lastcheck('now');
+#  $$repository->update();
 
-  $$repository->vcsrev($rev);
-  $$repository->lastcheck('now');
-  $$repository->update();
-
   print "end import Repo\n";
 }
 
@@ -79,24 +71,22 @@
 ###################################################
 
 info ("starting");
-########## THREAD POOLS #####
-$poolImportPkg = Thread::Pool::Simple->new(
-   min => 5,
-   max => 5,
-   load => 3,
-   do => [\&importPkg],
-   lifespan => 1
- );
 
-########
+$config = new SvnBuildStat::Config();
+$schema = SvnBuildStat::Schema->connect(
+  $config->db_dsn,
+  $config->db_user,
+  $config->db_password,
+  {AutoCommit => 1, debug => 1}
+);
 
+
 # Import packages
 my $repository_rs = $schema->resultset('Repository')->search({enabled => 'true'});
 while (my $repository = $repository_rs->next) {
   next unless $repository->vcs_id && $repository->vcs_id->name eq "git";
   importRepository(\$repository) or warn "importRepository failed for ".$repository->name."\n";
 }
-$poolImportPkg->join;
 
 # Purge the removed packages
 # This semems to be fucked?

Modified: svnbuildstat/trunk/script/svnbuildstat_update-db-svn.pl
===================================================================
--- svnbuildstat/trunk/script/svnbuildstat_update-db-svn.pl	2007-11-15 07:26:20 UTC (rev 510)
+++ svnbuildstat/trunk/script/svnbuildstat_update-db-svn.pl	2007-11-18 23:13:04 UTC (rev 511)
@@ -13,7 +13,7 @@
 use SvnBuildStat::Config;
 use Logger::Syslog;
 use SvnBuildStat::Common;
-use SvnBuildStat::Common::Svn;
+use SvnBuildStat::Vcs;
 
 my $config;
 my $schema;
@@ -35,19 +35,14 @@
 
 
 sub getUscanData {
-  my $package = shift;
+  my ($package, $watchfile) = shift;
   my $cmd;
 
+  return unless $watchfile;
   return unless $$package->svndebrelease;
-  return unless $$package->vcsuri;
 
-  $cmd = "svn cat ".$$package->vcsuri."/debian/watch";
-  my $watch = `$cmd`;
-
-  return unless $watch;
-
-  my ($fh, $watchfile) = tempfile(SUFFIX => '.uscan');
-  print $fh $watch;
+  my ($fh, $tmpfile) = tempfile(SUFFIX => '.uscan');
+  print $fh @$watchfile;
   close ($fh);
 
   my $majorrelease = $$package->svndebrelease;
@@ -55,10 +50,10 @@
   $majorrelease =~ s/-[0-9A-Za-z\.~]*$//;
   $majorrelease =~ s/dfsg.*//;
   $majorrelease =~ s/\d+://;
-  $cmd = "uscan --package ".$$package->name." --dehs --upstream-version ".$majorrelease." --watchfile ".$watchfile;
+  $cmd = "uscan --package ".$$package->name." --dehs --upstream-version ".$majorrelease." --watchfile ".$tmpfile;
 #  print $cmd."\n";
   my @uscan = `$cmd`;
-  unlink $watchfile or warn;
+  unlink $tmpfile or warn;
   return unless @uscan > 2; # empty output
 
   my $tarballuri;
@@ -78,56 +73,35 @@
   return {tarballuri => $tarballuri, isuptodate => $isuptodate, upstreamrelease => $upstreamrelease, iswatchfilebroken => $iswatchfilebroken};
 }
 
-sub updateChangelog {
-  my $package = shift;
+sub updateVcsChanges {
+  my ($package, $vcschanges) = @_;
 
-  print "UPDATE CHANGELOG\n";
-
-  my $last_rev;
-  my $vcschangelog_rs = $schema->resultset('Vcschangelog')->search({
-      package_id => $$package->id,
-    }, {order_by => "rev DESC"});
-  $last_rev = $vcschangelog_rs->first->rev if ($vcschangelog_rs->first);
-  if (!$last_rev) {
-    my $build_rs = $schema->resultset('Build')->search({
+  my @added_entry_id;
+  foreach (@$vcschanges) {
+    # TODO Git users put there email address in there login. With it we can link the vcs user
+    # to the package maintainer
+    use Data::Dumper;
+    print Dumper($_);
+    my $userlogin = $schema->resultset('Userlogin')->find_or_create({name=>$_->{login}});
+    my $entry = $schema->resultset('Changelogentry')->create({
+	userlogin_id =>$userlogin->id,
 	package_id => $$package->id,
-      }, {order_by => "rev"});
-    $last_rev = $build_rs->first->rev if ($build_rs->first);
+	date => $_->{date},
+	rev => $_->{rev},
+      });
+    $entry->log($_->{text});
+    $entry->update;
+    push @added_entry_id, $entry->id;
   }
 
-  $last_rev = $$package->vcsrev unless $last_rev;
-
-  my $cmd = "LC_ALL=C svn log -r ".$last_rev.":".$$package->vcsrev." ".$$package->vcsuri;
-  my $begin;
-  my $entry;
-  foreach (`$cmd`) {
-    print $_;
-    if (/^------------------------------------------------------------------------/) {
-      $begin = 1;
-      $entry->update if $entry;
-      $entry = undef;
-    } elsif ($begin) {
-      if (/r(\d+)\s\|\s(\S+)\s\|\s(20\d\d-\d\d-\d\d\s\d\d:\d\d:\d\d)/) {
-	my $rev = $1;
-	my $login = $2;
-	my $date = $3;
-	my $userlogin = $schema->resultset('Userlogin')->find_or_create({name=>$login});
-	$entry = $schema->resultset('Vcschangelog')->create({
-	    userlogin_id =>$userlogin->id,
-	    package_id => $$package->id,
-	    date => $date,
-	    rev => $rev,
-	  });
-
-	$begin = 0;
-      }
-
-    } elsif ($entry) {
-      $entry->log($entry->log.$_);
-    }
-
+  # I remove the old
+  if (@added_entry_id) { 
+    $schema->resultset('Changelogentry')->search({
+	id => { '!=', \@added_entry_id },
+	package_id => $$package->id
+      })->delete;
   }
-  $entry->update if $entry;
+
 }
 
 sub importPkg {
@@ -135,30 +109,34 @@
 
   my @maintainer;
   my $packagesrc;
-  my $svndebrelease;
   my $tarballuri;
-  my $rev = SvnBuildStat::Common::Svn::getRev($uri);
   my $todo;
   my $currentpendingbug;
-  my $currentchangelogentry;
 # arch
   my $i386 = 'f';
   my $powerpc = 'f';
   my $sparc = 'f';
   my $amd64 = 'f';
 
+  my $vcs;
 
+  my $vcsname = $$repository->vcs_id->name;
+  $vcs = new SvnBuildStat::Vcs($vcsname, $uri);
+
+  my $rev = $vcs->getCurrentRev();
+
+
   if (!$rev) {
     info ("Can't get current svn revision");
     return;
   }
 
-  my $control = SvnBuildStat::Common::parseControl(`svn cat $uri/debian/control`);
+  my $control = SvnBuildStat::Common::parseControl($vcs->getControl());
   if (!$control) {
     info ("Failed to parse $uri/debian/control");
     return;
   }
-  
+
   my $package = $schema->resultset('Package')->find_or_create({name => $control->{packagesrc}});
 
   if (defined($rev) && defined ($package->vcsrev) && $rev eq $package->vcsrev) {
@@ -170,92 +148,76 @@
   $package->issrcinmypool (0); # deprecated, replaced by dscuri
   $package->dscuri(undef);
 
-  my @changelog = `svn cat $uri/debian/changelog`;
-  if (@changelog) {
-     if ($changelog[0] =~ /^.*\ \((.*)\)/) {
-$package->realsvndebrelease($1)
-    }
+  my $changelog = SvnBuildStat::Common::parseChangelog($vcs->getChangelog);
+  $package->realsvndebrelease($changelog->{realsvndebrelease});
+  $package->svndebrelease ($changelog->{svndebrelease});
+  $package->currentchangelogentry($changelog->{currentchangelogentry});
+  $package->currentpendingbug($changelog->{currentpendingbug});
 
-    foreach (@changelog) {
-      if (/^\S/ && $currentchangelogentry) {
-	# I ignore svn-bp empty template entry
-	if ($currentchangelogentry =~ /^.*\n\s\s\*\sNOT RELEASED YET\n\n\s--.*/m) {
-	  $currentchangelogentry = '';
-	} else {
-	  last; 
-	}
-      }
-      $currentchangelogentry .= $_;
-    }
-   
-    if ($currentchangelogentry =~ /^.*\ \((.*)\)/) {
-      $svndebrelease = $1; 
-    }
-    # looks for bug closed in the changelog entry
-    # the regex come from the BTS documentation
-    # TODO dpkg-parsechangelog is probably more suitable for the job :D
-    foreach ($currentchangelogentry =~ /closes:\s*(?:bug)?\#\s*\d+(?:,\s*(?:bug)?\#\s*\d+)*/ig) {
-      s/([A-Za-z]|#|:|\s)//g;
-      $currentpendingbug .= $_.',' if $_;
-    }
-
-  } else {
-
-    print "Parse error: $uri/debian/changelog\n";
-    return;
-
-  }
-
-  my @todo = `svn cat $uri/debian/TODO`;
-  @todo = `svn cat $uri/debian/TODO.Debian` unless @todo;
-  @todo = `svn cat $uri/debian/todo` unless @todo;
+  my @todo = $vcs->getTODO();
   if (@todo) {
     $todo .= $_ foreach @todo;
   }
   $package->update_from_related('repository_id',$$repository);
-  
-  $package->svndebrelease ($svndebrelease);
+
   $package->vcsuri($uri);
   $package->repository_id($$repository);
-  foreach (@{$control->{maintainers}}) {
 
-    my $maintainer = $schema->resultset('Maintainer')->find_or_create({email=>$_->email});
-    $maintainer->name($_->name);
+  # Delete the current relation betwen the maintainers and the package
+  $schema->resultset('PackageMaintainer')->search({
+      package_id => $package->id
+    })->delete;
 
+  # And recreate them
+  foreach (@{$control->{maintainers}}) {
+    my $maintainer = $schema->resultset('Maintainer')->find_or_create({email=>$_->{email}});
+    $maintainer->name($_->{name});
+    $maintainer->update();
+
     my $package_maintainer =
     $package->find_or_create_related('package_maintainers', {
 	'maintainer_id' => $maintainer->id});
   }
 
+  # I keep the changelog entry since the oldest build, si I need.. ...to
+  # find the oldest build
+  my $vcschangelog_rs = $schema->resultset('Changelogentry')->search({
+      package_id => $package->id,
+    }, {order_by => "rev DESC"});
+  my $last_rev = $vcschangelog_rs->first->rev if ($vcschangelog_rs->first);
+  updateVcsChanges(\$package, $vcs->getLastVcsChanges(5));
 
-  updateChangelog(\$package);
+
   # Search for the tarball
   my $tarball = SvnBuildStat::Common::mkTarballFromPackage(\$package);
-  my $uscandata = getUscanData(\$package);
-  my $ondebiandata = SvnBuildStat::Common::getDataFromDebianFtp(\$package);
+  my $uscandata = getUscanData(\$package, $vcs->getWatchfile);
+  my $dataFromDebianFtp = SvnBuildStat::Common::getDataFromDebianFtp(\$package);
+  use Data::Dumper;
+  print Dumper($dataFromDebianFtp);
   my $tarballurlfromtarballlayout = createTarballUrlFromTarballlayout($repository,\$package);
   $package->iswatchfilebroken($uscandata->{iswatchfilebroken});
   # Is the tarball on a Debian mirror?
-  # TODO, isnative shouldn't be returned by ondebiandata
-  if ($ondebiandata->{isnative} eq 't') {
+  # TODO, isnative shouldn't be returned by dataFromDebianFtp
+  if ($dataFromDebianFtp->{isnative} eq 't') {
     $package->isnative(1);
     $package->tarballuri('');
     $package->istarballpresent(0);
   } else {
-      $package->isnative(0);
-    if ($ondebiandata->{tarballuri}) {
-      $package->tarballuri($ondebiandata->{tarballuri});
+    $package->isnative(0);
+    if ($dataFromDebianFtp->{tarballuri}) {
+      $package->tarballuri($dataFromDebianFtp->{tarballuri});
       $package->istarballpresent(1);
-      # Or on upstream repository (using uscan)
-    } elsif($uscandata->{tarballuri}) {
+    }
+    elsif ($uscandata->{tarballuri}) {
       $package->tarballuri($uscandata->{tarballuri});
       $package->istarballpresent(1);
-      # Or on a HTTP/FTP space is a tarball layout exists
-    } elsif (testUrl($tarballurlfromtarballlayout)) {
+    }
+    # Or on a HTTP/FTP space is a tarball layout exists
+    elsif (SvnBuildStat::Common::testUrl($tarballurlfromtarballlayout)) {
       $package->tarballuri($tarballurlfromtarballlayout);
       $package->istarballpresent(1);
       # Or on the same repository
-    } elsif(exists $tarballonrepository->{$tarball}) {
+    } elsif($tarballonrepository && exists ($tarballonrepository->{$tarball})) {
       my $t = $tarballonrepository->{$tarball};
       $t =~ s!svn://svn.debian.org/svn/(.*)!http://svn.debian.org/wsvn/$1?op=file&rev=0&sc=0!;
     } else {
@@ -267,37 +229,26 @@
   # 
   $package->isuptodate($uscandata->{isuptodate});
   $package->upstreamrelease($uscandata->{upstreamrelease});
-  $package->isindebian($ondebiandata->{isindebian});
-  
+  $package->isindebian($dataFromDebianFtp->{isindebian});
+
   $package->i386($control->{i386});
   $package->powerpc($control->{powerpc});
   $package->sparc($control->{sparc});
   $package->amd64($control->{amd64});
   $package->todo($todo);
-  $package->currentchangelogentry($currentchangelogentry);
-  $package->currentpendingbug($currentpendingbug);
   $package->lastcheck('now');
   $package->vcsrev($rev); # at the end since it marks in the new status of the package ins the DB
   $package->update();
 }
 
 
-$config = new SvnBuildStat::Config();
-$schema = SvnBuildStat::Schema->connect(
-  $config->db_dsn,
-  $config->db_user,
-  $config->db_password,
-  {AutoCommit => 1, debug => 1}
-);
-
 sub importRepository {
   my $repository = shift;
 
-
-  my $tarballonrepository;
+  my $vcs = new SvnBuildStat::Vcs::Svn($$repository->uri);
   print "Repository: ".$$repository->name."\n";
   debug ("importing ".$$repository->name);
-  my $rev = SvnBuildStat::Common::Svn::getRev($$repository->uri);
+  my $rev = $vcs->getCurrentRev();
   if(! $rev) {
     print "Failed to get the current revision of ".$$repository->name."\n";
     return;
@@ -308,31 +259,18 @@
     return;
   }
 
-  my @uri;
-  
-my $t = 'svn ls -R '.$$repository->uri;
-  foreach (`$t`) {
-    chomp;
-    my $uri = $$repository->uri.'/'.$_;
-    $tarballonrepository->{basename($_)}=$uri if /\.tar\.gz$/;
-    $uri =~ s/\/$//;
-    next if /\/(tags|branches|attic)\//; # I want trunk!
-    next if /\/(sarge|etch)\//; # Try to avoid sarge and etch backport 
-    next unless /debian\/control$/;
-    $uri =~ s/(|\/)debian\/control$//;
-    push @uri, $uri;
-  }
-  
-  foreach my $uri (@uri) {
+  my ($uri, $tarballonrepository) = $vcs->scan();
+
+  foreach (@$uri) {
     # look for packages
-    importPkg($repository,$uri,1);
+    importPkg($repository,$_,$tarballonrepository);
   }
 
   $$repository->vcsrev($rev);
   $$repository->lastcheck('now');
   $$repository->update();
 
-  debug( "end import Repo");
+  debug ($$repository->name." imported");
 }
 ###################################################
 ###################################################
@@ -345,14 +283,42 @@
 
 info ("starting");
 
+$config = new SvnBuildStat::Config();
+$schema = SvnBuildStat::Schema->connect(
+  $config->db_dsn,
+  $config->db_user,
+  $config->db_password,
+  {AutoCommit => 1, debug => 1}
+);
+
+
 ########
 
 # Import packages
 my $repository_rs = $schema->resultset('Repository')->search({enabled => 'true'});
 while (my $repository = $repository_rs->next) {
-  next unless $repository->vcs_id && $repository->vcs_id->name eq "svn";
-  print $repository->name."\n";
-  importRepository(\$repository) or warn "importRepository failed for ".$repository->name."\n";
+  my $vcsname = $repository->vcs_id->name;
+  my $uri = $repository->uri;
+
+  # one repo per team
+  if ($vcsname =~ /^(svn)$/) {
+    print "import Repository". $repository->name."\n";
+    importRepository(\$repository);
+  } else { # or one repo per package
+    # TODO put this in importRepository()
+    my $vcs = new SvnBuildStat::Vcs($vcsname, $uri);
+    my $beginrev = $vcs->getCurrentRev();
+    next if $repository->vcsrev eq $beginrev;
+    print "import Repository as package ". $repository->name."\n";
+    importPkg (\$repository, $uri);
+    my $endrev = $vcs->getCurrentRev();
+    print "$beginrev eq $endrev\n";
+    if ($beginrev eq $endrev) {
+      $repository->vcsrev($endrev);
+      $repository->lastcheck('now');
+    }
+    $repository->update();
+  }
 }
 
 # Purge the removed packages

Modified: svnbuildstat/trunk/script/svnbuildstat_update-repository.pl
===================================================================
--- svnbuildstat/trunk/script/svnbuildstat_update-repository.pl	2007-11-15 07:26:20 UTC (rev 510)
+++ svnbuildstat/trunk/script/svnbuildstat_update-repository.pl	2007-11-18 23:13:04 UTC (rev 511)
@@ -13,7 +13,9 @@
 use lib '/home/sites/svnbuildstat.debian.net/svnbuildstat/lib';
 use SvnBuildStat::Schema;
 use SvnBuildStat::Config;
+use SvnBuildStat::Common;
 use Logger::Syslog;
+use SvnBuildStat::Vcs;
 
 my $debmirror = "http://ftp.debian.org";
 my $config;
@@ -86,11 +88,12 @@
 
 
 
-sub prepareFromSvn {
+sub prepare {
   my ($package) = @_;
   debug("prepareFromSvn: ".$$package->name);
 
-  return unless $$package->vcsuri;
+  my $vcsname = $$package->repository_id->vcs_id->name;
+  my $vcs = new SvnBuildStat::Vcs($vcsname, $$package->vcsuri);
 
   my $repo_shortname = $$package->repository_id->shortname;
   next unless $repo_shortname;
@@ -109,20 +112,17 @@
   }
   print "cc\n";
 
-  my $rev;
   my $packagerootdir = SvnBuildStat::Common::mkRootdirectoryFromPackage($package);
-  my $cmd = "LC_ALL=C svn export ".$$package->vcsuri." $workdir/".$packagerootdir." --force 2>&1";
-  foreach (`$cmd`) {
-    $rev = $1 if /Exported revision (\d+)\./;
-  }
-  if (($? >> 8)!=0 || !$rev) {
-    info("failed to svn export ".$$package->vcsuri);
+  my $vcsrev = $vcs->exportIn($workdir."/".$packagerootdir);
+  if (!$vcsrev) {
+    info("failed to export from vcs ".$$package->vcsuri);
     return;
   }
 
-  return unless addSubRevInChangelog($packagerootdir, "svn".$rev);
-  if ($rev ne $$package->rev) {
-    TODO
+  return unless addSubRevInChangelog($packagerootdir, $vcsname.$vcsrev);
+  if ($vcsrev ne $$package->vcsrev) {
+    #TODO: We're preparing a package that is not up to date in the DB. We should
+    # call an update DB here.
   }
 
   print `dpkg-source -b -W $packagerootdir 2>&1`;
@@ -138,14 +138,15 @@
   my $dscfile;
   foreach my $file (<$workdir/*>) {
     next unless -f $file;
-    $dscfile = $file if /\.dsc/;
+    $dscfile = basename($file) if $file =~ /\.dsc/;
     move ($file, $destdir);
   }
   return unless $dscfile;
 
   $$package->dscuri($config->server_repositorydir.'/'.$$package->repository_id->team_id->shortname.'/'.$$package->name.'/'.$dscfile);
-  $$package->issrcinmypool(1);#TODO deprecated
+  $$package->issrcinmypool(1);#TODO deprecated, we use dscuri instead
   $$package->update;
+  `rm -Rf $workdir`;
   1;
 }
 
@@ -182,31 +183,9 @@
 
 #purgeOutDated();
 
-my $package_rs = $schema->resultset('Package')->search({issrcinmypool => 'false'});
+my $package_rs = $schema->resultset('Package')->search({ dscuri => undef });
 while (my $package = $package_rs->next) {
-  next unless $package->name;
-  next unless $package->realsvndebrelease;
-
-  my $vcs;
-  if ($package->repository_id->repositoryfamily_id->vcs_id) {
-   $vcs = $package->repository_id->repositoryfamily_id->vcs_id->name;
- }
-
- # if tthere is no VCS, it's a Debian pool somewhere that I don"t need to purge
-  next unless $vcs;
-
-#    my $svndebrelease = $package->realsvndebrelease;
-#    $svndebrelease =~ s/^\d+://;
-  #
-#    my $targetdir = $repo_shortname."/".$vcs."/".$package->name."/".$
-#    my $failedNotifFile = $package->name."_".$svndebrelease.".dsc.failed";
-  #
-#    next if -f $failedNotifFile;
-
-  if ($vcs eq "svn") {
-    prepareFromSvn(\$package);
-  }
-
+  prepare(\$package);
 }
 
 




More information about the Collab-qa-commits mailing list