1#!/bin/bash 2# 3# Script to cherry-pick 'IMPORT:' CLs. Needed since the Android cherry-picker 4# can't handle binary files. 5# 6# Copyright (C) 2024 The Android Open Source Project 7# 8# Licensed under the Apache License, Version 2.0 (the "License"); 9# you may not use this file except in compliance with the License. 10# You may obtain a copy of the License at 11# 12# http://www.apache.org/licenses/LICENSE-2.0 13# 14# Unless required by applicable law or agreed to in writing, software 15# distributed under the License is distributed on an "AS IS" BASIS, 16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17# See the License for the specific language governing permissions and 18# limitations under the License. 19 20# Prerequisites: 21# 22# * Be running in AOSP external/linux-firmware 23# * git remote add goog sso://googleplex-android/platform/external/linux-firmware 24# * "repo start" a branch for the IMPORT CLs to be picked. 25 26set -e 27 28# We'll use these as temp files. Could use `mktemp` but not worth it... 29aosp_changes=_aosp.txt 30goog_changes=_goog.txt 31 32rm -f "${aosp_changes}" 33rm -f "${goog_changes}" 34 35echo "Fetching..." 36git fetch aosp main 37git fetch goog main 38 39git log --reverse --format=%B --grep='^IMPORT:' aosp/main | grep '^Change-Id:' > "${aosp_changes}" || true 40git log --reverse --format=%B --grep='^IMPORT:' goog/main | grep '^Change-Id:' > "${goog_changes}" || true 41 42declare -A already_picked_dict 43for change_id in $(cat "${aosp_changes}"); do 44 already_picked_dict["${change_id}"]=1 45done 46 47echo 48echo "Picking..." 49 50for change_id in $(cat "${goog_changes}"); do 51 if [[ -n "${already_picked_dict["${change_id}"]}" ]]; then 52 continue 53 fi 54 55 hash="$(git log --format=%H --grep="^Change-Id: ${change_id}" goog/main)" 56 echo "Picking $(git log --oneline -1 ${hash})" 57 58 git cherry-pick "${hash}" > /dev/null 59 commit_message="$(git show -s --format=%B HEAD | 60 sed "s|Change-Id: ${change_id}|(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:${hash})\nMerged-In: ${change_id}\nChange-Id: ${change_id}|" 61 )" 62 echo "${commit_message}" | git commit -n --amend -F - > /dev/null 63done 64 65rm -f "${aosp_changes}" 66rm -f "${goog_changes}" 67