Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Mar 2001 23:19:56 +0200
From:      Anton Berezin <tobez@tobez.org>
To:        "Bruce A. Mah" <bmah@freebsd.org>
Cc:        freebsd-ports@freebsd.org, knu@freebsd.org
Subject:   Re: pkg_version comparison routine
Message-ID:  <20010328231956.B34676@heechee.tobez.org>
In-Reply-To: <200103280237.f2S2bUP02277@bmah-freebsd-0.cisco.com>; from bmah@freebsd.org on Tue, Mar 27, 2001 at 06:37:30PM -0800
References:  <200103280237.f2S2bUP02277@bmah-freebsd-0.cisco.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Mar 27, 2001 at 06:37:30PM -0800, Bruce A. Mah wrote:

> I'm going to revisit an issue long overdue...the fact that the
> algorithm used by pkg_version(1) for comparing versions doesn't work
> in all the cases specified by the Porter's Handbook.  knu tried to get
> my attention on this issue a number of months ago, even going so far
> as to submit some patches to fix this problem.  Unfortunately I
> dropped the ball on this, and I'm sure he's understandably annoyed at
> me.

We not just steal a little snippet from devel/p5-Sort-Versions?

I believe it handles most insane possibilities.

   sub versions {
	   my(@A) = ($::a =~ /(\.|\d+|[^\.\d]+)/g);
	   my(@B) = ($::b =~ /(\.|\d+|[^\.\d]+)/g);
	   my($A,$B);
	   while(@A and @B) {
		   $A=shift @A;
		   $B=shift @B;
		   if($A eq "." and $B eq ".") {
			   next;
		   } elsif( $A eq "." ) {
			   return -1;
		   } elsif( $B eq "." ) {
			   return 1;
		   } elsif($A =~ /^\d+$/ and $B =~ /^\d+$/) {
			   return $A <=> $B if $A <=> $B;
		   } else {
			   $A = uc $A;
			   $B = uc $B;
			   return $A cmp $B if $A cmp $B;
		   }       
	   }
	   @A <=> @B;
   }

Cheers,
+Anton.
-- 
May the tuna salad be with you.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010328231956.B34676>