]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
ls and sort: use filevercmp instead of strverscmp
authorKamil Dudka <kdudka@redhat.com>
Fri, 3 Oct 2008 09:03:40 +0000 (11:03 +0200)
committerJim Meyering <meyering@redhat.com>
Fri, 3 Oct 2008 09:59:17 +0000 (11:59 +0200)
* src/ls.c (cmp_version): Use filevercmp instead of strverscmp.
* src/sort.c (usage): Remove mna reference to strverscmp(3).
(compare_version): Use filevercmp instead of strverscmp.
* bootstrap.conf: Add filevercmp to list of gnulib modules.
* tests/misc/sort-version: Remove conflicting string and enhance test.
* NEWS: Mention the change.

NEWS
bootstrap.conf
src/ls.c
src/sort.c
tests/misc/sort-version

diff --git a/NEWS b/NEWS
index b3eb3a98a56ef77d8c3b33959db6de1628e2a4aa..c32079b68b4099fa02d21d6100e17664311f9833 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -40,6 +40,8 @@ GNU coreutils NEWS                                    -*- outline -*-
 
   ls now colorizes files with capabilities if libcap is available
 
+  ls -v now uses filevercmp function as sort predicate (instead of strverscmp)
+
   md5sum now accepts the new option, --quiet, to suppress the printing of
   'OK' messages.  sha1sum, sha224sum, sha384sum, and sha512sum accept it, too.
 
@@ -53,7 +55,7 @@ GNU coreutils NEWS                                    -*- outline -*-
   When processing more than NMERGE inputs, sort uses temporary files.
 
   sort accepts a new option --version-sort (-V, --sort=version),
-  specifying that ordering is to be based on strverscmp(3).
+  specifying that ordering is to be based on filevercmp.
 
 ** Bug fixes
 
index 5685ad55b28fe3e7d37cb16d9b95d9cefdae034c..b3eec48d52faa015dbc97c2aecca8511214d5f67 100644 (file)
@@ -48,7 +48,7 @@ gnulib_modules="
        cycle-check
        d-ino d-type diacrit dirfd dirname dup2
        error euidaccess exclude exitfail fchdir fcntl fcntl-safer fdl
-       file-type fileblocks filemode filenamecat fnmatch-gnu
+       file-type fileblocks filemode filenamecat filevercmp fnmatch-gnu
        fopen-safer
        fprintftime
        fseeko
index aeece67dd50f07e9f1b8b128dba143e72df72b48..e107162ef0f7d233e405853bfcc355d2258018a2 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -94,6 +94,7 @@
 #include "hash.h"
 #include "human.h"
 #include "filemode.h"
+#include "filevercmp.h"
 #include "idcache.h"
 #include "ls.h"
 #include "lstat.h"
@@ -3123,8 +3124,9 @@ DEFINE_SORT_FUNCTIONS (extension, cmp_extension)
 
 /* Compare file versions.
    Unlike all other compare functions above, cmp_version depends only
-   on strverscmp, which does not fail (even for locale reasons), and does not
-   need a secondary sort key.
+   on filevercmp, which does not fail (even for locale reasons), and does not
+   need a secondary sort key. See lib/filevercmp.h for function description.
+
    All the other sort options, in fact, need xstrcoll and strcmp variants,
    because they all use a string comparison (either as the primary or secondary
    sort key), and xstrcoll has the ability to do a longjmp if strcoll fails for
@@ -3133,7 +3135,7 @@ DEFINE_SORT_FUNCTIONS (extension, cmp_extension)
 static inline int
 cmp_version (struct fileinfo const *a, struct fileinfo const *b)
 {
-  return strverscmp (a->name, b->name);
+  return filevercmp (a->name, b->name);
 }
 
 static int xstrcoll_version (V a, V b)
index 44bfbe0759176d61e97595d23faa0c5dc0cdd937..43c28fc84df2509ebd5ea2b43be9cf9ca7cae36c 100644 (file)
@@ -29,6 +29,7 @@
 #include "system.h"
 #include "argmatch.h"
 #include "error.h"
+#include "filevercmp.h"
 #include "hard-locale.h"
 #include "hash.h"
 #include "md5.h"
@@ -346,7 +347,7 @@ Ordering options:\n\
       --sort=WORD             sort according to WORD:\n\
                                 general-numeric -g, month -M, numeric -n,\n\
                                 random -R, version -V\n\
-  -V, --version-sort          sort by numeric version (see strverscmp(3))\n\
+  -V, --version-sort          sort by numeric version\n\
 \n\
 "), stdout);
       fputs (_("\
@@ -1823,7 +1824,7 @@ compare_random (char *restrict texta, size_t lena,
 }
 
 /* Compare the keys TEXTA (of length LENA) and TEXTB (of length LENB)
-   using strverscmp.  */
+   using filevercmp. See lib/filevercmp.h for function description. */
 
 static int
 compare_version (char *restrict texta, size_t lena,
@@ -1832,7 +1833,7 @@ compare_version (char *restrict texta, size_t lena,
   int diff;
 
   /* It is necessary to save the character after the end of the field.
-     "strverscmp" works with NUL terminated strings.  Our blocks of
+     "filevercmp" works with NUL terminated strings.  Our blocks of
      text are not necessarily terminated with a NUL byte. */
   char sv_a = texta[lena];
   char sv_b = textb[lenb];
@@ -1840,7 +1841,7 @@ compare_version (char *restrict texta, size_t lena,
   texta[lena] = '\0';
   textb[lenb] = '\0';
 
-  diff = strverscmp (texta, textb);
+  diff = filevercmp (texta, textb);
 
   texta[lena] = sv_a;
   textb[lenb] = sv_b;
index 262ee95cebbe17349e2de10ccf288b879b712f05..bdcabe4bdaa7ce47662c2e8a98bacccb18f4aaf8 100755 (executable)
@@ -24,8 +24,26 @@ fi
 . $srcdir/test-lib.sh
 
 cat > in <<- _EOF_
+       gcc-c++-10.fc9.tar.gz
+       gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2
+       glibc-2-0.1.beta1.fc10.rpm
+       glibc-common-5-0.2.beta2.fc9.ebuild
+       glibc-common-5-0.2b.deb
+       glibc-common-11b.ebuild
+       glibc-common-11-0.6rc2.ebuild
+       libstdc++-0.5.8.11-0.7rc2.fc10.tar.gz
+       libstdc++-4a.fc8.tar.gz
+       libstdc++-4.10.4.20040204svn.rpm
+       libstdc++-devel-3.fc8.ebuild
+       libstdc++-devel-3a.fc9.tar.gz
+       libstdc++-devel-8.fc8.deb
+       libstdc++-devel-8.6.2-0.4b.fc8
+       nss_ldap-1-0.2b.fc9.tar.bz2
+       nss_ldap-1-0.6rc2.fc8.tar.gz
+       nss_ldap-1.0-0.1a.tar.gz
+       nss_ldap-10beta1.fc8.tar.gz
+       nss_ldap-10.11.8.6.20040204cvs.fc10.ebuild
        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
@@ -47,7 +65,25 @@ cat > in <<- _EOF_
        _EOF_
 
 cat > exp <<- _EOF_
-       string start 5.00.0 end of str
+       gcc-c++-10.fc9.tar.gz
+       gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2
+       glibc-2-0.1.beta1.fc10.rpm
+       glibc-common-5-0.2.beta2.fc9.ebuild
+       glibc-common-5-0.2b.deb
+       glibc-common-11b.ebuild
+       glibc-common-11-0.6rc2.ebuild
+       libstdc++-0.5.8.11-0.7rc2.fc10.tar.gz
+       libstdc++-4a.fc8.tar.gz
+       libstdc++-4.10.4.20040204svn.rpm
+       libstdc++-devel-3.fc8.ebuild
+       libstdc++-devel-3a.fc9.tar.gz
+       libstdc++-devel-8.fc8.deb
+       libstdc++-devel-8.6.2-0.4b.fc8
+       nss_ldap-1-0.2b.fc9.tar.bz2
+       nss_ldap-1-0.6rc2.fc8.tar.gz
+       nss_ldap-1.0-0.1a.tar.gz
+       nss_ldap-10beta1.fc8.tar.gz
+       nss_ldap-10.11.8.6.20040204cvs.fc10.ebuild
        string start 5.0.0 end of str
        string start 5.1.0 end of str
        string start 5.2.0 end of str