mirror of
https://github.com/armbian/build
synced 2025-09-24 19:47:06 +07:00
Make a shallow local repository for tracking history (#3172)
* Allocate repository cleanup to a separate function. Signed-off-by: The-going <48602507+The-going@users.noreply.github.com> * Add a waiter function to serve a shallow local git repository. Signed-off-by: The-going <48602507+The-going@users.noreply.github.com> * Configuration shallow repository in sunxi64_common.inc file Signed-off-by: The-going <48602507+The-going@users.noreply.github.com> * Configuration shallow repository in sunxi_common.inc file Signed-off-by: The-going <48602507+The-going@users.noreply.github.com> * An example of using the function of creating a shallow local repository. This example is a very bad crutch. It is necessary to come up with another option for permanent use. Signed-off-by: The-going <48602507+The-going@users.noreply.github.com> * Fix variable KERNELSOURCENAME as 'name=megous' for sunxi32 Signed-off-by: The-going <48602507+The-going@users.noreply.github.com> * Required variables cannot be empty Signed-off-by: The-going <48602507+The-going@users.noreply.github.com> * Print an action message. Signed-off-by: The-going <48602507+The-going@users.noreply.github.com>
This commit is contained in:
@@ -9,31 +9,24 @@ BOOTSCRIPT='boot-sun50i-next.cmd:boot.cmd'
|
||||
LINUXFAMILY=sunxi64
|
||||
|
||||
case $BRANCH in
|
||||
legacy)
|
||||
|
||||
KERNELSOURCE="https://github.com/megous/linux"
|
||||
KERNELBRANCH="branch:orange-pi-5.4"
|
||||
KERNELPATCHDIR='sunxi-'$BRANCH
|
||||
|
||||
;;
|
||||
legacy) KERNEL_VERSION_LEVEL="5.4" ;;
|
||||
|
||||
current)
|
||||
current) KERNEL_VERSION_LEVEL="5.10" ;;
|
||||
|
||||
KERNELSOURCE="https://github.com/megous/linux"
|
||||
KERNELBRANCH="branch:orange-pi-5.10"
|
||||
KERNELPATCHDIR='sunxi-'$BRANCH
|
||||
|
||||
;;
|
||||
|
||||
edge)
|
||||
|
||||
KERNELSOURCE="https://github.com/megous/linux"
|
||||
KERNELBRANCH="branch:orange-pi-5.14"
|
||||
KERNELPATCHDIR='sunxi-'$BRANCH
|
||||
|
||||
;;
|
||||
edge) KERNEL_VERSION_LEVEL="5.14" ;;
|
||||
esac
|
||||
|
||||
KERNELSOURCE="https://github.com/megous/linux"
|
||||
KERNELSOURCENAME='name=megous'
|
||||
KERNELBRANCH="branch:orange-pi-$KERNEL_VERSION_LEVEL"
|
||||
KERNELPATCHDIR='sunxi-'$BRANCH
|
||||
|
||||
# An optional parameter for switching to a git object such as a tag, commit,
|
||||
# or a specific branch. The object must exist in the local repository.
|
||||
# KERNELSWITCHOBJ=""
|
||||
# tag|obj|commit=v5.10.15|megous/$branch|$hash
|
||||
|
||||
family_tweaks()
|
||||
{
|
||||
# execute specific tweaks function if present
|
||||
@@ -68,3 +61,24 @@ setup_write_uboot_platform()
|
||||
[[ -n $dev && $dev == mmcblk* ]] && DEVICE="/dev/$dev"
|
||||
fi
|
||||
}
|
||||
|
||||
# default settings for kernel variables of the original kernel
|
||||
# VAR_SHALLOW_ORIGINAL=var_origin_kernel
|
||||
var_origin_kernel ()
|
||||
{
|
||||
url=$MAINLINE_KERNEL_SOURCE
|
||||
name='origin'
|
||||
branch="linux-${KERNEL_VERSION_LEVEL}.y"
|
||||
start_tag="v$KERNEL_VERSION_LEVEL"
|
||||
|
||||
# checking the reachability of the initial tag
|
||||
if [ "$(git ls-remote --tags $url $start_tag | \
|
||||
awk -F'/' '{if (NR == 1) print $NF}')" != "$start_tag" ];then
|
||||
exit 177
|
||||
fi
|
||||
|
||||
# Exceptions to the rule are when the desired tag is not
|
||||
# a bifurcation point at which all previous merge branches converge.
|
||||
# This is due to the subsequent extraction of `megous`
|
||||
[ "$KERNEL_VERSION_LEVEL" == "5.12" ] && start_tag="v5.12-rc7"
|
||||
}
|
||||
|
||||
@@ -10,31 +10,24 @@ ASOUND_STATE='asound.state.sunxi-next'
|
||||
GOVERNOR=ondemand
|
||||
|
||||
case $BRANCH in
|
||||
legacy)
|
||||
|
||||
KERNELSOURCE="https://github.com/megous/linux"
|
||||
KERNELBRANCH="branch:orange-pi-5.4"
|
||||
KERNELPATCHDIR='sunxi-'$BRANCH
|
||||
legacy) KERNEL_VERSION_LEVEL="5.4" ;;
|
||||
|
||||
;;
|
||||
current) KERNEL_VERSION_LEVEL="5.10" ;;
|
||||
|
||||
current)
|
||||
|
||||
KERNELSOURCE="https://github.com/megous/linux"
|
||||
KERNELBRANCH="branch:orange-pi-5.10"
|
||||
KERNELPATCHDIR='sunxi-'$BRANCH
|
||||
|
||||
;;
|
||||
|
||||
edge)
|
||||
|
||||
KERNELSOURCE="https://github.com/megous/linux"
|
||||
KERNELBRANCH="branch:orange-pi-5.14"
|
||||
KERNELPATCHDIR='sunxi-'$BRANCH
|
||||
|
||||
;;
|
||||
edge) KERNEL_VERSION_LEVEL="5.14" ;;
|
||||
esac
|
||||
|
||||
KERNELSOURCE="https://github.com/megous/linux"
|
||||
KERNELSOURCENAME='name=megous'
|
||||
KERNELBRANCH="branch:orange-pi-$KERNEL_VERSION_LEVEL"
|
||||
KERNELPATCHDIR='sunxi-'$BRANCH
|
||||
|
||||
# An optional parameter for switching to a git object such as a tag, commit,
|
||||
# or a specific branch. The object must exist in the local repository.
|
||||
# KERNELSWITCHOBJ="tag=v5.10.15"
|
||||
# tag|obj|commit=v5.10.15|megous/$branch|$hash
|
||||
|
||||
family_tweaks()
|
||||
{
|
||||
# execute specific tweaks function if present
|
||||
@@ -77,3 +70,24 @@ setup_write_uboot_platform()
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# default settings for kernel variables of the original kernel
|
||||
# VAR_SHALLOW_ORIGINAL=var_origin_kernel
|
||||
var_origin_kernel ()
|
||||
{
|
||||
url=$MAINLINE_KERNEL_SOURCE
|
||||
name='origin'
|
||||
branch="linux-${KERNEL_VERSION_LEVEL}.y"
|
||||
start_tag="v$KERNEL_VERSION_LEVEL"
|
||||
|
||||
# checking the reachability of the initial tag
|
||||
if [ "$(git ls-remote --tags $url $start_tag | \
|
||||
awk -F'/' '{if (NR == 1) print $NF}')" != "$start_tag" ];then
|
||||
exit 177
|
||||
fi
|
||||
|
||||
# Exceptions to the rule are when the desired tag is not
|
||||
# a bifurcation point at which all previous merge branches converge.
|
||||
# This is due to the subsequent extraction of `megous`
|
||||
[ "$KERNEL_VERSION_LEVEL" == "5.12" ] && start_tag="v5.12-rc7"
|
||||
}
|
||||
|
||||
139
lib/general.sh
139
lib/general.sh
@@ -14,6 +14,8 @@
|
||||
# exit_with_error
|
||||
# get_package_list_hash
|
||||
# create_sources_list
|
||||
# clean_up_repo
|
||||
# waiter_local_repo
|
||||
# fetch_from_repo
|
||||
# improved_git
|
||||
# display_alert
|
||||
@@ -252,6 +254,134 @@ improved_git()
|
||||
|
||||
}
|
||||
|
||||
clean_up_repo ()
|
||||
{
|
||||
local target_dir=$1
|
||||
|
||||
# Files that are not tracked by git and were added
|
||||
# when the patch was applied must be removed.
|
||||
improved_git -C $target_dir clean -qdf
|
||||
|
||||
# Return the files that are tracked by git to the initial state.
|
||||
improved_git -C $target_dir checkout -qf HEAD
|
||||
}
|
||||
|
||||
# used : waiter_local_repo arg1='value' arg2:'value'
|
||||
# waiter_local_repo \
|
||||
# url='https://github.com/megous/linux' \
|
||||
# name='megous' \
|
||||
# dir='linux-mainline/5.14' \
|
||||
# branch='orange-pi-5.14' \
|
||||
# obj=<tag|commit> or tag:$tag ...
|
||||
waiter_local_repo ()
|
||||
{
|
||||
for arg in $@;do
|
||||
|
||||
case $arg in
|
||||
url=*|https://*|git://*) eval "local url=${arg/url=/}"
|
||||
;;
|
||||
dir=*|/*/*/*) eval "local dir=${arg/dir=/}"
|
||||
;;
|
||||
*=*|*:*) eval "local ${arg/:/=}"
|
||||
;;
|
||||
esac
|
||||
|
||||
done
|
||||
|
||||
# Required variables cannot be empty.
|
||||
for var in url name dir branch; do
|
||||
[ "${var#*=}" == "" ] && exit_with_error "Error in configuration"
|
||||
done
|
||||
|
||||
local reachability
|
||||
|
||||
# The 'offline' variable must always be set to 'true' or 'false'
|
||||
if [ "$OFFLINE_WORK" == "yes" ]; then
|
||||
local offline=true
|
||||
else
|
||||
local offline=false
|
||||
fi
|
||||
|
||||
local work_dir="$(realpath ${SRC}/cache/sources)/$dir"
|
||||
mkdir -p $work_dir
|
||||
cd $work_dir || exit_with_error
|
||||
|
||||
display_alert "Checking git sources" "$dir $name/$branch" "info"
|
||||
|
||||
if [ "$(git rev-parse --git-dir 2>/dev/null)" != ".git" ]; then
|
||||
git init -q .
|
||||
|
||||
# Run in the sub shell to avoid mixing environment variables.
|
||||
if [ -n "$VAR_SHALLOW_ORIGINAL" ]; then
|
||||
(
|
||||
$VAR_SHALLOW_ORIGINAL
|
||||
|
||||
display_alert "Checking git sources" "$dir $name/$branch" "info"
|
||||
if [ "$(git ls-remote -h $url $branch | \
|
||||
awk -F'/' '{if (NR == 1) print $NF}')" != "$branch" ];then
|
||||
display_alert "Bad $branch for $url in $VAR_SHALLOW_ORIGINAL"
|
||||
exit 177
|
||||
fi
|
||||
|
||||
git remote add -t $branch $name $url
|
||||
git fetch --shallow-exclude=$start_tag $name
|
||||
git fetch --deepen=1 $name
|
||||
)
|
||||
|
||||
[ "$?" == "177" ] && exit
|
||||
fi
|
||||
fi
|
||||
|
||||
files_for_clean="$(git status -s | wc -l)"
|
||||
if [ "$files_for_clean" != "0" ];then
|
||||
display_alert " Cleaning .... " "$files_for_clean files"
|
||||
clean_up_repo $work_dir
|
||||
fi
|
||||
|
||||
if [ "$name" != "$(git remote show | grep $name)" ];then
|
||||
git remote add -t $branch $name $url
|
||||
fi
|
||||
|
||||
if ! $offline; then
|
||||
for t_name in $(git remote show);do
|
||||
git fetch $t_name
|
||||
done
|
||||
fi
|
||||
|
||||
# When switching, we use the concept of only "detached branch". Therefore,
|
||||
# we extract the hash from the tag, the branch name, or from the hash itself.
|
||||
# This serves as a check of the reachability of the extraction.
|
||||
# We do not use variables that characterize the current state of the git,
|
||||
# such as `HEAD` and `FETCH_HEAD`.
|
||||
reachability=false
|
||||
for var in obj tag commit branch;do
|
||||
eval pval=\$$var
|
||||
|
||||
if [ -n "$pval" ] && [ "$pval" != *HEAD ]; then
|
||||
case $var in
|
||||
obj|tag|commit) obj=$pval ;;
|
||||
branch) obj=${name}/$branch ;;
|
||||
esac
|
||||
|
||||
if t_hash=$(git rev-parse $obj 2>/dev/null);then
|
||||
reachability=true
|
||||
break
|
||||
else
|
||||
display_alert "Variable $var=$obj unreachable for extraction"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if $reachability && [ "$t_hash" != "$(git rev-parse @ 2>/dev/null)" ];then
|
||||
# Switch "detached branch" as hash
|
||||
display_alert "Switch $obj = $t_hash"
|
||||
git checkout -qf $t_hash
|
||||
else
|
||||
# the working directory corresponds to the target commit,
|
||||
# nothing needs to be done
|
||||
display_alert "Up to date"
|
||||
fi
|
||||
}
|
||||
|
||||
# fetch_from_repo <url> <directory> <ref> <ref_subdir>
|
||||
# <url>: remote repository URL
|
||||
@@ -273,6 +403,15 @@ fetch_from_repo()
|
||||
local ref=$3
|
||||
local ref_subdir=$4
|
||||
|
||||
if [ "${url#*megous/}" == linux ]; then
|
||||
unset LINUXSOURCEDIR
|
||||
LINUXSOURCEDIR="linux-mainline/$KERNEL_VERSION_LEVEL"
|
||||
VAR_SHALLOW_ORIGINAL=var_origin_kernel
|
||||
waiter_local_repo "url=$url $KERNELSOURCENAME $KERNELBRANCH dir=$LINUXSOURCEDIR $KERNELSWITCHOBJ"
|
||||
unset VAR_SHALLOW_ORIGINAL
|
||||
return
|
||||
fi
|
||||
|
||||
# The 'offline' variable must always be set to 'true' or 'false'
|
||||
if [ "$OFFLINE_WORK" == "yes" ]; then
|
||||
local offline=true
|
||||
|
||||
Reference in New Issue
Block a user