zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] is-at-least compares zsh's version if $2 is provided but empty
@ 2023-05-28 11:39 Stephane Chazelas
  2023-05-28 15:51 ` Mikael Magnusson
  0 siblings, 1 reply; 3+ messages in thread
From: Stephane Chazelas @ 2023-05-28 11:39 UTC (permalink / raw)
  To: Zsh hackers list

autoload is-at-least
is-at-least 7.2 "$(gcc -dumpfullversion 2> /dev/null)" ||
  die "need gcc 7.2 or newer"

Will fail to detect gcc not being available or from a
version that didn't support -dumpfullversion when zsh 7.2 is
out, because when the second argument is empty, is-at-least
falls back to comparing zsh's own version instead.

IMO, it should check whether $2 is provided or not rather than
non-empty or not.

diff --git a/Functions/Misc/is-at-least b/Functions/Misc/is-at-least
index d4ff3552a..9546cb2b7 100644
--- a/Functions/Misc/is-at-least
+++ b/Functions/Misc/is-at-least
@@ -25,7 +25,7 @@ emulate -L zsh
 local IFS=".-" min_cnt=0 ver_cnt=0 part min_ver version order
 
 min_ver=(${=1})
-version=(${=2:-$ZSH_VERSION} 0)
+version=(${=2-$ZSH_VERSION} 0)
 
 while (( $min_cnt <= ${#min_ver} )); do
   while [[ "$part" != <-> ]]; do


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

* Re: [PATCH] is-at-least compares zsh's version if $2 is provided but empty
  2023-05-28 11:39 [PATCH] is-at-least compares zsh's version if $2 is provided but empty Stephane Chazelas
@ 2023-05-28 15:51 ` Mikael Magnusson
  2023-06-01 18:23   ` [PATCHv2] " Stephane Chazelas
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Magnusson @ 2023-05-28 15:51 UTC (permalink / raw)
  To: Zsh hackers list

On 5/28/23, Stephane Chazelas <stephane@chazelas.org> wrote:
> autoload is-at-least
> is-at-least 7.2 "$(gcc -dumpfullversion 2> /dev/null)" ||
>   die "need gcc 7.2 or newer"
>
> Will fail to detect gcc not being available or from a
> version that didn't support -dumpfullversion when zsh 7.2 is
> out, because when the second argument is empty, is-at-least
> falls back to comparing zsh's own version instead.
>
> IMO, it should check whether $2 is provided or not rather than
> non-empty or not.
>
> diff --git a/Functions/Misc/is-at-least b/Functions/Misc/is-at-least
> index d4ff3552a..9546cb2b7 100644
> --- a/Functions/Misc/is-at-least
> +++ b/Functions/Misc/is-at-least
> @@ -25,7 +25,7 @@ emulate -L zsh
>  local IFS=".-" min_cnt=0 ver_cnt=0 part min_ver version order
>
>  min_ver=(${=1})
> -version=(${=2:-$ZSH_VERSION} 0)
> +version=(${=2-$ZSH_VERSION} 0)
>
>  while (( $min_cnt <= ${#min_ver} )); do
>    while [[ "$part" != <-> ]]; do

This requires more changes to be useful:
% is-at-least 1.9 ''; echo $?
1
% is-at-least 0.9 ''; echo $?
0

-- 
Mikael Magnusson


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

* [PATCHv2] is-at-least compares zsh's version if $2 is provided but empty
  2023-05-28 15:51 ` Mikael Magnusson
@ 2023-06-01 18:23   ` Stephane Chazelas
  0 siblings, 0 replies; 3+ messages in thread
From: Stephane Chazelas @ 2023-06-01 18:23 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Zsh hackers list

2023-05-28 17:51:49 +0200, Mikael Magnusson:
[...]
> This requires more changes to be useful:
> % is-at-least 1.9 ''; echo $?
> 1
> % is-at-least 0.9 ''; echo $?
> 0
[...]

Well spotted. I can't say I completely follow the logic in the
function, but those corner cases are probably better
special-cased.

diff --git a/Functions/Misc/is-at-least b/Functions/Misc/is-at-least
index d4ff3552a..5985684be 100644
--- a/Functions/Misc/is-at-least
+++ b/Functions/Misc/is-at-least
@@ -24,8 +24,14 @@ emulate -L zsh
 
 local IFS=".-" min_cnt=0 ver_cnt=0 part min_ver version order
 
+: ${2=$ZSH_VERSION}
+
+# sort out the easy corner cases first
+[[ $1 = $2 ]] && return 0 # same version
+[[ -n $2 ]] || return 1   # no version
+
 min_ver=(${=1})
-version=(${=2:-$ZSH_VERSION} 0)
+version=(${=2} 0)
 
 while (( $min_cnt <= ${#min_ver} )); do
   while [[ "$part" != <-> ]]; do


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

end of thread, other threads:[~2023-06-01 18:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-28 11:39 [PATCH] is-at-least compares zsh's version if $2 is provided but empty Stephane Chazelas
2023-05-28 15:51 ` Mikael Magnusson
2023-06-01 18:23   ` [PATCHv2] " Stephane Chazelas

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).