summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2009-12-29 14:11:47 +0000
committerMarc Espie <espie@cvs.openbsd.org>2009-12-29 14:11:47 +0000
commit6e0440942a21d3294f142e2935104255629c0baf (patch)
treee391f23a42e6367ca7ea1a8f50b1947921b10917
parent61637602eb7ffa3ac0b5717004ca6b59a46fa81e (diff)
prepare to cache conflicts in sets: object to do so, code to merge conflicts
and solver, actual auto-gen of conflict cache and solver.
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Dependencies.pm18
-rw-r--r--usr.sbin/pkg_add/pkg_add51
2 files changed, 67 insertions, 2 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
index f0258067cfb..89a9b323188 100644
--- a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Dependencies.pm,v 1.105 2009/12/29 14:03:31 espie Exp $
+# $OpenBSD: Dependencies.pm,v 1.106 2009/12/29 14:11:46 espie Exp $
#
# Copyright (c) 2005-2007 Marc Espie <espie@openbsd.org>
#
@@ -188,12 +188,28 @@ sub find_in_new_source
return $self->find_in_already_done($solver, $state, $obj);
}
+package OpenBSD::Cloner;
+sub clone
+{
+ my ($self, $h, @extra) = @_;
+ for my $extra (@extra) {
+ next unless defined $extra;
+ while (my ($k, $e) = each %{$extra->{$h}}) {
+ $self->{$h}{$k} //= $e;
+ }
+ }
+}
+
package OpenBSD::Dependencies::Solver;
+our @ISA = (qw(OpenBSD::Cloner));
use OpenBSD::PackageInfo;
sub merge
{
+ my ($solver, @extra) = @_;
+
+ $solver->clone('cache', @extra);
}
sub find_candidate
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index 4de93e3c10b..c87630a3c6e 100644
--- a/usr.sbin/pkg_add/pkg_add
+++ b/usr.sbin/pkg_add/pkg_add
@@ -1,7 +1,7 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_add,v 1.445 2009/12/29 13:58:18 espie Exp $
+# $OpenBSD: pkg_add,v 1.446 2009/12/29 14:11:46 espie Exp $
#
# Copyright (c) 2003-2009 Marc Espie <espie@openbsd.org>
#
@@ -127,10 +127,59 @@ sub quirks
return $state->{quirks};
}
+package OpenBSD::ConflictCache;
+our @ISA = (qw(OpenBSD::Cloner));
+sub new
+{
+ my $class = shift;
+ bless {done => {}, c => {}}, $class;
+}
+
+sub add
+{
+ my ($self, $handle) = @_;
+ return if $self->{done}{$handle};
+ $self->{done}{$handle} = 1;
+ for my $conflict (OpenBSD::PkgCfl::find_all($handle->plist, $state)) {
+ $self->{c}{$conflict} = 1;
+ }
+}
+
+sub list
+{
+ my $self = shift;
+ return keys %{$self->{c}};
+}
+
+sub merge
+{
+ my ($self, @extra) = @_;
+ $self->clone('c', @extra);
+ $self->clone('done', @extra);
+}
+
package OpenBSD::UpdateSet;
use OpenBSD::PackageInfo;
use OpenBSD::Error;
+sub solver
+{
+ my $set = shift;
+ if (!defined $set->{solver}) {
+ $set->{solver} = OpenBSD::Dependencies::Solver->new($set);
+ }
+ return $set->{solver};
+}
+
+sub conflict_cache
+{
+ my $set = shift;
+ if (!defined $set->{conflict_cache}) {
+ $set->{conflict_cache} = OpenBSD::ConflictCache->new;
+ }
+ return $set->{conflict_cache};
+}
+
sub setup_header
{
my ($set, $state, $handle, $info) = @_;