[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sort --version-sort
From: |
Jim Meyering |
Subject: |
Re: sort --version-sort |
Date: |
Wed, 13 Aug 2008 20:27:12 +0200 |
Bruce Korb <address@hidden> wrote:
> Jim Meyering wrote:
>> Simon Josefsson <address@hidden> wrote:
>>> Bruce Korb <address@hidden> writes:
>>>
>>>> Here is the usage text from my latest --sort=version patch (attached),
>>>> now that paperwork is in order.
>>> What is the status of this work? I have wanted to use sort this way
>>> several times but became disappointed that there is no support for it
>>> every time.
>>
>> The most recent patch I saw was incomplete.
>> Some of these were missing:
>> documentation (--help, NEWS, .texi), a proper "log", tests.
>
> Color me confused:
>
>
> @@ -336,10 +337,11 @@ Ordering options:\n\
> -M, --month-sort compare (unknown) < `JAN' < ... < `DEC'\n\
> -n, --numeric-sort compare according to string numerical value\n\
> -R, --random-sort sort by random hash of keys\n\
> + -V, --version-sort sort by numeric version (see strverscmp(3C))\n\
> --random-source=FILE get random bytes from FILE (default
> /dev/urandom)\n\
> --sort=WORD sort according to WORD:\n\
> general-numeric -g, month -M, numeric -n,\n\
> - random -R\n\
> + random -R, version -V\n\
> -r, --reverse reverse the result of comparisons\n\
> \n\
> "), stdout);
>
> what else is needed for "--help"?
That looks fine.
Remaining: NEWS, coreutils.texi.
Also nice (it'd make less work for me) would be if you'd
follow the new guidelines in HACKING.
I.e., use "git format-patch ..." to create the patch,
ensure that "make check" and "make syntax-check" still succeed
with the very latest.
Neither is a must, but the closer it is to perfect,
the quicker it'll go in, because I won't have to find time
to adjust things.
> I also have a clear recollection about someone volunteering to cover the
> ancillary stuff (tests, .text), though an unclear recollection as to who
> it was ( #-( - sorry). And I did write a test anyway (below).
Thanks.
> Cheers - Bruce
>
> [[P.S. does anyone know the reason for the ``(exit 1) ; exit 1'' idiom?
> It seems weird and I've not been able to google up an answer.]]
It's to ensure that the right exit code makes it into the trap
code that cleans up. Look in "info autoconf" in the "Limitations of
Builtins" discussion of "trap".
> diff --git a/tests/misc/sort-version b/tests/misc/sort-version
> new file mode 100755
> index 0000000..7410015
> --- /dev/null
> +++ b/tests/misc/sort-version
> @@ -0,0 +1,79 @@
> +#!/usr/bin/echo do-not-run-this-directly.-Use-a-shell
> +# -*- Mode: shell-script -*-
> +
> +if test "$VERBOSE" = yes; then
> + set -x
> + sort --version
> +fi
> +
> +. $top_srcdir/tests/test-lib.sh
> +
> +s_file=sort-ver-src
> +g_file=sort-ver-good
> +r_file=sort-ver-res
> +
> +cat > ${s_file} <<- _EOF_
No curly braces, please.
> + string start 5.0.0 end of str
> + string start 5.00.0 end of str
> + string start 5.1.0 end of str
> + string start 5.10.0 end of str
> + string start 5.2.0 end of str
> + string start 5.20.0 end of str
> + string start 5.3.0 end of str
> + string start 5.30.0 end of str
> + string start 5.4.0 end of str
> + string start 5.40.0 end of str
> + string start 5.5.0 end of str
> + string start 5.50.0 end of str
> + string start 5.6.0 end of str
> + string start 5.60.0 end of str
> + string start 5.7.0 end of str
> + string start 5.70.0 end of str
> + string start 5.8.0 end of str
> + string start 5.80.0 end of str
> + string start 5.9.0 end of str
> + string start 5.90.0 end of str
> + _EOF_
> +
> +
> +cat > ${g_file} <<- _EOF_
> + string start 5.00.0 end of str
> + string start 5.0.0 end of str
> + string start 5.1.0 end of str
> + string start 5.2.0 end of str
> + string start 5.3.0 end of str
> + string start 5.4.0 end of str
> + string start 5.5.0 end of str
> + string start 5.6.0 end of str
> + string start 5.7.0 end of str
> + string start 5.8.0 end of str
> + string start 5.9.0 end of str
> + string start 5.10.0 end of str
> + string start 5.20.0 end of str
> + string start 5.30.0 end of str
> + string start 5.40.0 end of str
> + string start 5.50.0 end of str
> + string start 5.60.0 end of str
> + string start 5.70.0 end of str
> + string start 5.80.0 end of str
> + string start 5.90.0 end of str
> + _EOF_
>From here on down, these 4 lines should be sufficient:
[i.e., no need to remove things, since the entire temporary
directory will be removed automatically; no need to suppress stdout ]
fail=0
sort --sort=version -o $r_file $s_file || fail=1
compare $g_file $r_file || fail=1
(exit $fail); exit $fail
> +
> +fail=0
> +sort --sort=version -o ${r_file} ${s_file}
> +
> +compare ${g_file} ${r_file} >/dev/null 2>&1
> +
> +if test $? -eq 0
> +then
> + rm -f sort-ver-*
> + (exit 0)
> + exit 0
> +fi
> +
> +exec 1>2
> +echo "sorted versions are out of order"
> +diff -u ${g_file} ${r_file}
> +ls -l sort-ver-*
> +(exit 1)
> +exit 1
>
>
> _______________________________________________
> Bug-coreutils mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/bug-coreutils
- Re: sort --version-sort, Simon Josefsson, 2008/08/13
- Re: sort --sort=version, Bruce Korb, 2008/08/13
- Re: sort --version-sort, Jim Meyering, 2008/08/13
- Re: sort --version-sort, Bruce Korb, 2008/08/13
- Re: sort --version-sort,
Jim Meyering <=
- Re: sort --version-sort, Bruce Korb, 2008/08/14
- Re: sort --version-sort, Jim Meyering, 2008/08/15
- Re: sort --version-sort, Bruce Korb, 2008/08/15
- Re: sort --version-sort, Jim Meyering, 2008/08/19
- Re: sort --version-sort, Bruce Korb, 2008/08/19
- Re: sort --version-sort, Eric Blake, 2008/08/19
- Re: sort --version-sort, Jim Meyering, 2008/08/19
- Re: sort --version-sort, Eric Blake, 2008/08/19
- Re: sort --version-sort, Jim Meyering, 2008/08/19
- Re: sort --version-sort, Eric Blake, 2008/08/19