diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2010-01-01 17:37:09 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2010-01-01 17:37:09 +0000 |
commit | ae353120162b72eb79c4702301b7b1121552a2b0 (patch) | |
tree | 161c78bf12d130f464ab0472e4d77e5c4a8211a4 | |
parent | f4dd1cbac0e2d135d33d8ecb160151c8e58d16e8 (diff) |
for -z/-l, if several candidates are found, try to order them, and use the
nearest to the hint if they all have larger/smaller versions.
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Update.pm | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm index 37e3efc8506..a0258edfbe2 100644 --- a/usr.sbin/pkg_add/OpenBSD/Update.pm +++ b/usr.sbin/pkg_add/OpenBSD/Update.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Update.pm,v 1.125 2010/01/01 13:41:49 espie Exp $ +# $OpenBSD: Update.pm,v 1.126 2010/01/01 17:37:08 espie Exp $ # # Copyright (c) 2004-2010 Marc Espie <espie@openbsd.org> # @@ -219,6 +219,22 @@ sub process_handle } } +sub find_nearest +{ + my ($base, $locs) = @_; + + my $pkgname = OpenBSD::PackageName->from_string($base); + return undef if !defined $pkgname->{version}; + my @sorted = sort {$a->pkgname->{version}->compare($b->pkgname->{version}) } @$locs; + if ($sorted[0]->pkgname->{version}->compare($pkgname->{version}) > 0) { + return $sorted[0]; + } + if ($sorted[-1]->pkgname->{version}->compare($pkgname->{version}) < 0) { + return $sorted[-1]; + } + return undef; +} + sub process_hint { my ($self, $set, $hint, $state) = @_; @@ -235,6 +251,13 @@ sub process_hint $t =~ s/\-\d([^-]*)\-?/--/; $l = $set->match_locations(OpenBSD::Search::Stem->new($t), $k); } + if (@$l > 1) { + my $r = find_nearest($hint_name, $l); + if (defined $r) { + $self->add_location($set, $hint, $r); + return 1; + } + } my $r = $state->choose_location($hint_name, $l); if (defined $r) { $self->add_location($set, $hint, $r); |