hulk inclusion category: doc bugzilla: NA CVE: NA Link: https://gitee.com/openeuler/kernel/issues/I1SF7H
-------------------------------------------------
provide a simple script to help generate mainline patch info. It is useful when backport many patches from mainline or stable tree.
usage: 1) backport a patch from mainline ./scripts/pick -c <commit> --issue I1SF7H
2) insert patch info to exsit patch file ./scripts/pick -c <commit> --issue I1SF7H -i test.patch
3) backport a patch from stable branch ./scripts/pick -c <commit> -s --issue I1SF7H
4) insert patch info to a out-of-tree patch ./scripts/pick --from driver --issue I1SF7H -i 0001-driver.patch ./scripts/pick --from driver --cate feature --feat "xxx feature" --issue I1SF7H -i 0001-driver.patch
5) if the commit information is not provided in the argument, try to identify it from the input file. The following formats can be recognized: (cherry picked from commit 587a87b9d7e94927edcdea018565bc1939381eb1) commit 65caafd0d2145d1dd02072c4ced540624daeab40 upstream.
./scripts/pick --issue I1SF7H -i 0001-input.patch
Signed-off-by: Xie XiuQi xiexiuqi@huawei.com --- scripts/pick | 205 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100755 scripts/pick
diff --git a/scripts/pick b/scripts/pick new file mode 100755 index 000000000000..1166a300f508 --- /dev/null +++ b/scripts/pick @@ -0,0 +1,205 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# pick - helpers for pick a patch from upstream +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# (C) Copyright 2015-2020 Huawei Technologies Co., Ltd +# +# Authors: Xie XiuQi xiexiuqi@huawei.com + +# +# usage: +# 1) backport a patch from mainline +# ./scripts/pick -c <commit> --issue I1SF7H +# +# 2) insert patch info to exsit patch file +# ./scripts/pick -c <commit> --issue I1SF7H -i test.patch +# +# 3) backport a patch from stable branch +# ./scripts/pick -c <commit> -s --issue I1SF7H +# +# 4) insert patch info to a out-of-tree patch +# ./scripts/pick --from driver --issue I1SF7H -i 0001-driver.patch +# ./scripts/pick --from driver --cate feature --feat "xxx feature" --issue I1SF7H -i 0001-driver.patch +# +# 5) if the commit information is not provided in the argument, +# try to identify it from the input file. +# The following formats can be recognized: +# (cherry picked from commit 587a87b9d7e94927edcdea018565bc1939381eb1) +# commit 65caafd0d2145d1dd02072c4ced540624daeab40 upstream. +# +# ./scripts/pick --issue I1SF7H -i 0001-input.patch +# + +# set -x + +COMMIT= +CVE=NA +BUG=NA +ISSUE=NA +WITH_ISSUE=0 +ISSUE_PREFIX=https://gitee.com/openeuler/kernel/issues +OUTPUT_PREFIX= +OUTPUT= +FROM=mainline # default +CATEGORY=bugfix # default +FEATURE="" +SUBJECT_PREFIX= +WITH_SOB= +INSERT_LINE=0 + +usage() +{ + echo "usage: $(basename $0) [options]" >&2 + echo " -h|--help show this help message" >&2 + echo " -s|--stable from stable (default mainline)" >&2 + echo " -f|--from where does the patch from (default mainline)" >&2 + echo " -C|--cve ID of CVE (without CVE prefix)" >&2 + echo " --cate category(feature/bugfix/...)" >&2 + echo " --feat feature" >&2 + echo " --subject-prefix " >&2 + echo " -b|--bugzilla ID of BUGZILLA" >&2 + echo " --issue issue id of gitee" >&2 + echo " -o|--output output filename, use input filename if no specific" >&2 + echo " -i|--input input patch filename" >&2 + echo " --output-prefix output filename" >&2 + echo " --with-sob with signed-off-by" >&2 + echo " -c|--commit <commit id>" >&2 +} + +options=$(getopt -o hr:u:c: "help,pick,stable,from:bugzilla:cate:feat:cve:commit" -- "$@") || die "getopt failed" + +eval set -- "$options" +while [[ $# -gt 0 ]]; do + case "$1" in + -h|--help) + usage + exit 0 + ;; + -f|--from) + FROM="$2" + shift + ;; + -s|--stable) + FROM="stable" + ;; + -C|--cve) + CVE="$2" + shift + ;; + --cate) + CATEGORY="$2" + shift + ;; + --feat) + FEATURE="$2" + shift + ;; + --subject-prefix) + SUBJECT_PREFIX=" $2" + shift + ;; + --with-sob) + WITH_SOB="-s" + ;; + -b|--bugzilla) + BUG="$2" + shift + ;; + --issue) + ISSUE=$2 + WITH_ISSUE=1 + shift + ;; + -i|--input) + INPUT=$2 + shift + ;; + -u|--utf8) + UTF8=1 + ;; + -c|--commit) + COMMIT=$2 + shift + ;; + esac + shift +done + +if [ -z "$COMMIT" ] && [ -z "$INPUT" ]; then + echo 'Your must specific at least commit or input filename' + exit 1 +fi + +if [ "$INPUT" != "" ] && [ "$COMMIT" == "" ]; then + COMMIT=$(grep "^(cherry picked from commit" $INPUT | sed 's/^(cherry picked from commit ([a-f0-9]*).*/\1/g') + + if [ "$COMMIT" == "" ]; then + COMMIT=$(grep "^commit [a-f0-9]* upstream" $INPUT | sed 's/^commit ([a-f0-9]*).*/\1/g') + fi +fi + +if [ "$PREFIX" != "" ]; then + PREFIX="[$PREFIX] " +fi + +if [ $(echo $CVE |grep CVE -c) -eq 0 ] && [ "$CVE" != "NA" ]; then + CVE=CVE-$CVE +fi + +TAG=$(git name-rev --tags $COMMIT |sed 's/^[a-f0-9]* tags/v//g' | sed 's/~.*//' | sed 's/-.*//') + +trap 'rm -f "$TMPFILE"' EXIT +TMPFILE=$(mktemp) || exit 1 + +printf "%s\n" "$FROM inclusion" >> $TMPFILE +if [ $FROM == "mainline" ] || [ "$FROM" == "stable" ]; then + printf "%s\n" "from $FROM-$TAG" >> $TMPFILE + printf "%s\n" "commit $COMMIT" >> $TMPFILE +fi +printf "%s\n" "category: $CATEGORY" >> $TMPFILE + +if [ "$CATEGORY" == "feature" ]; then + if [ "$FEATURE" == "" ]; then + echo "please describe this feature" + exit 1 + else + printf "%s\n" "feature: $FEATURE" >> $TMPFILE + fi +fi + +printf "%s\n" "bugzilla: $BUG" >> $TMPFILE +printf "%s\n" "CVE: $CVE" >> $TMPFILE + +if [ "$BUG" == "NA" ] && [ "$ISSUE" == "NA" ]; +then + echo please set bugzilla id or issue id + exit 1 +fi + +if [ $WITH_ISSUE -eq 1 ] && [ "$ISSUE" != "" ]; then + printf "%s\n" "Link: $ISSUE_PREFIX/$ISSUE" >> $TMPFILE +fi + +printf "\n%s\n\n" "-------------------------------------------------" >> $TMPFILE + +if [ -z $INPUT ]; then + INPUT=$(git format-patch -1 $WITH_SOB --subject-prefix="PATCH$SUBJECT_PREFIX" $COMMIT) +fi + +if [ -z $OUTPUT ]; then + OUTPUT=$INPUT +fi + +INSERT_LINE=$(sed -n -e '/^$/=' $INPUT |head -n1) +sed -i "$INSERT_LINE"r" $TMPFILE" $OUTPUT