eshowkw: Apply a patch from Mart Raudsepp <leio@gentoo.org> to speedup
authoridl0r <idl0r@gentoo.org>
Tue, 19 Oct 2010 19:38:38 +0000 (19:38 -0000)
committeridl0r <idl0r@gentoo.org>
Tue, 19 Oct 2010 19:38:38 +0000 (19:38 -0000)
version_sort(). Remove unused functions.

svn path=/trunk/gentoolkit-dev/; revision=817

ChangeLog
src/eshowkw/eshowkw
src/eshowkw/eshowkw.1

index 95f22dc337ba310e3a20216c17507b818bb2aa0a..3652b25c093e3725fe71913876a2a125560bd4d7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-10-19: Christian Ruppert <idl0r@gentoo.org>
+       * eshowkw: Apply a patch from Mart Raudsepp <leio@gentoo.org> to speedup
+               version_sort(). Remove unused functions.
+
 2010-10-10: Christian Ruppert <idl0r@gentoo.org>
        * ebump: Make ebump POSIX conform
 
index d5d3584c6a890a4b08334af4c96ac6fce62ae709..98ee7c9053ffbb67ec8a6a3b52d63b1405f880c2 100644 (file)
@@ -30,168 +30,8 @@ get_portage_dir() {
 }
 
 version_sort() {
-    local items= left=0
-    items=( $@ )
-
-    while [[ ${left} -lt ${#items[@]} ]] ; do
-        local lowest_idx=${left}
-        local idx=$(( ${lowest_idx} + 1 ))
-        while [[ ${idx} -lt ${#items[@]} ]] ; do
-            version_compare "${items[${lowest_idx}]}" "${items[${idx}]}"
-            [[ $? -eq 3 ]] && lowest_idx=${idx}
-            idx=$(( ${idx} + 1 ))
-        done
-        local tmp=${items[${lowest_idx}]}
-        items[${lowest_idx}]=${items[${left}]}
-        items[${left}]=${tmp}
-        left=$(( ${left} + 1 ))
-    done
-    echo ${items[@]}
-}
-
-version_compare() {
-    local ver_a=${1} ver_b=${2} parts_a parts_b cur_idx_a=0 cur_idx_b=0
-    parts_a=( $(get_all_version_components "${ver_a}" ) )
-    parts_b=( $(get_all_version_components "${ver_b}" ) )
-
-    ### compare number parts.
-    local inf_loop=0
-    while true ; do
-        # grab the current number components
-        local cur_tok_a=${parts_a[${cur_idx_a}]}
-        local cur_tok_b=${parts_b[${cur_idx_b}]}
-
-        # number?
-        if [[ -n ${cur_tok_a} ]] && [[ -z ${cur_tok_a//[[:digit:]]} ]] ; then
-            cur_idx_a=$(( ${cur_idx_a} + 1 ))
-            [[ ${parts_a[${cur_idx_a}]} == "." ]] \
-                && cur_idx_a=$(( ${cur_idx_a} + 1 ))
-        else
-            cur_tok_a=""
-        fi
-
-        if [[ -n ${cur_tok_b} ]] && [[ -z ${cur_tok_b//[[:digit:]]} ]] ; then
-            cur_idx_b=$(( ${cur_idx_b} + 1 ))
-            [[ ${parts_b[${cur_idx_b}]} == "." ]] \
-                && cur_idx_b=$(( ${cur_idx_b} + 1 ))
-        else
-            cur_tok_b=""
-        fi
-
-        # done with number components?
-        [[ -z ${cur_tok_a} ]] && [[ -z ${cur_tok_b} ]] && break
-
-        # to avoid going into octal mode, strip any leading zeros. otherwise
-        # bash will throw a hissy fit on versions like 6.3.068.
-        cur_tok_a=${cur_tok_a##+(0)}
-        cur_tok_b=${cur_tok_b##+(0)}
-
-        # if a component is blank, make it zero.
-        [[ -z ${cur_tok_a} ]] && cur_tok_a=0
-        [[ -z ${cur_tok_b} ]] && cur_tok_b=0
-
-        # compare
-        [[ ${cur_tok_a} -lt ${cur_tok_b} ]] && return 1
-        [[ ${cur_tok_a} -gt ${cur_tok_b} ]] && return 3
-    done
-
-    ### number parts equal. compare letter parts.
-    local letter_a=
-    letter_a=${parts_a[${cur_idx_a}]}
-    if [[ ${#letter_a} -eq 1 ]] && [[ -z ${letter_a/[a-z]} ]] ; then
-        cur_idx_a=$(( ${cur_idx_a} + 1 ))
-    else
-        letter_a="@"
-    fi
-
-    local letter_b=
-    letter_b=${parts_b[${cur_idx_b}]}
-    if [[ ${#letter_b} -eq 1 ]] && [[ -z ${letter_b/[a-z]} ]] ; then
-        cur_idx_b=$(( ${cur_idx_b} + 1 ))
-    else
-        letter_b="@"
-    fi
-
-    # compare
-    [[ ${letter_a} < ${letter_b} ]] && return 1
-    [[ ${letter_a} > ${letter_b} ]] && return 3
-
-    ### letter parts equal. compare suffixes in order.
-    local suffix rule part r_lt r_gt
-    for rule in "alpha=1" "beta=1" "pre=1" "rc=1" "p=3" "r=3" ; do
-        suffix=${rule%%=*}
-        r_lt=${rule##*=}
-        [[ ${r_lt} -eq 1 ]] && r_gt=3 || r_gt=1
-
-        local suffix_a=
-        for part in ${parts_a[@]} ; do
-            [[ ${part#${suffix}} != ${part} ]] && \
-                [[ -z ${part##${suffix}*([[:digit:]])} ]] && \
-                suffix_a=${part#${suffix}}0
-        done
-
-        local suffix_b=
-        for part in ${parts_b[@]} ; do
-            [[ ${part#${suffix}} != ${part} ]] && \
-                [[ -z ${part##${suffix}*([[:digit:]])} ]] && \
-                suffix_b=${part#${suffix}}0
-        done
-
-        [[ -z ${suffix_a} ]] && [[ -z ${suffix_b} ]] && continue
-
-        [[ -z ${suffix_a} ]] && return ${r_gt}
-        [[ -z ${suffix_b} ]] && return ${r_lt}
-
-        # avoid octal problems
-        suffix_a=${suffix_a##+(0)} ; suffix_a=${suffix_a:-0}
-        suffix_b=${suffix_b##+(0)} ; suffix_b=${suffix_b:-0}
-
-        [[ ${suffix_a} -lt ${suffix_b} ]] && return 1
-        [[ ${suffix_a} -gt ${suffix_b} ]] && return 3
-    done
-
-    ### no differences.
-    return 2
-}
-
-get_all_version_components() {
-    local ver_str=${1} result result_idx=0
-    result=( )
-
-    while [[ -n "$ver_str" ]] ; do
-        case "${ver_str:0:1}" in
-            # number: parse whilst we have a number
-            [[:digit:]])
-                result[$result_idx]="${ver_str%%[^[:digit:]]*}"
-                ver_str="${ver_str##+([[:digit:]])}"
-                result_idx=$(($result_idx + 1))
-                ;;
-
-            # separator: single character
-            [-_.])
-                result[$result_idx]="${ver_str:0:1}"
-                ver_str="${ver_str:1}"
-                result_idx=$(($result_idx + 1))
-                ;;
-
-            # letter: grab the letters plus any following numbers
-            [[:alpha:]])
-                local not_match="${ver_str##+([[:alpha:]])*([[:digit:]])}"
-                result[$result_idx]=${ver_str:0:$((${#ver_str} - ${#not_match}))}
-                ver_str="${not_match}"
-                result_idx=$(($result_idx + 1))
-                ;;
-
-            # huh?
-            *)
-                result[$result_idx]="${ver_str:0:1}"
-                ver_str="${ver_str:1}"
-                result_idx=$(($result_idx + 1))
-                ;;
-        esac
-    done
-
-    echo ${result[@]}
+    items=$@
+    python -c "import portage.versions; versions='$items'.split(); versions.sort(portage.versions.vercmp); print ' '.join(versions)"
 }
 
 get_package_dir() {
@@ -354,4 +194,3 @@ main() {
 }
 
 main "$@"
-
index 8d08048472f9c27fab703a0c75b748d6390ed86f..6099f0a213af16d53f0d91db93a2ee097234a10c 100644 (file)
@@ -10,5 +10,7 @@ eshowkw [ packagename ] (defaults to current directory if no packagename is prov
 .SH "AUTHORS"
 .LP 
 Ciaran McCreesh <ciaranm@gentoo.org>
+Mart Raudsepp <leio@gentoo.org>
+Christian Ruppert <idl0r@gentoo.org>
 .SH "BUGS"
 Please report any bugs to http://bugs.gentoo.org