Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
336a78ae
Commit
336a78ae
authored
Feb 28, 2017
by
Matthias Bertschy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use natural sorting for strings in sorting_printer
Import new dependency vbom.ml/util/sortorder Run ./hack/update-bazel.sh
parent
2681e38d
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
147 additions
and
3 deletions
+147
-3
Godeps.json
Godeps/Godeps.json
+5
-1
LICENSES
Godeps/LICENSES
+25
-0
BUILD
pkg/kubectl/BUILD
+1
-0
sorting_printer.go
pkg/kubectl/sorting_printer.go
+4
-2
BUILD
vendor/BUILD
+9
-0
LICENSE
vendor/vbom.ml/util/LICENSE
+17
-0
README.md
vendor/vbom.ml/util/sortorder/README.md
+5
-0
doc.go
vendor/vbom.ml/util/sortorder/doc.go
+5
-0
natsort.go
vendor/vbom.ml/util/sortorder/natsort.go
+76
-0
No files found.
Godeps/Godeps.json
View file @
336a78ae
{
"ImportPath"
:
"k8s.io/kubernetes"
,
"GoVersion"
:
"go1.7"
,
"GodepVersion"
:
"v7
8
"
,
"GodepVersion"
:
"v7
9
"
,
"Packages"
:
[
"github.com/ugorji/go/codec/codecgen"
,
"github.com/onsi/ginkgo/ginkgo"
,
...
...
@@ -2761,6 +2761,10 @@
"ImportPath"
:
"k8s.io/heapster/metrics/apis/metrics/v1alpha1"
,
"Comment"
:
"v1.2.0-beta.1"
,
"Rev"
:
"c2ac40f1adf8c42a79badddb2a2acd673cae3bcb"
},
{
"ImportPath"
:
"vbom.ml/util/sortorder"
,
"Rev"
:
"db5cfe13f5cc80a4990d98e2e1b0707a4d1a5394"
}
]
}
Godeps/LICENSES
View file @
336a78ae
...
...
@@ -83176,3 +83176,28 @@ Apache License
=
vendor
/
k8s
.
io
/
heapster
/
LICENSE
136e4f49
dbf29942c572a3a8f6e88a77
-
================================================================================
================================================================================
=
vendor
/
vbom
.
ml
/
util
/
sortorder
licensed
under
:
=
The
MIT
License
(
MIT
)
Copyright
(
c
)
2015
Frits
van
Bommel
Permission
is
hereby
granted
,
free
of
charge
,
to
any
person
obtaining
a
copy
of
this
software
and
associated
documentation
files
(
the
"Software"
),
to
deal
in
the
Software
without
restriction
,
including
without
limitation
the
rights
to
use
,
copy
,
modify
,
merge
,
publish
,
distribute
,
sublicense
,
and
/
or
sell
copies
of
the
Software
,
and
to
permit
persons
to
whom
the
Software
is
furnished
to
do
so
,
subject
to
the
following
conditions
:
The
above
copyright
notice
and
this
permission
notice
shall
be
included
in
all
copies
or
substantial
portions
of
the
Software
.
THE
SOFTWARE
IS
PROVIDED
"AS IS"
,
WITHOUT
WARRANTY
OF
ANY
KIND
,
EXPRESS
OR
IMPLIED
,
INCLUDING
BUT
NOT
LIMITED
TO
THE
WARRANTIES
OF
MERCHANTABILITY
,
FITNESS
FOR
A
PARTICULAR
PURPOSE
AND
NONINFRINGEMENT
.
IN
NO
EVENT
SHALL
THE
AUTHORS
OR
COPYRIGHT
HOLDERS
BE
LIABLE
FOR
ANY
CLAIM
,
DAMAGES
OR
OTHER
LIABILITY
,
WHETHER
IN
AN
ACTION
OF
CONTRACT
,
TORT
OR
OTHERWISE
,
ARISING
FROM
,
OUT
OF
OR
IN
CONNECTION
WITH
THE
SOFTWARE
OR
THE
USE
OR
OTHER
DEALINGS
IN
THE
SOFTWARE
.
=
vendor
/
vbom
.
ml
/
util
/
LICENSE
9f7e1
d7e8f527330ebb5f4c32e0f3e40
-
================================================================================
pkg/kubectl/BUILD
View file @
336a78ae
...
...
@@ -99,6 +99,7 @@ go_library(
"//vendor:k8s.io/client-go/rest",
"//vendor:k8s.io/client-go/util/integer",
"//vendor:k8s.io/client-go/util/jsonpath",
"//vendor:vbom.ml/util/sortorder",
],
)
...
...
pkg/kubectl/sorting_printer.go
View file @
336a78ae
...
...
@@ -32,6 +32,8 @@ import (
"k8s.io/client-go/util/jsonpath"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/printers"
"vbom.ml/util/sortorder"
)
// Sorting printer sorts list types before delegating to another printer.
...
...
@@ -175,7 +177,7 @@ func isLess(i, j reflect.Value) (bool, error) {
case
reflect
.
Float32
,
reflect
.
Float64
:
return
i
.
Float
()
<
j
.
Float
(),
nil
case
reflect
.
String
:
return
i
.
String
()
<
j
.
String
(
),
nil
return
sortorder
.
NaturalLess
(
i
.
String
(),
j
.
String
()
),
nil
case
reflect
.
Ptr
:
return
isLess
(
i
.
Elem
(),
j
.
Elem
())
case
reflect
.
Struct
:
...
...
@@ -254,7 +256,7 @@ func isLess(i, j reflect.Value) (bool, error) {
}
case
string
:
if
jtype
,
ok
:=
j
.
Interface
()
.
(
string
);
ok
{
return
itype
<
jtype
,
nil
return
sortorder
.
NaturalLess
(
itype
,
jtype
)
,
nil
}
default
:
return
false
,
fmt
.
Errorf
(
"unsortable type: %T"
,
itype
)
...
...
vendor/BUILD
View file @
336a78ae
...
...
@@ -16568,3 +16568,12 @@ go_library(
"//vendor:k8s.io/client-go/pkg/apis/storage/v1beta1",
],
)
go_library(
name = "vbom.ml/util/sortorder",
srcs = [
"vbom.ml/util/sortorder/doc.go",
"vbom.ml/util/sortorder/natsort.go",
],
tags = ["automanaged"],
)
vendor/vbom.ml/util/LICENSE
0 → 100644
View file @
336a78ae
The MIT License (MIT)
Copyright (c) 2015 Frits van Bommel
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
vendor/vbom.ml/util/sortorder/README.md
0 → 100644
View file @
336a78ae
## sortorder [](https://godoc.org/vbom.ml/util/sortorder)
import "vbom.ml/util/sortorder"
Sort orders and comparison functions.
vendor/vbom.ml/util/sortorder/doc.go
0 → 100644
View file @
336a78ae
// Package sortorder implements sort orders and comparison functions.
//
// Currently, it only implements so-called "natural order", where integers
// embedded in strings are compared by value.
package
sortorder
vendor/vbom.ml/util/sortorder/natsort.go
0 → 100644
View file @
336a78ae
package
sortorder
// Natural implements sort.Interface to sort strings in natural order. This
// means that e.g. "abc2" < "abc12".
//
// Non-digit sequences and numbers are compared separately. The former are
// compared bytewise, while the latter are compared numerically (except that
// the number of leading zeros is used as a tie-breaker, so e.g. "2" < "02")
//
// Limitation: only ASCII digits (0-9) are considered.
type
Natural
[]
string
func
(
n
Natural
)
Len
()
int
{
return
len
(
n
)
}
func
(
n
Natural
)
Swap
(
i
,
j
int
)
{
n
[
i
],
n
[
j
]
=
n
[
j
],
n
[
i
]
}
func
(
n
Natural
)
Less
(
i
,
j
int
)
bool
{
return
NaturalLess
(
n
[
i
],
n
[
j
])
}
func
isdigit
(
b
byte
)
bool
{
return
'0'
<=
b
&&
b
<=
'9'
}
// NaturalLess compares two strings using natural ordering. This means that e.g.
// "abc2" < "abc12".
//
// Non-digit sequences and numbers are compared separately. The former are
// compared bytewise, while the latter are compared numerically (except that
// the number of leading zeros is used as a tie-breaker, so e.g. "2" < "02")
//
// Limitation: only ASCII digits (0-9) are considered.
func
NaturalLess
(
str1
,
str2
string
)
bool
{
idx1
,
idx2
:=
0
,
0
for
idx1
<
len
(
str1
)
&&
idx2
<
len
(
str2
)
{
c1
,
c2
:=
str1
[
idx1
],
str2
[
idx2
]
dig1
,
dig2
:=
isdigit
(
c1
),
isdigit
(
c2
)
switch
{
case
dig1
!=
dig2
:
// Digits before other characters.
return
dig1
// True if LHS is a digit, false if the RHS is one.
case
!
dig1
:
// && !dig2, because dig1 == dig2
// UTF-8 compares bytewise-lexicographically, no need to decode
// codepoints.
if
c1
!=
c2
{
return
c1
<
c2
}
idx1
++
idx2
++
default
:
// Digits
// Eat zeros.
for
;
idx1
<
len
(
str1
)
&&
str1
[
idx1
]
==
'0'
;
idx1
++
{
}
for
;
idx2
<
len
(
str2
)
&&
str2
[
idx2
]
==
'0'
;
idx2
++
{
}
// Eat all digits.
nonZero1
,
nonZero2
:=
idx1
,
idx2
for
;
idx1
<
len
(
str1
)
&&
isdigit
(
str1
[
idx1
]);
idx1
++
{
}
for
;
idx2
<
len
(
str2
)
&&
isdigit
(
str2
[
idx2
]);
idx2
++
{
}
// If lengths of numbers with non-zero prefix differ, the shorter
// one is less.
if
len1
,
len2
:=
idx1
-
nonZero1
,
idx2
-
nonZero2
;
len1
!=
len2
{
return
len1
<
len2
}
// If they're not equal, string comparison is correct.
if
nr1
,
nr2
:=
str1
[
nonZero1
:
idx1
],
str2
[
nonZero2
:
idx2
];
nr1
!=
nr2
{
return
nr1
<
nr2
}
// Otherwise, the one with less zeros is less.
// Because everything up to the number is equal, comparing the index
// after the zeros is sufficient.
if
nonZero1
!=
nonZero2
{
return
nonZero1
<
nonZero2
}
}
// They're identical so far, so continue comparing.
}
// So far they are identical. At least one is ended. If the other continues,
// it sorts last.
return
len
(
str1
)
<
len
(
str2
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment