]> git.ozlabs.org Git - next-scripts/blobdiff - common.sh
extract the check_dups function from common.sh
[next-scripts] / common.sh
index 9f18277ca57cc1b8d782514d27724bb851f1dfdd..272d2690a4add9521564f9c9d909c1a550aeab02 100644 (file)
--- a/common.sh
+++ b/common.sh
@@ -3,43 +3,67 @@
 #
 
 # Just in case this gets included twice ...
-[ "$_next_common_included" ] && return 0
+if [ "$_next_common_included" ]; then
+       return 0
+fi
 _next_common_included=1
 
-bin_dir=$(realpath $(dirname "$0"))
+bin_dir=$(realpath "$(dirname "$0")")
 top_dir=$(dirname "$bin_dir")
 
-[ "$LOG_FILE" ] || LOG_FILE="$top_dir/merge.log"
+if [ -z "$LOG_FILE" ]; then
+       LOG_FILE="$top_dir/merge.log"
+fi
+# "... appears unused"
+# shellcheck disable=SC2034
 SHA1_FILE="$top_dir/SHA1s"
 CTRL_FILE="$top_dir/etc/control"
 
 build_host="ash"
-build_dir="/home/sfr/next/next"
+build_dir="$HOME/next/next"
 gcc_version="4.9.0"
 j_factor=$(nproc)
+# "... appears unused"
+# shellcheck disable=SC2034
 gpg_key=89F91C0A41D5C07A
+# "... appears unused"
+# shellcheck disable=SC2034
 kup_gpg_key=015042F34957D06C
 
-[ "$NEXT_BUILD_HOST" ] && {
+if [ "$NEXT_BUILD_HOST" ]; then
        build_host="$NEXT_BUILD_HOST"
-       [ "$build_host" = "none" ] && build_host=""
-}
-[ "$NEXT_BUILD_DIR" ] && build_dir="$NEXT_BUILD_DIR"
-[ "$NEXT_GCC_VERSION" ] && gcc_version="$NEXT_GCC_VERSION"
+       if [ "$build_host" = "none" ]; then
+               build_host=""
+       fi
+fi
+if [ "$NEXT_BUILD_DIR" ]; then
+       build_dir="$NEXT_BUILD_DIR"
+fi
+if [ "$NEXT_GCC_VERSION" ]; then
+       gcc_version="$NEXT_GCC_VERSION"
+fi
 gcc_ppc_version=$gcc_version
-[ "$NEXT_GCC_PPC_VERSION" ] && gcc_ppc_version="$NEXT_GCC_PPC_VERSION"
+if [ "$NEXT_GCC_PPC_VERSION" ]; then
+       gcc_ppc_version="$NEXT_GCC_PPC_VERSION"
+fi
 gcc_ppcle_version=$gcc_ppc_version
-[ "$NEXT_GCC_PPCLE_VERSION" ] && gcc_ppcle_version="$NEXT_GCC_PPCLE_VERSION"
-[ "$NEXT_J_FACTOR" ] && j_factor="$NEXT_J_FACTOR"
+if [ "$NEXT_GCC_PPCLE_VERSION" ]; then
+       gcc_ppcle_version="$NEXT_GCC_PPCLE_VERSION"
+fi
+if [ "$NEXT_J_FACTOR" ]; then
+       j_factor="$NEXT_J_FACTOR"
+fi
 
-[ -n "$1" ] && {
-       build_host="$1"
-       shift
-}
-[ -n "$1" ] && {
-       build_dir="$1"
-       shift
-}
+if [ -z "$_next_common_no_args" ]; then
+       if [ -n "$1" ]; then
+               build_host="$1"
+               shift
+       fi
+       if [ -n "$1" ]; then
+               build_dir="$1"
+               shift
+       fi
+fi
 
 export NEXT_BUILD_HOST="${build_host:-none}"
 export NEXT_BUILD_DIR="$build_dir"
@@ -49,9 +73,65 @@ export NEXT_GCC_PPCLE_VERSION="$gcc_ppcle_version"
 export NEXT_J_FACTOR="$j_factor"
 
 # Support functions
+_TAB=$(printf '\t')
+
+get_control_field()
+{
+       awk -F "$_TAB" -v branch="$1" -v field="$2" '/^[^-#]/ && $3==branch { print $field; }' "$CTRL_FILE"
+}
+
+get_branches()
+{
+       awk -F "$_TAB" '/^[^-#]/ && $2=="git"{ print $3; }' "$CTRL_FILE"
+}
+
+get_pending_branches()
+{
+       awk -F "$_TAB" '/^[^-#]/ && $2=="git"{ print $3; } $1=="pending-fixes" { exit; }' "$CTRL_FILE"
+}
+
 get_contacts()
 {
-       awk -F '\t' '/^[^#]/ && $3=="'"$1"'" { print $1; }' $CTRL_FILE
+       get_control_field "$1" 1
+}
+
+get_type()
+{
+       get_control_field "$1" 2
+}
+
+get_url()
+{
+       get_control_field "$1" 4
+}
+
+get_remote_branch()
+{
+       get_control_field "$1" 5
+}
+
+get_build_flag()
+{
+       get_control_field "$1" 6
+}
+
+check_unmerged_files()
+{
+       # "In POSIX sh, 'local' is undefined."
+       # shellcheck disable=SC3043
+       local tree="$1"
+       # shellcheck disable=SC3043
+       local um_files
+       # shellcheck disable=SC3043
+       local rm_files
+
+       um_files=$(git diff 2>&1 | sed -n 's/^\* Unmerged path //p')
+       if [ "$um_files" ] && [ -f "../merge-files/$tree" ]; then
+               rm_files=$(grep -F "$um_files" "../merge-files/$tree")
+               if [ "$rm_files" ]; then
+                       "$bin_dir/do_rm" "$rm_files"
+               fi
+       fi
 }
 
 true