From b6cd7fbabe2dd220f1906762823e6b4cd143aef3 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Mon, 16 Sep 2024 20:46:11 +0200 Subject: [PATCH] build/sync: turn the port_dir_mfc script into a 'sync' step --- Makefile | 4 +- README.md | 11 ++- build/skim.sh | 2 +- scripts/port_dir_mfc.sh => build/sync.sh | 93 +++++++++++++----------- 4 files changed, 65 insertions(+), 45 deletions(-) rename scripts/port_dir_mfc.sh => build/sync.sh (56%) diff --git a/Makefile b/Makefile index 83f6766..52ac4d4 100644 --- a/Makefile +++ b/Makefile @@ -26,8 +26,8 @@ STEPS= audit arm base boot chroot clean clone compress confirm \ connect core distfiles download dvd fingerprint info \ kernel list make.conf nano options packages plugins ports \ - prefetch print rebase release rename serial sign \ - skim test update upload verify vga vm xtools + prefetch print rebase release rename serial sign skim \ + sync test update upload verify vga vm xtools SCRIPTS= custom distribution factory hotfix nightly watch .PHONY: ${STEPS} ${SCRIPTS} diff --git a/README.md b/README.md index a9b4780..d331c90 100644 --- a/README.md +++ b/README.md @@ -371,7 +371,7 @@ Available clean options are: * vm: remove vm image * xtools: remove xtools set -How the port tree is synced with its upstream repository +How the port tree is updated via its upstream repository -------------------------------------------------------- The ports tree has a few of our modifications and is sometimes a @@ -422,6 +422,15 @@ for standalone use on the host use: # make make.conf +Syncing a ports branch from PORTSDIR +------------------------------------ + +When maintaining branches the master branch holds updates that +we want to cherry-pick to another branch. To ease the process +the sync step can deal with the complexity involved: + + # make sync-category/port[,category/port[,...]] + Reading and modifying version numbers of build sets and images -------------------------------------------------------------- diff --git a/build/skim.sh b/build/skim.sh index ec4b95a..978bd12 100644 --- a/build/skim.sh +++ b/build/skim.sh @@ -27,8 +27,8 @@ set -e -SELF=skim FROM=FreeBSD +SELF=skim . ./common.sh diff --git a/scripts/port_dir_mfc.sh b/build/sync.sh similarity index 56% rename from scripts/port_dir_mfc.sh rename to build/sync.sh index 24ade3d..61d898f 100755 --- a/scripts/port_dir_mfc.sh +++ b/build/sync.sh @@ -27,52 +27,63 @@ set -e -DIR=${1:-.} -BRANCH=${2:-master} FROM=FreeBSD +SELF=sync -if git diff --quiet ${BRANCH} ${DIR}; then - echo ">>> Cherry-pick already complete." - exit 0 -fi +. ./common.sh -echo -n ">>> Run a git-cherry-pick or raw merge? [r/G]: " +GIT="git -C ${PORTSDIR}" -read YN < /dev/tty -case ${YN} in -[rR]) - git diff -R ${BRANCH} ${DIR} | git apply - git add ${DIR} - git commit -m \ -"${DIR}: sync with upstream +for ARG in ${@}; do + # ARG should be "category/name" but not strictly checked -Taken from: ${FROM}" - exit 0 - ;; -*) - # FALLTHROUGH - ;; -esac - -COMMITS= - -for HASH in $(git log --oneline ${BRANCH} ${DIR} | awk '{ print $1 }'); do - if git diff --quiet ${HASH} ${DIR}; then - # found no more changes - break + if [ ! -d ${PORTSDIR}/${ARG} ]; then + echo ">>> Sync did not find the port ${ARG}" >&2 + exit 1 fi - # reverse commit order for cherry-pick - COMMITS="${HASH} ${COMMITS}" + if ${GIT} diff --quiet ${PORTSBRANCH} ${ARG}; then + echo ">>> Sync already complete for ${ARG}" + continue + fi + + + COMMITS= + + for HASH in $(${GIT} log --oneline ${PORTSBRANCH} ${ARG} | \ + awk '{ print $1 }'); do + if ${GIT} diff --quiet ${HASH} ${ARG}; then + # found no more changes + break + fi + + # reverse commit order for cherry-pick + COMMITS="${HASH} ${COMMITS}" + done + + FAILED= + + for COMMIT in ${COMMITS}; do + if ! (${GIT} cherry-pick ${COMMIT} || \ + ${GIT} cherry-pick --skip); then + FAILED=yes + break + fi + done + + if [ -n "${FAILED}" ]; then + ${GIT} diff -R ${PORTSBRANCH} ${ARG} | ${GIT} apply + ${GIT} add ${ARG} + ${GIT} commit -m \ +"${ARG}: sync with upstream + +Taken from: ${FROM}" + fi + + if ! ${GIT} diff --quiet ${PORTSBRANCH} ${ARG}; then + echo ">>> Sync failed due to non-emtpy diff for ${ARG}" >&2 + exit 1 + fi + + echo ">>> Sync succeeded for ${ARG}" done - -for COMMIT in ${COMMITS}; do - git cherry-pick ${COMMIT} || git cherry-pick --skip -done - -if ! git diff --quiet ${BRANCH} ${DIR}; then - echo ">>> Cherry-pick failed due to non-emtpy diff." >&2 - exit 1 -fi - -echo ">>> Cherry-pick finished successfully."