[Debtags-commits] [svn] r1490 - central-database/branches/alioth/webfrontend

Enrico Zini enrico at costa.debian.org
Mon Nov 14 18:30:17 UTC 2005


Author: enrico
Date: Mon Nov 14 18:30:16 2005
New Revision: 1490

Modified:
   central-database/branches/alioth/webfrontend/Engine.pm
   central-database/branches/alioth/webfrontend/maint
Log:
Added 'maint applypatch' and Engine::applyPatch


Modified: central-database/branches/alioth/webfrontend/Engine.pm
==============================================================================
--- central-database/branches/alioth/webfrontend/Engine.pm	(original)
+++ central-database/branches/alioth/webfrontend/Engine.pm	Mon Nov 14 18:30:16 2005
@@ -494,7 +494,7 @@
 #				if (exists $specialTags{$t->name})
 #				{
 #					#&main::msg("Special tag: %s\n", $t->name);
-#					$tags{$t->name()} += 1;
+#					$tags{$t->name()} += 2;
 #				} else {
 					++$tags{$t->name()}
 #				}
@@ -572,6 +572,58 @@
 	return @tags;
 }
 
+sub applyPatch ($)
+{
+	my ($in) = @_;
+
+	lockdb();
+	$db = retrieve($DEBTAGS);
+	while (<$in>)
+	{
+		chop();
+		my ($pkg, $changes) = split(': ', $_);
+		if (not exists $db->{pkgs}{$pkg})
+		{
+			if ($pkg !~ /^[a-z0-9][a-z0-9+.-]+$/)
+			{
+				warn "$pkg is not a valid package name at line $.";
+				next;
+			}
+		}
+		for my $ch (split(', ', $changes))
+		{
+			if ($ch =~ /^(\+|-)(.+)/)
+			{
+				my $tag = $2;
+				if (not exists $tags{$tag})
+				{
+					warn "$tag is not a valid tag name at line $.";
+					next;
+				}
+				
+				if ($1 eq '+')
+				{
+					$db->{pkgs}{$pkg}{tags} =
+						[ sort { $a->{name} cmp $b->{name} }
+							(@{$db->{pkgs}{$pkg}{tags}}, mkdbtag($tag)) ];
+					$db->{tags}{$tag}{pkgs} =
+						[ sort { $a->{name} cmp $b->{name} }
+							(@{$db->{tags}{$tag}{pkgs}}, mkdbpkg($pkg)) ];
+				} else {
+					$db->{pkgs}{$pkg}{tags} =
+						[ grep { $_->{name} ne $tag } @{$db->{pkgs}{$pkg}{tags}} ];
+					$db->{tags}{$tag}{pkgs} =
+						[ grep { $_->{name} ne $pkg } @{$db->{tags}{$tag}{pkgs}} ];
+				}
+			} else {
+				warn "Cannot understand change $ch at line $.";
+			}
+		}
+	}
+	store $db, $DEBTAGS;
+	unlockdb();
+}
+
 ##
 ## DB maintainance functions
 ##

Modified: central-database/branches/alioth/webfrontend/maint
==============================================================================
--- central-database/branches/alioth/webfrontend/maint	(original)
+++ central-database/branches/alioth/webfrontend/maint	Mon Nov 14 18:30:16 2005
@@ -3,10 +3,11 @@
 use strict;
 use warnings;
 use Engine;
+use IO::File;
 
 sub usage ()
 {
-	print STDERR qq{Usage: $0 init|check|dump|tagcat
+	print STDERR qq{Usage: $0 init|check|dump|tagcat|patch-from|applypatch
 };
 	exit 1;
 }
@@ -139,6 +140,25 @@
 	close OUT;
 
 	Engine::closeDB();
+} elsif ($cmd eq 'applypatch') {
+	Engine::openDB();
+	if (@ARGV)
+	{
+		for my $f (@ARGV)
+		{
+			my $in = IO::File->new($f);
+			$in or die "Cannot read $f: $!";
+			Engine::applyPatch($in);
+			$in->close();
+		}
+	} else {
+		my $in = IO::File->new();
+		$in->fdopen(fileno(STDIN), "r");
+		$in or die "Cannot fdopen stdin: $!";
+		Engine::applyPatch($in);
+		$in->close();
+	}
+	Engine::closeDB();
 } else {
 	usage();
 }



More information about the Debtags-commits mailing list