1 Star 0 Fork 16

jackzhao166/grub2

forked from OpenCloudOS Stream/grub2 
Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
0015-use-rpmsort-for-version-sorting.patch 4.73 KB
Copy Edit Raw Blame History
nilusyi authored 2024-04-07 16:45 . update patches
From 82bf27c2bfbd9d731c77618acf2c3c5b8eb0378c Mon Sep 17 00:00:00 2001
From: nilusyi <nilusyi@tencent.com>
Date: Mon, 1 Apr 2024 14:52:13 +0800
Subject: [PATCH 015/272] use rpmsort for version sorting
use rpmsort provided by rpm
Signed-off-by: Michael Chang <mchang@suse.com>
---
util/grub-mkconfig_lib.in | 7 +++++-
util/grub.d/10_linux.in | 44 +++++++++++++++++++++++++++++++++++++
util/grub.d/20_linux_xen.in | 44 +++++++++++++++++++++++++++++++++++++
3 files changed, 94 insertions(+), 1 deletion(-)
diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in
index 33e1750ae..d8dc4af10 100644
--- a/util/grub-mkconfig_lib.in
+++ b/util/grub-mkconfig_lib.in
@@ -203,12 +203,17 @@ grub_file_is_not_garbage ()
version_sort ()
{
case $version_sort_sort_has_v in
+ rpmsort)
+ LC_ALL=C /usr/bin/rpmsort "$@";;
yes)
LC_ALL=C sort -V "$@";;
no)
LC_ALL=C sort -n "$@";;
*)
- if sort -V </dev/null > /dev/null 2>&1; then
+ if test -x /usr/bin/rpmsort; then
+ version_sort_sort_has_v=rpmsort
+ LC_ALL=C /usr/bin/rpmsort "$@"
+ elif sort -V </dev/null > /dev/null 2>&1; then
version_sort_sort_has_v=yes
LC_ALL=C sort -V "$@"
else
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index 523d13e81..f69f6753d 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -199,12 +199,56 @@ title_correction_code=
# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
submenu_indentation=""
+listvrf=""
+pre_sort () {
+ local l=""
+
+ for f in $list; do
+ vr="`echo $f | sed -e 's/[^-]*-//' -e 's/-\([^0-9]*\)$/\.\1/' -e 's/-/~/g' -e 's/~\([^~]*\)$/-\1/'`"
+ l="$l $vr"
+ listvrf="$listvrf $vr:$f"
+ done
+
+ list=$l
+}
+
+post_sort () {
+ local l=""
+ local vr=""
+ local f=""
+ local found=""
+
+ for i in $reverse_sorted_list; do
+ found=""
+ for vrf in $listvrf; do
+ vr=${vrf%%:*}
+ f=${vrf#*:}
+ if test x"$vr" = x"$i"; then
+ l="$l $f"
+ found=$vrf
+ break
+ fi
+ done
+ if test -n "$found"; then
+ listvrf="`echo $listvrf | (sed -e 's!'$found'!!' 2>/dev/null || echo $listvrf)`"
+ fi
+ done
+
+ for vrf in $listvrf; do
+ f=${vrf#*:}
+ l="$l $f"
+ done
+
+ reverse_sorted_list=$l
+}
+pre_sort
# Perform a reverse version sort on the entire list.
# Temporarily replace the '.old' suffix by ' 1' and append ' 2' for all
# other files to order the '.old' files after their non-old counterpart
# in reverse-sorted order.
reverse_sorted_list=$(echo $list | tr ' ' '\n' | sed -e 's/\.old$/ 1/; / 1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/; s/ 2$//')
+post_sort
if [ "x$GRUB_TOP_LEVEL" != x ]; then
reverse_sorted_list=$(grub_move_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_list})
diff --git a/util/grub.d/20_linux_xen.in b/util/grub.d/20_linux_xen.in
index ee445068f..cf64700e9 100644
--- a/util/grub.d/20_linux_xen.in
+++ b/util/grub.d/20_linux_xen.in
@@ -255,13 +255,57 @@ esac
# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
submenu_indentation=""
+listvrf=""
+pre_sort () {
+ local l=""
+
+ for f in $linux_list; do
+ vr="`echo $f | sed -e 's/[^-]*-//' -e 's/-\([^0-9]*\)$/\.\1/' -e 's/-/~/g' -e 's/~\([^~]*\)$/-\1/'`"
+ l="$l $vr"
+ listvrf="$listvrf $vr:$f"
+ done
+
+ linux_list=$l
+}
+
+post_sort () {
+ local l=""
+ local vr=""
+ local f=""
+ local found=""
+
+ for i in $reverse_sorted_linux_list; do
+ found=""
+ for vrf in $listvrf; do
+ vr=${vrf%%:*}
+ f=${vrf#*:}
+ if test x"$vr" = x"$i"; then
+ l="$l $f"
+ found=$vrf
+ break
+ fi
+ done
+ if test -n "$found"; then
+ listvrf="`echo $listvrf | (sed -e 's!'$found'!!' 2>/dev/null || echo $listvrf)`"
+ fi
+ done
+
+ for vrf in $listvrf; do
+ f=${vrf#*:}
+ l="$l $f"
+ done
+
+ reverse_sorted_linux_list=$l
+}
# Perform a reverse version sort on the entire xen_list and linux_list.
# Temporarily replace the '.old' suffix by ' 1' and append ' 2' for all
# other files to order the '.old' files after their non-old counterpart
# in reverse-sorted order.
reverse_sorted_xen_list=$(echo ${xen_list} | tr ' ' '\n' | sed -e 's/\.old$/ 1/; / 1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/; s/ 2$//')
+pre_sort
reverse_sorted_linux_list=$(echo ${linux_list} | tr ' ' '\n' | sed -e 's/\.old$/ 1/; / 1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/; s/ 2$//')
+post_sort
if [ "x$GRUB_TOP_LEVEL_XEN" != x ]; then
reverse_sorted_xen_list=$(grub_move_to_front "$GRUB_TOP_LEVEL_XEN" ${reverse_sorted_xen_list})
--
2.41.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jackzhao166/grub2.git
git@gitee.com:jackzhao166/grub2.git
jackzhao166
grub2
grub2
master

Search