From root@ugh.net.au  Sat Apr 15 19:47:31 2000
Return-Path: <root@ugh.net.au>
Received: from starbug.ugh.net.au (starbug.ugh.net.au [203.31.238.37])
	by hub.freebsd.org (Postfix) with ESMTP id E3B4037B736
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 15 Apr 2000 19:47:29 -0700 (PDT)
	(envelope-from root@ugh.net.au)
Received: by starbug.ugh.net.au (Postfix, from userid 0)
	id 95336A818; Sun, 16 Apr 2000 12:47:28 +1000 (EST)
Message-Id: <20000416024728.95336A818@starbug.ugh.net.au>
Date: Sun, 16 Apr 2000 12:47:28 +1000 (EST)
From: andrew@ugh.net.au
Sender: root@ugh.net.au
Reply-To: andrew@ugh.net.au
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] pkg_version thinks 4.04 > 4.1
X-Send-Pr-Version: 3.2

>Number:         18030
>Category:       bin
>Synopsis:       [PATCH] pkg_version thinks 4.04 > 4.1
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bmah
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 15 19:50:01 PDT 2000
>Closed-Date:    Thu Oct 19 23:17:52 PDT 2000
>Last-Modified:  Thu Oct 19 23:19:58 PDT 2000
>Originator:     Andrew
>Release:        FreeBSD 4.0-STABLE i386
>Organization:
UgH!
>Environment:

4.0-STABLE as of yesterday

>Description:

pkg_version thinks 4.04 > 4.1. It does this becasue it splits version numbers
up as if they were . delimited. It then tries to comapre each group. The second
comparison is 04 <=> 1. Perl treats 04 as 4 and so it becomes bigger.

>How-To-Repeat:

Run pkg_version with an old port (such as analog 4.04) installed.

>Fix:

Force a . on the front of the numbers. This seems to work. I have also changed
the variables $p1 and $p2 to my from local as per perlsub(1) and changed a
little bit of indenting to make it more logical (IMHO) and closer to style(9).


--- pkg_version.pl.orig	Mon Dec  6 13:19:16 1999
+++ pkg_version.pl	Sun Apr 16 12:32:36 2000
@@ -57,36 +57,39 @@
 # This function returns -1, 0, or 1, in the same manner as <=> or cmp.
 #
 sub CompareVersions {
-    local($v1, $v2);
+    my($v1, $v2);
     $v1 = $_[0];
     $v2 = $_[1];
 
     # Short-cut in case of equality
     if ($v1 eq $v2) {
-	return 0;
+		return 0;
     }
 
     # Loop over different components (the parts separated by dots).
     # If any component differs, we have the basis for an inequality.
     while (1) {
-	($p1, $v1) = split(/\./, $v1, 2);
-	($p2, $v2) = split(/\./, $v2, 2);
+		($p1, $v1) = split(/\./, $v1, 2);
+		($p2, $v2) = split(/\./, $v2, 2);
 
-	# If we\'re out of components, they\'re equal (this probably won\'t
-	# happen, since the short-cut case above should get this).
-	if (($p1 eq "") && ($p2 eq "")) {
-	    return 0;
-	}
-	# Check for numeric inequality.  We assume here that (for example)
-	# 3.09 < 3.10.
-	elsif ($p1 != $p2) {
-	    return $p1 <=> $p2;
-	}
-	# Check for string inequality, given numeric equality.  This
-	# handles version numbers of the form 3.4j < 3.4k.
-	elsif ($p1 ne $p2) {
-	    return $p1 cmp $p2;
-	}
+		# If we\'re out of components, they\'re equal (this probably won\'t
+		# happen, since the short-cut case above should get this).
+		if (($p1 eq "") && ($p2 eq "")) {
+			return 0;
+		}
+		# Check for numeric inequality.  We assume here that (for example)
+		# 3.09 < 3.10. We force a . on the front of $p1 and $p2 so that
+		# 4.1 > 4.04
+		elsif ($p1 != $p2) {
+			$p1 = '.' . $p1;
+			$p2 = '.' . $p2;
+			return $p1 <=> $p2;
+		}
+		# Check for string inequality, given numeric equality.  This
+		# handles version numbers of the form 3.4j < 3.4k.
+		elsif ($p1 ne $p2) {
+			return $p1 cmp $p2;
+		}
     }
 
 }

>Release-Note:
>Audit-Trail:

From: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To: andrew@ugh.net.au
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: bin/18030: [PATCH] pkg_version thinks 4.04 > 4.1
Date: Sat, 15 Apr 2000 23:09:00 -0400 (EDT)

 <<On Sun, 16 Apr 2000 12:47:28 +1000 (EST), andrew@ugh.net.au said:
 
 >> Synopsis:       [PATCH] pkg_version thinks 4.04 > 4.1
 
 That's because it is.  Version numbers, by tradition, are not reals;
 4.10 comes nine revisions after 4.1.
 
 -GAWollman
 
 --
 Garrett A. Wollman   | O Siem / We are all family / O Siem / We're all the same
 wollman@lcs.mit.edu  | O Siem / The fires of freedom 
 Opinions not those of| Dance in the burning flame
 MIT, LCS, CRS, or NSA|                     - Susan Aglukark and Chad Irschick
 

From: Samuel Tardieu <sam@inf.enst.fr>
To: andrew@ugh.net.au
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/18030: [PATCH] pkg_version thinks 4.04 > 4.1
Date: Mon, 17 Apr 2000 08:53:48 +0200

 On 16/04, andrew@ugh.net.au wrote:
 
 | Force a . on the front of the numbers. This seems to work.
 
 a2ps 4.12 > a2ps 4.3, and your patch will break it. There is no way to make
 this fully automated.
 
 

From: andrew@ugh.net.au
To: Samuel Tardieu <sam@inf.enst.fr>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/18030: [PATCH] pkg_version thinks 4.04 > 4.1
Date: Mon, 17 Apr 2000 18:24:16 +1000 (EST)

 On Mon, 17 Apr 2000, Samuel Tardieu wrote:
 
 > On 16/04, andrew@ugh.net.au wrote:
 > 
 > | Force a . on the front of the numbers. This seems to work.
 > 
 > a2ps 4.12 > a2ps 4.3, and your patch will break it. There is no way to make
 > this fully automated.
 
 Garrett Wollman pointed this out...I suggested only forcing a . infront of
 version numbers beggining with 0? I think that should fix things but
 perhaps I'm missing something else...
 
 Thanks,
 
 Andrew
 
 
 

From: andrew@ugh.net.au
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/18030: [PATCH] pkg_version thinks 4.04 > 4.1
Date: Thu, 6 Jul 2000 02:47:14 +1000 (EST)

 Well no one said anything about my leading 0 suggestion so I have coded
 it. It seems to get everything right on my system and I'm guessing even if
 it now gets some wrong that it used to get right it will get more right
 overall.
 
 I guess it will have trouble if anyone puts a leading 0 on their version
 numbers just to pad the field. Hopefully not too many of them.
 
 Thanks,
 
 Andrew
 
 --- /usr/src/usr.sbin/pkg_install/version/pkg_version.pl.orig	Mon Dec  6 13:19:16 1999
 +++ pkg_version.pl	Thu Jul  6 00:39:22 2000
 @@ -57,7 +57,7 @@
  # This function returns -1, 0, or 1, in the same manner as <=> or cmp.
  #
  sub CompareVersions {
 -    local($v1, $v2);
 +    my($v1, $v2);
      $v1 = $_[0];
      $v2 = $_[1];
  
 @@ -77,9 +77,14 @@
  	if (($p1 eq "") && ($p2 eq "")) {
  	    return 0;
  	}
 -	# Check for numeric inequality.  We assume here that (for example)
 -	# 3.09 < 3.10.
 +		# Check for numeric inequality.  We assume here that if the number
 +		# begins with a 0 then it is a decimal, else it is natural.
 +		# 3.09 < 3.10, 4.03 < 4.1
  	elsif ($p1 != $p2) {
 +			if ((index($p1, '0') == 0) or (index($p2, '0') == 0)) {
 +				$p1 = '.' . $p1;
 +				$p2 = '.' . $p2;
 +			}
  	    return $p1 <=> $p2;
  	}
  	# Check for string inequality, given numeric equality.  This
 
 
Responsible-Changed-From-To: freebsd-bugs->billf 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Mon Aug 7 07:04:45 PDT 2000 
Responsible-Changed-Why:  
Over to the maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=18030 
State-Changed-From-To: open->closed 
State-Changed-By: bmah 
State-Changed-When: Thu Oct 19 23:17:52 PDT 2000 
State-Changed-Why:  
I think that pkg_version is doing the right thing;  
if a port has version numbers that work like decimals, we ought to  
change the metadata in the port's Makefile. 


Responsible-Changed-From-To: billf->bmah 
Responsible-Changed-By: bmah 
Responsible-Changed-When: Thu Oct 19 23:17:52 PDT 2000 
Responsible-Changed-Why:  
MAINTAINER change. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=18030 
>Unformatted:
