Hello,

I've completely rewritten the patch for filevercmp. Now it is easier and 
gives "better" results. Please have a look at tests/test-filevercmp.c
for expected ordering which covers most of cases.


Kamil
From 495b5d95ddca27efd31929df358c3749965691e7 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdu...@redhat.com>
Date: Thu, 5 Mar 2009 10:39:48 +0100
Subject: [PATCH] filevercmp: move hidden files up in ordering

---
 ChangeLog               |    5 +++++
 NEWS                    |    2 ++
 lib/filevercmp.c        |   15 +++++++++++++--
 tests/test-filevercmp.c |   10 ++++++++++
 4 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 903ff80..795c34f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-03-05  Kamil Dudka  <kdu...@redhat.com>
+
+	* lib/filevercmp.c: Move hidden files up in ordering.
+	* tests/test-filevercmp.c: Add tests for hidden files.
+
 2009-03-04  Bruno Haible  <br...@clisp.org>
 
 	* modules/visibility (Makefile.am): Augment AM_CFLAGS.
diff --git a/NEWS b/NEWS
index bf48451..17e241f 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
+2009-03-05  filevercmp      Move hidden files up in ordering.
+
 2009-01-22  c-strtod        This function no longer calls xalloc_die(). If
             c-strtold       you want to exit the program in case of out-of-
                             memory, the calling function needs to arrange
diff --git a/lib/filevercmp.c b/lib/filevercmp.c
index 856f30f..7b40c98 100644
--- a/lib/filevercmp.c
+++ b/lib/filevercmp.c
@@ -124,8 +124,8 @@ verrevcmp (const char *s1, size_t s1_len, const char *s2, size_t s2_len)
 int
 filevercmp (const char *s1, const char *s2)
 {
-  const char *s1_pos = s1;
-  const char *s2_pos = s2;
+  const char *s1_pos;
+  const char *s2_pos;
   const char *s1_suffix, *s2_suffix;
   size_t s1_len, s2_len;
   int result;
@@ -135,7 +135,18 @@ filevercmp (const char *s1, const char *s2)
   if (simple_cmp == 0)
     return 0;
 
+  /* handle hidden files */
+  while (*s1 == '.' || *s2 == '.')
+    {
+      if (*s1 != *s2)
+	return *s1 - *s2;
+      s1++;
+      s2++;
+    }
+
   /* "cut" file suffixes */
+  s1_pos = s1;
+  s2_pos = s2;
   s1_suffix = match_suffix (&s1_pos);
   s2_suffix = match_suffix (&s2_pos);
   s1_len = (s1_suffix ? s1_suffix : s1_pos) - s1;
diff --git a/tests/test-filevercmp.c b/tests/test-filevercmp.c
index 4efd108..fe54dc2 100644
--- a/tests/test-filevercmp.c
+++ b/tests/test-filevercmp.c
@@ -37,6 +37,16 @@
 /* set of well sorted examples */
 static const char *const examples[] =
 {
+  ".",
+  "..",
+  ".a~",
+  ".a",
+  ".b~",
+  ".b",
+  "a~",
+  "a",
+  "b~",
+  "b",
   "gcc-c++-10.fc9.tar.gz",
   "gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2",
   "glibc-2-0.1.beta1.fc10.rpm",
-- 
1.6.1.2

Reply via email to