initial commit
This commit is contained in:
commit
d3fa832ca2
|
@ -0,0 +1,20 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright 2020 "yafox"
|
||||
|
||||
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.
|
|
@ -0,0 +1,4 @@
|
|||
vercmp-bare-formats
|
||||
===================
|
||||
|
||||
basic formats for use with `vercmp`. as simple as it gets.
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/sh
|
||||
|
||||
. "$VERCMPROOT/format/default.sh"
|
||||
|
||||
comparever_default_after_dash() {
|
||||
comparever_default "$(echo "$1" | cut -d- -f2)" "$(echo "$2" | cut -d- -f2)"
|
||||
}
|
||||
comparever() { comparever_default_after_dash $@; }
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/sh
|
||||
|
||||
. "$VERCMPROOT/format/default.sh"
|
||||
|
||||
comparever_dotless_patch() {
|
||||
# a semver that sometimes uses letters as an additional patch field without
|
||||
# bothering to add a dot.
|
||||
comparever_default \
|
||||
"$(echo "$1" | sed 's/\([a-z]\+[0-9a-z]*\)$/.\1/')" \
|
||||
"$(echo "$2" | sed 's/\([a-z]\+[0-9a-z]*\)$/.\1/')"
|
||||
}
|
||||
comparever() { comparever_dotless_patch $@; }
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/sh
|
||||
|
||||
. "$VERCMPROOT/format/default.sh"
|
||||
|
||||
comparever_default_with_underscores() {
|
||||
comparever_default "$(echo "$1" | tr '_' '.')" "$(echo "$2" | tr '_' '.')"
|
||||
}
|
||||
comparever() { comparever_default_with_underscores $@; }
|
|
@ -0,0 +1,10 @@
|
|||
#!/bin/sh
|
||||
|
||||
. "$VERCMPROOT/format/default.sh"
|
||||
|
||||
comparever_gdb() {
|
||||
# a semver that eschews using a dash before prerelease versions.
|
||||
comparever_default "$(echo "$1" | sed 's/\([a-z]\+[0-9a-z]*\)$/-\1/i')" \
|
||||
"$(echo "$2" | sed 's/\([a-z]\+[0-9a-z]*\)$/-\1/i')"
|
||||
}
|
||||
comparever() { comparever_gdb $@; }
|
|
@ -0,0 +1,67 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
# accepts two semantic-ish versions and echoes a character representing the
|
||||
# relationship between the two.
|
||||
# "semantic-ish" means here "a superset of semantic versioning." all correctly
|
||||
# constructed semantic versions should compare in accordance with version 2.0 of
|
||||
# the semver.org spec. versions that do not conform to the spec may also
|
||||
# compare correctly. the primary difference is that there is no limitation on
|
||||
# the number of version fields.
|
||||
comparever() { comparever_default $@; }
|
||||
|
||||
# a split definition allows other formats to use this function to define their
|
||||
# own comparever functions if they wish.
|
||||
comparever_default() {
|
||||
v1="$1"
|
||||
v2="$2"
|
||||
|
||||
# strip any trailing meta tags
|
||||
v1="${v1%+*}"
|
||||
v2="${v2%+*}"
|
||||
|
||||
# equal?
|
||||
[ "$v1" != "$v2" ] || { echo "=" && return 0; }
|
||||
|
||||
# strip leading characters that match.
|
||||
while [ "$(echo "$v1" | cut -c1)" = "$(echo "$v2" | cut -c1)" ]; do
|
||||
v1="$(echo "$v1" | cut -c2-)"
|
||||
v2="$(echo "$v2" | cut -c2-)"
|
||||
done
|
||||
v1head="$(echo "$v1" | cut -c1)"
|
||||
v2head="$(echo "$v2" | cut -c1)"
|
||||
|
||||
# if the difference is a prerelease tag, the prerelease is lesser.
|
||||
case "$v1head" in -) echo '<' && return 0;; esac
|
||||
case "$v2head" in -) echo '>' && return 0;; esac
|
||||
|
||||
# otherwise, if one is a prefix of the other, the other is greater.
|
||||
[ -n "$v1" ] || { echo '<' && return 0; }
|
||||
[ -n "$v2" ] || { echo '>' && return 0; }
|
||||
|
||||
# otherwise, if one starts with a dot, the other is the greater.
|
||||
case "$v1head" in .) echo '<' && return 0;; esac
|
||||
case "$v2head" in .) echo '>' && return 0;; esac
|
||||
|
||||
# strip any remaining version fields
|
||||
v1="$(echo "$v1" | sed s/\\..*\$//)"
|
||||
v2="$(echo "$v2" | sed s/\\..*\$//)"
|
||||
|
||||
# if the version tails are numeric, compare numerically. (ignore prerelease
|
||||
# tags.) otherwise, compare lexically.
|
||||
if (echo "${v1%-*}${v2%-*}" | grep -q "^[0-9]\+\$"); then
|
||||
[ "$(echo "${v1%-*}")" -gt "$(echo "${v2%-*}")" ] \
|
||||
&& echo ">" \
|
||||
|| echo "<"
|
||||
|
||||
else
|
||||
# v1 and v2 contain only the differences. using 'cut' and tabs here to
|
||||
# perform a lexical sort on the differences and retrieve the original
|
||||
# string associated with the greater of the two remainders.
|
||||
greater=$(printf "%s\t%s\n%s\t%s" "$v1" "$1" "$v2" "$2" \
|
||||
| sort | tail -n1 | cut -f2)
|
||||
|
||||
[ "$greater" = "$1" ] && echo ">" || echo "<"
|
||||
fi
|
||||
}
|
Loading…
Reference in New Issue