Author: wade
Date: 2005-12-09 18:23:57 -0500 (Fri, 09 Dec 2005)
New Revision: 54177

Added:
   trunk/release/rpmvercmp/test
   trunk/release/rpmvercmp/version_compare
Removed:
   trunk/release/rpmvercmp/bash_test
Modified:
   trunk/release/rpmvercmp/Makefile
   trunk/release/rpmvercmp/rpmvercmp
   trunk/release/rpmvercmp/rpmvercmp.c
Log:
Finally fix (hopefully for good) the version sorting we use.

This is important for the webpages, mono dailies, linux installer,
windows installer

RPM's rpmvercmp is broken, and this should work around the issues,
and still give us what we want



Modified: trunk/release/rpmvercmp/Makefile
===================================================================
--- trunk/release/rpmvercmp/Makefile    2005-12-09 23:16:42 UTC (rev 54176)
+++ trunk/release/rpmvercmp/Makefile    2005-12-09 23:23:57 UTC (rev 54177)
@@ -1,11 +1,9 @@
-
-
 CC=gcc
 
 all: rpmvercmp
 
 rpmvercmp: rpmvercmp.c Makefile
-       ${CC} -o rpmvercmp -lpopt -lrpm -lrpmio -lrpmdb rpmvercmp.c
+       ${CC} `pkg-config --libs --cflags glib-2.0` -I/opt/gnome/include -lpopt 
-lrpm -lrpmio -lrpmdb  -o rpmvercmp rpmvercmp.c
 
 clean:
        rm -f rpmvercmp

Deleted: trunk/release/rpmvercmp/bash_test
===================================================================
--- trunk/release/rpmvercmp/bash_test   2005-12-09 23:16:42 UTC (rev 54176)
+++ trunk/release/rpmvercmp/bash_test   2005-12-09 23:23:57 UTC (rev 54177)
@@ -1,13 +0,0 @@
-#!/bin/bash
-
-
-dir=`ls`
-for i in `./rpmvercmp [EMAIL PROTECTED]; do
-   echo $i
-
-done
-
-echo `./rpmvercmp [EMAIL PROTECTED]
-
-#echo $sorted
-

Modified: trunk/release/rpmvercmp/rpmvercmp
===================================================================
(Binary files differ)

Modified: trunk/release/rpmvercmp/rpmvercmp.c
===================================================================
--- trunk/release/rpmvercmp/rpmvercmp.c 2005-12-09 23:16:42 UTC (rev 54176)
+++ trunk/release/rpmvercmp/rpmvercmp.c 2005-12-09 23:23:57 UTC (rev 54177)
@@ -1,16 +1,76 @@
 /*
+ *
  * simple program to return sorted strings using rpmvercmp
  *
- * Compile with: gcc rpmvercmp.c -lrpm -lrpmio -lrpmdb -lpopt -o rpmvercmp
- *
  * Wade Berrier <[EMAIL PROTECTED]>
  *
+ * TODO: Problem, "1.1.10.1" and "1.1.10-1" are considered equivalent 
according to rpmvercmp (solved)
+ *
  */
 
 #include <rpm/rpmlib.h>
+#include <glib-2.0/glib.h>
 
-void sort(char **text, int *index_map, int size)
+/* Uses rpmvercmp but fixes it's brokenness */
+int version_compare(const char *string1, const char *string2)
 {
+       gchar **string1_list;
+       gchar **string2_list;
+
+       int difference_found = 0;
+       int result = 0;
+       int i = 0;
+
+       string1_list = g_strsplit (string1, "-", 0);
+       string2_list = g_strsplit (string2, "-", 0);
+
+       while(!difference_found) { 
+
+               if(string1_list[i] == NULL && string2_list[i] == NULL) { 
+                       /* We're at the end, and we've still found no 
differences, end it */
+                       result = 0;
+                       difference_found = 1;
+               } else if(string1_list[i] != NULL && string2_list[i] == NULL) {
+                       /* The first string has something while next is empty, 
it wins */
+                       result = 1;
+                       difference_found = 1;
+               } else if(string1_list[i] == NULL && string2_list[i] != NULL) {
+                       /* The first string is empty, second (containing 
something) wins */
+                       result = -1;
+                       difference_found = 1;
+               } else {
+                       /* Both strings are not NULL */
+
+                       result = rpmvercmp(string1_list[i], string2_list[i]);
+
+                       if (result > 0 ) { 
+                               /* Greater than */
+                               difference_found = 1;
+
+                       } else if( result < 0 ) { 
+                               /* Less than */
+                               difference_found = 1;
+                       } else {
+                               /* Equal to, continue to next round */
+                       }
+               }
+
+               i++;
+
+       }
+
+       g_strfreev(string1_list);
+       g_strfreev(string2_list);
+
+       return (result);
+
+}
+
+
+/* Simple bubble sort */
+/* Args: array of strings, map to signify order, size, and function pointer to 
use for comparison */
+void sort(char **text, int *index_map, int size, int (compare_func)(const char 
*, const char*))
+{
        int swap_made = 1;
        int i;
        int temp_index;
@@ -22,7 +82,7 @@
                for(i = 0; i < size - 1; i++) {
                        
                        /* If the first is of higher precedence than the second 
*/      
-                       if(rpmvercmp(text[index_map[i]], text[index_map[i + 
1]]) == 1) {
+                       if(compare_func(text[index_map[i]], text[index_map[i + 
1]]) == 1) {
                        
                                temp_index = index_map[i];
                                index_map[i] = index_map[i + 1];
@@ -40,7 +100,6 @@
        int i = 0;
        for(i = 0; i < size; i++)
                printf("%s\n", text[index_map[i]]);
-       /*printf("\n");*/
 }
 
 
@@ -52,16 +111,16 @@
        int index_map[argc];
 
        if(argc < 2) {
-               /* printf("Usage: rpmvercmp string1 string2 ... string[n]\n"); 
*/
                exit(1);
-
        }
 
        /* Init map */
        for(i = 0; i < argc; i++)
                index_map[i] = i;
 
-       sort(&argv[1], index_map, argc - 1);
+       sort(&argv[1], index_map, argc - 1, &version_compare);
+
        print_list(&argv[1], index_map, argc - 1);
 
 }
+

Copied: trunk/release/rpmvercmp/test (from rev 54174, 
trunk/release/rpmvercmp/bash_test)
===================================================================
--- trunk/release/rpmvercmp/bash_test   2005-12-09 22:42:19 UTC (rev 54174)
+++ trunk/release/rpmvercmp/test        2005-12-09 23:23:57 UTC (rev 54177)
@@ -0,0 +1,31 @@
+#!/bin/bash
+  
+  
+# Why something had to be used besides ls -v : fails sorting the files mono 
source tarball versions
+# rpmvercmp fixed the below version problem, but introduced some problems in 
that 1.1.10.1 and 1.1.10-1 were equivalent, thus had to come up with currently 
in rpmvercmp.c
+  
+# This is what fails with ls -v *
+versions=(
+       mono-1.1.9.2.tar.gz
+       mono-1.1.10.1.tar.gz
+       mono-1.1.10.tar.gz
+       hey
+       mono-1.1.9.tar.gz
+       mono-1.1.9.1.tar.gz
+)
+  
+echo [EMAIL PROTECTED]
+./rpmvercmp [EMAIL PROTECTED]
+  
+versions=(
+       1.1.9.2
+       1.1.10-1
+       1.1.10.1
+       1.1.10
+       1.1.9
+       1.1.9.1
+)
+  
+echo [EMAIL PROTECTED]
+./rpmvercmp [EMAIL PROTECTED]
+

Added: trunk/release/rpmvercmp/version_compare
===================================================================
--- trunk/release/rpmvercmp/version_compare     2005-12-09 23:16:42 UTC (rev 
54176)
+++ trunk/release/rpmvercmp/version_compare     2005-12-09 23:23:57 UTC (rev 
54177)
@@ -0,0 +1,264 @@
+#!/usr/bin/env python
+
+# Toying with the idea of doing this in python if I couldn't get the C version 
to work... 
+
+# This program obviously doesn't work
+
+import sys
+import string
+import re
+
+# Delimiters ordered by sort preference (earlier in list has lower preference)
+delimiters = '-.'
+
+delimit_match = re.compile("[%s]" % delimiters)
+
+def compare_with_operator(string1, string2, operator):
+       pass
+
+# Takes an array of strings and sorts "doing the right thing" 
+#  (specifically for filenames with versions in them)
+def version_compare(string1, string2):
+
+       # First, split these strings on delimeters, namely, '.' and '-'
+
+       # Then, going down each of the paired lists, do string comparisons, 
+       #  but if they are equal, give preference to certain preceding 
delimiters (in our case, '.')
+       list1 = delimit_match.split(string1)
+       list2 = delimit_match.split(string2)
+
+       list1_len = len(list1)
+       list2_len = len(list2)
+
+       result = 0
+       # Have i count up to the smaller of the two lists
+       for i in range(min(len(list1), len(list2))):
+               print "First %s" % list1[i]
+               print "Second %s" % list2[i]
+               # Only continue through the list if they are equivalent
+               if list1[i] == list2[i]: 
+                       result = 0
+               elif list1[i] > list2[i]: 
+                       result = 1
+                       break
+               elif list1[i] < list2[i]: 
+                       result = -1
+                       break
+
+       # Or, 
+       # First, split on first delimiter, for each of those, split second 
delimited, and compare
+
+       return result
+
+
+def commandline():
+       version_strings = sys.argv[1:]
+
+       # Sort using our method
+       version_strings.sort(version_compare)
+
+       for str in version_strings:
+               print str,
+
+
+# If called from the command line, run main, otherwise, functions are callable 
through imports
+if __name__ == "__main__":
+       commandline()
+
+
+
+#!/usr/bin/env python
+
+import sys
+import string
+import re
+
+# Delimiters ordered by sort preference (earlier in list has lower preference)
+delimiters = '-.'
+
+delimit_match = re.compile("[%s]" % delimiters)
+
+def compare_with_operator(string1, string2, operator):
+       pass
+
+# Takes an array of strings and sorts "doing the right thing" 
+#  (specifically for filenames with versions in them)
+def version_compare(string1, string2):
+
+       # First, split these strings on delimeters, namely, '.' and '-'
+
+       # Then, going down each of the paired lists, do string comparisons, 
+       #  but if they are equal, give preference to certain preceding 
delimiters (in our case, '.')
+       list1 = delimit_match.split(string1)
+       list2 = delimit_match.split(string2)
+
+       list1_len = len(list1)
+       list2_len = len(list2)
+
+       result = 0
+       # Have i count up to the smaller of the two lists
+       for i in range(min(len(list1), len(list2))):
+               print "First %s" % list1[i]
+               print "Second %s" % list2[i]
+               # Only continue through the list if they are equivalent
+               if list1[i] == list2[i]: 
+                       result = 0
+               elif list1[i] > list2[i]: 
+                       result = 1
+                       break
+               elif list1[i] < list2[i]: 
+                       result = -1
+                       break
+
+       # Or, 
+       # First, split on first delimiter, for each of those, split second 
delimited, and compare
+
+       return result
+
+
+def commandline():
+       version_strings = sys.argv[1:]
+
+       # Sort using our method
+       version_strings.sort(version_compare)
+
+       for str in version_strings:
+               print str,
+
+
+# If called from the command line, run main, otherwise, functions are callable 
through imports
+if __name__ == "__main__":
+       commandline()
+
+
+
+#!/usr/bin/env python
+
+import sys
+import string
+import re
+
+# Delimiters ordered by sort preference (earlier in list has lower preference)
+delimiters = '-.'
+
+delimit_match = re.compile("[%s]" % delimiters)
+
+def compare_with_operator(string1, string2, operator):
+       pass
+
+# Takes an array of strings and sorts "doing the right thing" 
+#  (specifically for filenames with versions in them)
+def version_compare(string1, string2):
+
+       # First, split these strings on delimeters, namely, '.' and '-'
+
+       # Then, going down each of the paired lists, do string comparisons, 
+       #  but if they are equal, give preference to certain preceding 
delimiters (in our case, '.')
+       list1 = delimit_match.split(string1)
+       list2 = delimit_match.split(string2)
+
+       list1_len = len(list1)
+       list2_len = len(list2)
+
+       result = 0
+       # Have i count up to the smaller of the two lists
+       for i in range(min(len(list1), len(list2))):
+               print "First %s" % list1[i]
+               print "Second %s" % list2[i]
+               # Only continue through the list if they are equivalent
+               if list1[i] == list2[i]: 
+                       result = 0
+               elif list1[i] > list2[i]: 
+                       result = 1
+                       break
+               elif list1[i] < list2[i]: 
+                       result = -1
+                       break
+
+       # Or, 
+       # First, split on first delimiter, for each of those, split second 
delimited, and compare
+
+       return result
+
+
+def commandline():
+       version_strings = sys.argv[1:]
+
+       # Sort using our method
+       version_strings.sort(version_compare)
+
+       for str in version_strings:
+               print str,
+
+
+# If called from the command line, run main, otherwise, functions are callable 
through imports
+if __name__ == "__main__":
+       commandline()
+
+
+
+#!/usr/bin/env python
+
+import sys
+import string
+import re
+
+# Delimiters ordered by sort preference (earlier in list has lower preference)
+delimiters = '-.'
+
+delimit_match = re.compile("[%s]" % delimiters)
+
+def compare_with_operator(string1, string2, operator):
+       pass
+
+# Takes an array of strings and sorts "doing the right thing" 
+#  (specifically for filenames with versions in them)
+def version_compare(string1, string2):
+
+       # First, split these strings on delimeters, namely, '.' and '-'
+
+       # Then, going down each of the paired lists, do string comparisons, 
+       #  but if they are equal, give preference to certain preceding 
delimiters (in our case, '.')
+       list1 = delimit_match.split(string1)
+       list2 = delimit_match.split(string2)
+
+       list1_len = len(list1)
+       list2_len = len(list2)
+
+       result = 0
+       # Have i count up to the smaller of the two lists
+       for i in range(min(len(list1), len(list2))):
+               print "First %s" % list1[i]
+               print "Second %s" % list2[i]
+               # Only continue through the list if they are equivalent
+               if list1[i] == list2[i]: 
+                       result = 0
+               elif list1[i] > list2[i]: 
+                       result = 1
+                       break
+               elif list1[i] < list2[i]: 
+                       result = -1
+                       break
+
+       # Or, 
+       # First, split on first delimiter, for each of those, split second 
delimited, and compare
+
+       return result
+
+
+def commandline():
+       version_strings = sys.argv[1:]
+
+       # Sort using our method
+       version_strings.sort(version_compare)
+
+       for str in version_strings:
+               print str,
+
+
+# If called from the command line, run main, otherwise, functions are callable 
through imports
+if __name__ == "__main__":
+       commandline()
+
+
+


Property changes on: trunk/release/rpmvercmp/version_compare
___________________________________________________________________
Name: svn:executable
   + *

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to