From a9972d82869e1f31de857e30d29fe18417e8b4c9 Mon Sep 17 00:00:00 2001
From: Assaf Gordon <assafgordon@gmail.com>
Date: Tue, 31 May 2016 20:19:38 -0400
Subject: [PATCH 3/3] sort: modify 'leading spaces' debug warning scenarios

Print warning regardless of locale, avoid warning if key is zero width.

* src/sort.c: (key_warnings): change conditions for 'leading spaces'
warning.
* tests/misc/sort-debug-warn.sh: adjust tests accordingly.
---
 src/sort.c                    | 9 ++++-----
 tests/misc/sort-debug-warn.sh | 3 ++-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/sort.c b/src/sort.c
index 72ee995..5d9ecdd 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -2424,17 +2424,16 @@ key_warnings (struct keyfield const *gkey, bool gkey_only)
         }
 
       /* Warn about field specs that will never match.  */
-      if (key->sword != SIZE_MAX && key->eword < key->sword)
+      bool zero_width = key->sword != SIZE_MAX && key->eword < key->sword;
+      if (zero_width)
         error (0, 0, _("sort key %lu has zero width and will be ignored"),
                keynum);
 
       /* Warn about significant leading blanks.  */
       bool implicit_skip = key_numeric (key) || key->month;
-      bool maybe_space_aligned = !hard_LC_COLLATE && default_key_compare (key)
-                                 && !(key->schar || key->echar);
       bool line_offset = key->eword == 0 && key->echar != 0; /* -k1.x,1.y  */
-      if (!gkey_only && tab == TAB_DEFAULT && !line_offset
-          && ((!key->skipsblanks && !(implicit_skip || maybe_space_aligned))
+      if (!zero_width && !gkey_only && tab == TAB_DEFAULT && !line_offset
+          && ((!key->skipsblanks && !implicit_skip)
               || (!key->skipsblanks && key->schar)
               || (!key->skipeblanks && key->echar)))
         error (0, 0, _("leading blanks are significant in sort key %lu; "
diff --git a/tests/misc/sort-debug-warn.sh b/tests/misc/sort-debug-warn.sh
index 4c0ef58..903bb8d 100755
--- a/tests/misc/sort-debug-warn.sh
+++ b/tests/misc/sort-debug-warn.sh
@@ -41,6 +41,7 @@ sort: using simple byte comparison
 sort: option '-r' only applies to last-resort comparison
 7
 sort: using simple byte comparison
+sort: leading blanks are significant in sort key 2; consider also specifying 'b'
 sort: options '-bg' are ignored
 8
 sort: using simple byte comparison
@@ -51,6 +52,7 @@ sort: option '-b' is ignored
 sort: using simple byte comparison
 11
 sort: using simple byte comparison
+sort: leading blanks are significant in sort key 1; consider also specifying 'b'
 12
 sort: using simple byte comparison
 sort: leading blanks are significant in sort key 1; consider also specifying 'b'
@@ -116,7 +118,6 @@ sort: using simple byte comparison
 sort: sort key 1 is numeric and spans multiple fields
 sort: obsolescent sort key '+2 -1' used; consider '-k 3,1' instead
 sort: sort key 2 has zero width and will be ignored
-sort: leading blanks are significant in sort key 2; consider also specifying 'b'
 sort: option '-b' is ignored
 sort: option '-r' only applies to last-resort comparison
 EOF
-- 
2.7.0

