mkinitrd unification across distributions
 help / color / mirror / Atom feed
From: Harald Hoyer <harald-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: "Amadeusz Żołnowski" <aidecoe-2qtfh70TtYba5EbDDlwbIw@public.gmane.org>
Cc: initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] dracut-functions: fun. vercmp optimized; credits go to Victor Lowther
Date: Wed, 09 Jun 2010 17:40:43 +0200	[thread overview]
Message-ID: <4C0FB5FB.8000309@redhat.com> (raw)
In-Reply-To: <20100609172936.752221c5-YdJE6FOikKfe60hTmSeVGxfX6IwIUJvj@public.gmane.org>

On 06/09/2010 05:29 PM, Amadeusz Żołnowski wrote:
> ---
>   dracut-functions |   23 ++++++++++++-----------
>   1 files changed, 12 insertions(+), 11 deletions(-)
>
> diff --git a/dracut-functions b/dracut-functions
> index fbac282..500e3ae 100755
> --- a/dracut-functions
> +++ b/dracut-functions
> @@ -27,19 +27,20 @@ strstr() { [[ $1 =~ $2 ]]; }
>   # Version comparision function.  Returns result similar to C strcmp,
>   # but instead of -1 is 2.  Function assumes version scheme like does
>   # Linux kernel.
> +# $1<  $2 ->  2
> +# $1 = $2 ->  0
> +# $1>  $2 ->  1
> +# To remember it easy, ask the question: Which argument is greater? ;-)
>   vercmp() {
> -    local n1 n2 i=1
> -
> -    while true
> -    do
> -        n1=$(echo $1 | cut -d'.' -f$i)
> -        n2=$(echo $2 | cut -d'.' -f$i)
> -
> -        [[ ! $n1&&  ! $n2 ]]&&  return 0
> -        [[ $n1 -lt $n2 ]]&&  return 2
> -        [[ $n1 -gt $n2 ]]&&  return 1
> -
> -        ((i++))
> +    local i n1=(${1//./ }) n2=(${2//./ })
> +
> +    for ((i=0; ; i++))
> +    do
> +        [[ ${n1[i]}&&  ! ${n2[i]} ]]&&  return 1
> +        [[ ! ${n1[i]}&&  ${n2[i]} ]]&&  return 2
> +        [[ ${n1[i]}&&  ${n2[i]} ]] || return 0
> +        ((${n1[i]}>  ${n2[i]}))&&  return 1
> +        ((${n1[i]}<  ${n2[i]}))&&  return 2
>       done
>   }
>

pushed

      parent reply	other threads:[~2010-06-09 15:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-09 15:29 [PATCH] dracut-functions: fun. vercmp optimized; credits go to Victor Lowther Amadeusz Żołnowski
     [not found] ` <20100609172936.752221c5-YdJE6FOikKfe60hTmSeVGxfX6IwIUJvj@public.gmane.org>
2010-06-09 15:40   ` Harald Hoyer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C0FB5FB.8000309@redhat.com \
    --to=harald-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=aidecoe-2qtfh70TtYba5EbDDlwbIw@public.gmane.org \
    --cc=initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox