zsh-users
 help / color / mirror / code / Atom feed
* possible 'is-at-least' bug?
@ 2015-12-04 23:45 TJ Luoma
  2015-12-05  6:29 ` Benjamin R. Haskell
  0 siblings, 1 reply; 6+ messages in thread
From: TJ Luoma @ 2015-12-04 23:45 UTC (permalink / raw)
  To: Zsh-Users List

[-- Attachment #1: Type: text/plain, Size: 824 bytes --]

Thanks to a recent tip from the list, I've started using 'is-at-least' to
compare version numbers.

However, I seem to have found a situation/edge case where it does not seem
to work.

I am trying to compare version numbers of software, in this case ImageOptim
for the Mac.

The version I have installed is '1.6.1a1' where the 'a' is for 'alpha'

There is a newer version '1.6.1b2' where the 'b' is for 'beta'

##

LATEST_VERSION='1.6.1b2'

INSTALLED_VERSION='1.6.1a1'

autoload is-at-least

is-at-least "$LATEST_VERSION" "$INSTALLED_VERSION"

if [ "$?" = "0" ]
then
echo "Up-To-Date (Installed = $INSTALLED_VERSION vs Latest =
$LATEST_VERSION)"
else
echo "Outdated (Installed = $INSTALLED_VERSION vs Latest = $LATEST_VERSION)"
fi

exit 0
##

That test results in "Up-To-Date (Installed = 1.6.1a1 vs Latest = 1.6.1b2)"

TjL

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: possible 'is-at-least' bug?
  2015-12-04 23:45 possible 'is-at-least' bug? TJ Luoma
@ 2015-12-05  6:29 ` Benjamin R. Haskell
  2015-12-07 10:25   ` Vincent Lefevre
  0 siblings, 1 reply; 6+ messages in thread
From: Benjamin R. Haskell @ 2015-12-05  6:29 UTC (permalink / raw)
  To: TJ Luoma; +Cc: Zsh-Users List

[-- Attachment #1: Type: text/plain, Size: 1714 bytes --]

On Fri, Dec 4, 2015 at 6:45 PM, TJ Luoma <luomat@gmail.com> wrote:

> Thanks to a recent tip from the list, I've started using 'is-at-least' to
> compare version numbers.
>
> However, I seem to have found a situation/edge case where it does not seem
> to work.
>
> I am trying to compare version numbers of software, in this case ImageOptim
> for the Mac.
>

`is-at-least` isn't intended to be that general.  From `man zshall`:

is-at-least needed [ present ]
    Perform  a  greater-than-or-equal-to  comparison of two strings having
the
    format of a zsh version number; that is, a string of numbers and text
with
    segments separated by dots or dashes.

To do so would require a great deal more complexity.  It'd probably be a
better check for a package manager (where the version strings can be
limited to a specific format).

The version I have installed is '1.6.1a1' where the 'a' is for 'alpha'
>
> There is a newer version '1.6.1b2' where the 'b' is for 'beta'
>
> ##
>
> LATEST_VERSION='1.6.1b2'
>
> INSTALLED_VERSION='1.6.1a1'
>
> autoload is-at-least
>
> is-at-least "$LATEST_VERSION" "$INSTALLED_VERSION"
>

For this specific case, the following seems reasonable:

LATEST_VERSION=1.6.1b2
INSTALLED_VERSION=1.6.1a1
alpha='(#b)([A-Za-z]##)'
is-at-least ${LATEST_VERSION//$~alpha/.$match[1].}
${INSTALLED_VERSION//$~alpha/.$match[1].}

'(#b)' in a pattern activates back references
'##' is the equivalent of '+' in most regular expression libraries
I think both of those require 'EXTENDED_GLOB'

The `~` in $~alpha means treat the contents of $alpha as a pattern, not
just a string to match
The $match[1] is the parenthesized group in the match (so, a string of
alphabetic characters).

-- 
Best,
Ben

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: possible 'is-at-least' bug?
  2015-12-05  6:29 ` Benjamin R. Haskell
@ 2015-12-07 10:25   ` Vincent Lefevre
  2015-12-10  0:01     ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Vincent Lefevre @ 2015-12-07 10:25 UTC (permalink / raw)
  To: zsh-users

On 2015-12-05 01:29:46 -0500, Benjamin R. Haskell wrote:
> `is-at-least` isn't intended to be that general.  From `man zshall`:
> 
> is-at-least needed [ present ]
>     Perform a greater-than-or-equal-to comparison of two strings
> having the format of a zsh version number; that is, a string of
> numbers and text with segments separated by dots or dashes.
> 
> To do so would require a great deal more complexity.

No, zsh already implements numeric sorting for the "n" parameter
expansion flag.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: possible 'is-at-least' bug?
  2015-12-07 10:25   ` Vincent Lefevre
@ 2015-12-10  0:01     ` Bart Schaefer
  2015-12-11 11:22       ` Vincent Lefevre
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2015-12-10  0:01 UTC (permalink / raw)
  To: zsh-users

On Dec 7, 11:25am, Vincent Lefevre wrote:
} Subject: Re: possible 'is-at-least' bug?
}
} On 2015-12-05 01:29:46 -0500, Benjamin R. Haskell wrote:
} > `is-at-least` isn't intended to be that general.
} > 
} > To do so would require a great deal more complexity.
} 
} No, zsh already implements numeric sorting for the "n" parameter
} expansion flag.

That's not the complexity he means.  Right now is-at-least splits up
the string on dots and dashes by the simple expedient of setting $IFS.
To also split "1a1" and "1b2" etc. on the non-space between the numbers
and the letters, would require quite a bit more effort.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: possible 'is-at-least' bug?
  2015-12-10  0:01     ` Bart Schaefer
@ 2015-12-11 11:22       ` Vincent Lefevre
  2015-12-12  5:29         ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Vincent Lefevre @ 2015-12-11 11:22 UTC (permalink / raw)
  To: zsh-users

On 2015-12-09 16:01:57 -0800, Bart Schaefer wrote:
> On Dec 7, 11:25am, Vincent Lefevre wrote:
> } Subject: Re: possible 'is-at-least' bug?
> }
> } On 2015-12-05 01:29:46 -0500, Benjamin R. Haskell wrote:
> } > `is-at-least` isn't intended to be that general.
> } > 
> } > To do so would require a great deal more complexity.
> } 
> } No, zsh already implements numeric sorting for the "n" parameter
> } expansion flag.
> 
> That's not the complexity he means.  Right now is-at-least splits up
> the string on dots and dashes by the simple expedient of setting $IFS.
> To also split "1a1" and "1b2" etc. on the non-space between the numbers
> and the letters, would require quite a bit more effort.

I meant that two such words could be compared without having to
split them, thanks to numeric sorting.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: possible 'is-at-least' bug?
  2015-12-11 11:22       ` Vincent Lefevre
@ 2015-12-12  5:29         ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2015-12-12  5:29 UTC (permalink / raw)
  To: zsh-users

On Dec 11, 12:22pm, Vincent Lefevre wrote:
}
} > } On 2015-12-05 01:29:46 -0500, Benjamin R. Haskell wrote:
} > } > `is-at-least` isn't intended to be that general.
} > } > 
} > } > To do so would require a great deal more complexity.
} > 
} > To also split "1a1" and "1b2" etc. on the non-space between the numbers
} > and the letters, would require quite a bit more effort.
} 
} I meant that two such words could be compared without having to
} split them, thanks to numeric sorting.

Hmm.  Yes, that could be done.  I think it conflicts with sorting of zsh
version numbers, though, because "zefram2" is supposed to be considered
an older version substring than "pws4".  (Although no version of zsh has
had a ZSH_VERSION string that looks like that in more than a decade.)

Incidentally, is-at-least completely ignores segments that have no
digits in them at all, so zsh-5.2-dev-1 and zsh-5.2-test-1 will be
considered the same.

The following is what Vincent suggested but does not address dev / test.


diff --git a/Functions/Misc/is-at-least b/Functions/Misc/is-at-least
index d4b0e2f..d1073ff 100644
--- a/Functions/Misc/is-at-least
+++ b/Functions/Misc/is-at-least
@@ -16,7 +16,7 @@
 
 emulate -L zsh
 
-local IFS=".-" min_cnt=0 ver_cnt=0 part min_ver version
+local IFS=".-" min_cnt=0 ver_cnt=0 part min_ver version order
 
 min_ver=(${=1})
 version=(${=2:-$ZSH_VERSION} 0)
@@ -24,6 +24,12 @@ version=(${=2:-$ZSH_VERSION} 0)
 while (( $min_cnt <= ${#min_ver} )); do
   while [[ "$part" != <-> ]]; do
     (( ++ver_cnt > ${#version} )) && return 0
+    if [[ ${version[ver_cnt]} = *[0-9][^0-9]* ]]; then
+      # A leading number and then some text.  Not a zsh version string,
+      # so compare by sorting with numeric order.
+      order=( ${version[ver_cnt]} ${min_ver[ver_cnt]} )
+      [[ $order != ${${(On)order}} ]] && return 1
+    fi
     part=${version[ver_cnt]##*[^0-9]}
   done
 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-12-12  5:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-04 23:45 possible 'is-at-least' bug? TJ Luoma
2015-12-05  6:29 ` Benjamin R. Haskell
2015-12-07 10:25   ` Vincent Lefevre
2015-12-10  0:01     ` Bart Schaefer
2015-12-11 11:22       ` Vincent Lefevre
2015-12-12  5:29         ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).