From a29949f5469ff337ed09b0bcb5608710951e8381 Mon Sep 17 00:00:00 2001 From: Michael Bestas Date: Thu, 9 Jun 2022 22:47:13 +0300 Subject: [PATCH] aosp-merger: Implement subtree merge handling for pixels Change-Id: Idbb5427497d5d04766f8a37e7fa6e1264458dd29 --- aosp-merger/_subtree_merge_helper.sh | 107 +++++++++++++++++++++++++++ aosp-merger/aosp-merger.sh | 20 +++-- aosp-merger/squash.sh | 14 +++- aosp-merger/upload-squash.sh | 12 ++- 4 files changed, 135 insertions(+), 18 deletions(-) create mode 100755 aosp-merger/_subtree_merge_helper.sh diff --git a/aosp-merger/_subtree_merge_helper.sh b/aosp-merger/_subtree_merge_helper.sh new file mode 100755 index 0000000..fbf938f --- /dev/null +++ b/aosp-merger/_subtree_merge_helper.sh @@ -0,0 +1,107 @@ +#!/bin/bash +# +# SPDX-FileCopyrightText: 2017, 2020-2022 The LineageOS Project +# SPDX-FileCopyrightText: 2021-2022 The Calyx Institute +# +# SPDX-License-Identifier: Apache-2.0 +# + +usage() { + echo "Usage ${0} " +} + +# Verify argument count +if [ "$#" -ne 3 ]; then + usage + exit 1 +fi + +PROJECTPATH="${1}" +OLDTAG="${2}" +NEWTAG="${3}" + +### CONSTANTS ### +readonly script_path="$(cd "$(dirname "$0")";pwd -P)" +readonly vars_path="${script_path}/../../../vendor/lineage/vars" + +source "${vars_path}/common" + +readonly hook="${script_path}/prepare-commit-msg" + +TOP="${script_path}/../../.." +BRANCH="${lineageos_branch}" + +cd "${TOP}/${PROJECTPATH}" +# Ditch any existing staging branches +repo abandon "${STAGINGBRANCH}" . +repo start "${STAGINGBRANCH}" . +git fetch -q --force --tags "$(cat .gitupstream)" "${NEWTAG}" + +[[ ! -e .git/hooks/prepare-commit-msg ]] && cp "${hook}" .git/hooks/ +chmod +x .git/hooks/prepare-commit-msg + +# Was there any change upstream? Skip if not. +if [[ -z "$(git diff ${OLDTAG} ${NEWTAG})" ]]; then + echo -e "nochange\t\t${PROJECTPATH}" | tee -a "${MERGEDREPOS}" + repo abandon "${STAGINGBRANCH}" . + exit 0 +fi + +# Determine whether OLDTAG is an ancestor of NEWTAG +# ie is history consistent. +git merge-base --is-ancestor "${OLDTAG}" "${NEWTAG}" +# If no, print a warning message. +if [[ "$?" -eq 1 ]]; then + echo -n "#### Warning: project ${PROJECTPATH} old tag ${OLDTAG} is not an ancestor " + echo "of new tag ${NEWTAG} ####" +fi + +CONFLICT="" + +echo "#### Merging ${NEWTAG} into ${PROJECTPATH} ####" +git merge --no-commit --log "${NEWTAG}" + +if [[ -z "$(git diff HEAD)" ]]; then + echo "#### Skipping empty merge ####" + git reset --hard +else + git commit --no-edit + if [[ -n "$(git status --porcelain)" ]]; then + CONFLICT="conflict-" + fi + read -p "Waiting for conflict resolution before continuing. Press enter when done." + + echo $(git log -1 --pretty=%b | tail -2) > .git/CHANGE_ID +fi + +for subtree in `find -mindepth 2 -type f -name .gitupstream | cut -d / -f 2- | sed s#/.gitupstream##`; do + gitupstream="${subtree}/.gitupstream" + git fetch -q --force --tags "$(cat ${gitupstream})" "${NEWTAG}" + git merge -X subtree="$subtree" --no-commit --log "${NEWTAG}" + + if [[ -z "$(git diff HEAD)" ]]; then + echo "#### Skipping empty merge on ${subtree} ####" + git reset --hard + continue + fi + + git commit --no-edit + if [[ -n "$(git status --porcelain)" && -z "${CONFLICT}" ]]; then + CONFLICT="conflict-" + fi + read -p "Waiting for conflict resolution before continuing. Press enter when done." + + if [[ ! -f ".git/CHANGE_ID" ]]; then + echo $(git log -1 --pretty=%b | tail -2) > .git/CHANGE_ID + fi +done + +# Check if we've actually changed anything after the merge +# If we haven't, just abandon the branch +if [[ -z "$(git diff HEAD m/${lineageos_branch})" && -z "$(git status --porcelain)" ]]; then + echo -e "nochange\t\t${PROJECTPATH}" | tee -a "${MERGEDREPOS}" + repo abandon "${STAGINGBRANCH}" . + exit 0 +fi + +echo -e "${CONFLICT}merge\t\t${PROJECTPATH}" | tee -a "${MERGEDREPOS}" diff --git a/aosp-merger/aosp-merger.sh b/aosp-merger/aosp-merger.sh index ffa6e4b..21b4909 100755 --- a/aosp-merger/aosp-merger.sh +++ b/aosp-merger/aosp-merger.sh @@ -54,11 +54,11 @@ merge_aosp_forks() { } squash_aosp_merge() { - "${script_path}"/squash.sh merge "${prev_common_aosp_tag}" "${common_aosp_tag}" + "${script_path}"/squash.sh merge "${prev_common_aosp_tag}" "${common_aosp_tag}" false } upload_squash_aosp_to_review() { - "${script_path}"/upload-squash.sh merge "${prev_common_aosp_tag}" "${common_aosp_tag}" + "${script_path}"/upload-squash.sh merge "${prev_common_aosp_tag}" "${common_aosp_tag}" false } push_aosp_merge() { @@ -68,16 +68,16 @@ push_aosp_merge() { merge_pixel_device() { export STAGINGBRANCH="staging/${lineageos_branch}_merge-${aosp_tag}" for repo in ${device_repos[@]}; do - "${script_path}"/_merge_helper.sh "${repo}" merge "${prev_aosp_tag}" "${aosp_tag}" + "${script_path}"/_subtree_merge_helper.sh "${repo}" "${prev_aosp_tag}" "${aosp_tag}" done } squash_pixel_device() { - "${script_path}"/squash.sh merge "${prev_aosp_tag}" "${aosp_tag}" + "${script_path}"/squash.sh merge "${prev_aosp_tag}" "${aosp_tag}" true } upload_squash_device_to_review() { - "${script_path}"/upload-squash.sh merge "${prev_aosp_tag}" "${aosp_tag}" + "${script_path}"/upload-squash.sh merge "${prev_aosp_tag}" "${aosp_tag}" true } push_device_merge() { @@ -87,16 +87,16 @@ push_device_merge() { merge_pixel_kernel() { export STAGINGBRANCH="staging/${lineageos_branch}_merge-${kernel_tag}" for repo in ${device_kernel_repos}; do - "${script_path}"/_merge_helper.sh "${repo}" merge "${prev_kernel_tag}" "${kernel_tag}" + "${script_path}"/_subtree_merge_helper.sh "${repo}" "${prev_kernel_tag}" "${kernel_tag}" done } squash_pixel_kernel() { - "${script_path}"/squash.sh merge "${prev_kernel_tag}" "${kernel_tag}" + "${script_path}"/squash.sh merge "${prev_kernel_tag}" "${kernel_tag}" true } upload_squash_kernel_to_review() { - "${script_path}"/upload-squash.sh merge "${prev_kernel_tag}" "${kernel_tag}" + "${script_path}"/upload-squash.sh merge "${prev_kernel_tag}" "${kernel_tag}" true } push_kernel_merge() { @@ -164,9 +164,7 @@ main() { ( source "${vars_path}/${kernel}" - readonly manifest="${TOP}"/.repo/manifests/snippets/${kernel}.xml - readonly device_kernel_repos=$(grep "name=\"LineageOS/" "${manifest}" \ - | sed -n 's/.*path="\([^"]\+\)".*/\1/p') + readonly device_kernel_repos="kernel/google/${kernel}" export MERGEDREPOS="${TOP}/merged_repos_${kernel}.txt" # Remove any existing list of merged repos file diff --git a/aosp-merger/squash.sh b/aosp-merger/squash.sh index fbd8bd0..8d8b551 100755 --- a/aosp-merger/squash.sh +++ b/aosp-merger/squash.sh @@ -7,11 +7,11 @@ # usage() { - echo "Usage ${0} " + echo "Usage ${0} " } # Verify argument count -if [ "$#" -ne 3 ]; then +if [ "$#" -ne 4 ]; then usage exit 1 fi @@ -19,6 +19,7 @@ fi OPERATION="${1}" OLDTAG="${2}" NEWTAG="${3}" +PIXEL="${4}" if [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then usage @@ -59,7 +60,12 @@ for PROJECTPATH in ${PROJECTPATHS}; do repo abandon "${SQUASHBRANCH}" . git checkout -b "${SQUASHBRANCH}" "${STAGINGBRANCH}" git branch --set-upstream-to=m/"${BRANCH}" - git reset --soft HEAD~1 + git reset --soft m/"${BRANCH}" git add . - git commit -m "[SQUASH] $(git log ${STAGINGBRANCH} -1 --pretty=%s)" -m "$(git log ${STAGINGBRANCH} -1 --pretty=%b)" + if [ "${PIXEL}" = true ]; then + git commit -m "[SQUASH] Merge tag '${NEWTAG}' into ${STAGINGBRANCH}" -m "$(cat .git/CHANGE_ID)" + rm .git/CHANGE_ID + else + git commit -m "[SQUASH] $(git log ${STAGINGBRANCH} -1 --pretty=%s)" -m "$(git log ${STAGINGBRANCH} -1 --pretty=%b)" + fi done diff --git a/aosp-merger/upload-squash.sh b/aosp-merger/upload-squash.sh index 5874787..88cd390 100755 --- a/aosp-merger/upload-squash.sh +++ b/aosp-merger/upload-squash.sh @@ -7,11 +7,11 @@ # usage() { - echo "Usage ${0} " + echo "Usage ${0} " } # Verify argument count -if [ "$#" -ne 3 ]; then +if [ "$#" -ne 4 ]; then usage exit 1 fi @@ -19,6 +19,7 @@ fi OPERATION="${1}" OLDTAG="${2}" NEWTAG="${3}" +PIXEL="${4}" if [ "${OPERATION}" != "merge" -a "${OPERATION}" != "rebase" ]; then usage @@ -34,6 +35,11 @@ source "${vars_path}/common" TOP="${script_path}/../../.." BRANCH="${lineageos_branch}" SQUASHBRANCH="squash/${BRANCH}_${OPERATION}-${NEWTAG}" +if [ "${PIXEL}" = true ]; then + TOPIC="${topic}_pixel" +else + TOPIC="${topic}" +fi # List of merged repos PROJECTPATHS=$(cat ${MERGEDREPOS} | grep -w merge | awk '{printf "%s\n", $2}') @@ -56,5 +62,5 @@ for PROJECTPATH in ${PROJECTPATHS}; do cd "${TOP}/${PROJECTPATH}" echo "#### Pushing ${PROJECTPATH} squash to review ####" git checkout "${SQUASHBRANCH}" - repo upload -c -y --no-verify -o topic="${topic}" . + repo upload -c -y --no-verify -o topic="${TOPIC}" . done