scripts: sort-makefile-lines.py
authorCarlos O'Donell <carlos@redhat.com>
Wed, 17 May 2023 13:16:41 +0000 (09:16 -0400)
committerCarlos O'Donell <carlos@redhat.com>
Thu, 18 May 2023 16:33:24 +0000 (12:33 -0400)
We must return < 0, 0, or > 0 as the result of the comparison function
for cmp_to_key() to work correctly across all comparisons.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
scripts/sort-makefile-lines.py

index fd657df..c0badeb 100755 (executable)
@@ -102,7 +102,10 @@ def glibc_makefile_numeric(string1, string2):
             # string1 and string2 both share a prefix and
             # have a numeric suffix that can be compared.
             # Sort order is based on the numeric suffix.
-            return int(var1.group(1)) > int(var2.group(1))
+            # If the suffix is the same return 0, otherwise
+            # > 0 for greater-than, and < 0 for less-than.
+            # This is equivalent to the numerical difference.
+            return int(var1.group(1)) - int(var2.group(1))
     # Default to strcoll.
     return locale.strcoll(string1, string2)