2018-10-07 03:58:27 +02:00
|
|
|
#!/usr/bin/env bash
|
util/: Replace GPLv2 boiler plate with SPDX header
Used commands:
perl -i -p0e 's|\/\*[\s*]*.*is free software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and\/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-2.0-only */|' $(cat filelist)
perl -i -p0e 's|This[\s*]*program[\s*]*is[\s*]*free[\s*]*software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*either[\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License,[\s*]*or[\s*]*.at[\s*]*your[\s*]*option.*[\s*]*any[\s*]*later[\s*]*version.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-2.0-or-later */|' $(cat filelist)
perl -i -p0e 's|\/\*[\s*]*.*This[\s*#]*program[\s*#]*is[\s*#]*free[\s*#]*software[;:,][\s*#]*you[\s*#]*can[\s*#]*redistribute[\s*#]*it[\s*#]*and/or[\s*#]*modify[\s*#]*it[\s*#]*under[\s*#]*the[\s*#]*terms[\s*#]*of[\s*#]*the[\s*#]*GNU[\s*#]*General[\s*#]*Public[\s*#]*License[\s*#]*as[\s*#]*published[\s*#]*by[\s*#]*the[\s*#]*Free[\s*#]*Software[\s*#]*Foundation[;:,][\s*#]*either[\s*#]*version[\s*#]*3[\s*#]*of[\s*#]*the[\s*#]*License[;:,][\s*#]*or[\s*#]*.at[\s*#]*your[\s*#]*option.*[\s*#]*any[\s*#]*later[\s*#]*version.[\s*#]*This[\s*#]*program[\s*#]*is[\s*#]*distributed[\s*#]*in[\s*#]*the[\s*#]*hope[\s*#]*that[\s*#]*it[\s*#]*will[\s*#]*be[\s*#]*useful[;:,][\s*#]*but[\s*#]*WITHOUT[\s*#]*ANY[\s*#]*WARRANTY[;:,][\s*#]*without[\s*#]*even[\s*#]*the[\s*#]*implied[\s*#]*warranty[\s*#]*of[\s*#]*MERCHANTABILITY[\s*#]*or[\s*#]*FITNESS[\s*#]*FOR[\s*#]*A[\s*#]*PARTICULAR[\s*#]*PURPOSE.[\s*#]*See[\s*#]*the[\s*#]*GNU[\s*#]*General[\s*#]*Public[\s*#]*License[\s*#]*for[\s*#]*more[\s*#]*details.[\s*]*\*\/|/* SPDX-License-Identifier: GPL-3.0-or-later */|' $(cat filelist)
perl -i -p0e 's|(\#\#*)[\w]*.*is free software[:;][\#\s]*you[\#\s]*can[\#\s]*redistribute[\#\s]*it[\#\s]*and\/or[\#\s]*modify[\#\s]*it[\s\#]*under[\s \#]*the[\s\#]*terms[\s\#]*of[\s\#]*the[\s\#]*GNU[\s\#]*General[\s\#]*Public[\s\#]*License[\s\#]*as[\s\#]*published[\s\#]*by[\s\#]*the[\s\#]*Free[\s\#]*Software[\s\#]*Foundation[;,][\s\#]*version[\s\#]*2[\s\#]*of[\s\#]*the[\s\#]*License.*[\s\#]*This[\s\#]*program[\s\#]*is[\s\#]*distributed[\s\#]*in[\s\#]*the[\s\#]*hope[\s\#]*that[\s\#]*it[\s\#]*will[\#\s]*be[\#\s]*useful,[\#\s]*but[\#\s]*WITHOUT[\#\s]*ANY[\#\s]*WARRANTY;[\#\s]*without[\#\s]*even[\#\s]*the[\#\s]*implied[\#\s]*warranty[\#\s]*of[\#\s]*MERCHANTABILITY[\#\s]*or[\#\s]*FITNESS[\#\s]*FOR[\#\s]*A[\#\s]*PARTICULAR[\#\s]*PURPOSE.[\#\s]*See[\#\s]*the[\#\s]*GNU[\#\s]*General[\#\s]*Public[\#\s]*License[\#\s]*for[\#\s]*more[\#\s]*details.\s(#* *\n)*|\1 SPDX-License-Identifier: GPL-2.0-only\n\n|' $(cat filelist)
perl -i -p0e 's|(\#\#*)[\w*]*.*is free software[:;][\s*]*you[\s*]*can[\s*]*redistribute[\s*]*it[\s*]*and\/or[\s*]*modify[\s*]*it[\s*]*under[\s*]*the[\s*]*terms[\s*]*of[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*as[\s*]*published[\s*]*by[\s*]*the[\s*]*Free[\s*]*Software[\s*]*Foundation[;,][\s*]*version[\s*]*2[\s*]*of[\s*]*the[\s*]*License.[\s*]*This[\s*]*program[\s*]*is[\s*]*distributed[\s*]*in[\s*]*the[\s*]*hope[\s*]*that[\s*]*it[\s*]*will[\s*]*be[\s*]*useful,[\s*]*but[\s*]*WITHOUT[\s*]*ANY[\s*]*WARRANTY;[\s*]*without[\s*]*even[\s*]*the[\s*]*implied[\s*]*warranty[\s*]*of[\s*]*MERCHANTABILITY[\s*]*or[\s*]*FITNESS[\s*]*FOR[\s*]*A[\s*]*PARTICULAR[\s*]*PURPOSE.[\s*]*See[\s*]*the[\s*]*GNU[\s*]*General[\s*]*Public[\s*]*License[\s*]*for[\s*]*more[\s*]*details.\s(#* *\n)*|\1 SPDX-License-Identifier: GPL-2.0-only\n\n|' $(cat filelist)
Change-Id: I1008a63b804f355a916221ac994701d7584f60ff
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/41177
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2020-05-08 20:48:04 +02:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
2016-10-24 11:58:07 +02:00
|
|
|
|
2016-09-22 12:46:45 +02:00
|
|
|
# $0 from-branch to-branch
|
2016-10-24 11:58:07 +02:00
|
|
|
#
|
2016-09-22 12:46:45 +02:00
|
|
|
# applies all commits that from-branch has over to-branch,
|
|
|
|
# based on a common ancestor and gerrit meta-data
|
|
|
|
from=$1
|
|
|
|
to=$2
|
|
|
|
|
|
|
|
# match string: this is the git commit line that is used to
|
|
|
|
# identify commits that were already copied over.
|
|
|
|
#
|
|
|
|
# Must not contain spaces except for leading and trailing.
|
|
|
|
#
|
|
|
|
# The first pick was Change-Id, but it was lost too often,
|
|
|
|
# so go for Reviewed-on instead. It's also unique because it
|
|
|
|
# contains the gerrit instance's host name and the change's number
|
|
|
|
# on that system.
|
2017-06-13 15:14:09 +02:00
|
|
|
match_string='[-A-Za-z]*[Rr]eviewed-on:'
|
|
|
|
|
|
|
|
# Custom root: allow a certain CL (identified by matching either side's
|
|
|
|
# match_string) to be the new root, instead of using git's common history only.
|
|
|
|
# This allows cutting down on commits that are re-evaluated on every run.
|
|
|
|
#
|
|
|
|
# Use:
|
|
|
|
# To the commit message of a commit on the "to" side, add
|
|
|
|
# $custom_root: match_string (the part coming after $match_string)
|
|
|
|
#
|
|
|
|
# For a $match_string of ~ "Reviewed-on: " this might
|
|
|
|
# be "$custom_root: https://example.com/12345"
|
|
|
|
#
|
|
|
|
# On traversal, the commit with "$match_string: https://example.com/12345"
|
|
|
|
# is then considered a base commit.
|
|
|
|
custom_root='^Gerrit-Rebase-Ignore-CLs-Before:'
|
2016-09-22 12:46:45 +02:00
|
|
|
|
|
|
|
# fetch common ancestor
|
|
|
|
common_base=$(git merge-base ${from} ${to} 2>/dev/null)
|
|
|
|
|
|
|
|
if [ -z "${common_base}" ]; then
|
|
|
|
echo \"${from}\" or \"${to}\" is not a valid branch name.
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-06-13 15:14:09 +02:00
|
|
|
from_base=$common_base
|
|
|
|
|
|
|
|
# fetch custom root ID
|
|
|
|
croot_marker=$(git log --pretty=%b -1 --grep "${custom_root}" \
|
|
|
|
${common_base}..${to} | \
|
|
|
|
grep "${custom_root}" | cut -d: -f2-)
|
|
|
|
if [ -n "${croot_marker}" ]; then
|
|
|
|
from_base=$( ( \
|
|
|
|
git log --pretty=%H -1 \
|
|
|
|
--grep "^${match_string}${croot_marker}" \
|
|
|
|
${from_base}..${from}; echo ${from_base} )| head -1)
|
|
|
|
fi
|
|
|
|
|
2016-09-22 12:46:45 +02:00
|
|
|
# collect matches that are present on the target side
|
|
|
|
to_matches="$(git log ${common_base}..${to} | \
|
2017-06-13 15:14:09 +02:00
|
|
|
grep "^ ${match_string}" | \
|
2016-09-22 12:46:45 +02:00
|
|
|
cut -d: -f2-)"
|
|
|
|
|
|
|
|
# start rebase process, but fail immediately by enforcing an invalid todo
|
2020-03-09 10:15:39 +01:00
|
|
|
GIT_SEQUENCE_EDITOR="echo 'Ignore this error, it works around a git-rebase limitation'>" \
|
2016-09-22 12:46:45 +02:00
|
|
|
git rebase -i --onto ${to} ${from} ${to} 2>/dev/null
|
|
|
|
|
|
|
|
# write new rebase todo
|
|
|
|
# the appended "commit" line triggers handling of the last log entry
|
|
|
|
commit=""
|
2017-06-13 15:14:09 +02:00
|
|
|
(git log --reverse ${from_base}..${from} | \
|
|
|
|
grep -E "(^commit [0-9a-f]{40}\$|^ ${match_string})"; \
|
2016-09-22 12:46:45 +02:00
|
|
|
echo "commit") | \
|
|
|
|
while read key value; do
|
|
|
|
if [ "${key}" = "commit" ]; then
|
|
|
|
if [ -n "${commit}" ]; then
|
|
|
|
git log -n 1 --pretty="pick %h %s" ${commit}
|
|
|
|
fi
|
|
|
|
commit="${value}"
|
|
|
|
else
|
|
|
|
# if value was already found on the "to" side, skip this
|
|
|
|
# commit
|
|
|
|
if [[ ${to_matches} == *"${value}"* ]]; then
|
|
|
|
commit=""
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done | GIT_SEQUENCE_EDITOR="cat >" git rebase --edit-todo
|
|
|
|
|
|
|
|
# allow user to edit todo
|
|
|
|
git rebase --edit-todo
|
|
|
|
|
|
|
|
# start processing todo to mimick git rebase -i behavior
|
|
|
|
git rebase --continue
|