File indexing completed on 2024-05-19 04:32:38
0001 #!/bin/bash 0002 # 0003 # SPDX-License-Identifier: GPL-3.0-or-later 0004 # 0005 0006 # A POSIX variable 0007 # Reset in case getopts has been used previously in the shell. 0008 OPTIND=1 0009 0010 # Initialize our own variables: 0011 ALL_COMMITS=0 0012 SINCE_ARG= 0013 UNTIL_ARG= 0014 ARS=() 0015 0016 OPTIONS=as:u: 0017 0018 function print_usage { 0019 echo "Usage: $0 [-a] [-s SINCE] [-u UNTIL]" 0020 } 0021 0022 while getopts "h?as:u:" opt; do 0023 case "$opt" in 0024 h|\?) 0025 print_usage 0026 exit 0 0027 ;; 0028 a) 0029 ALL_COMMITS=1 0030 ;; 0031 s) 0032 ARGS+=(--since="$OPTARG") 0033 ;; 0034 u) 0035 ARGS+=(--until="$OPTARG") 0036 ;; 0037 *) 0038 print_usage 0039 exit 1 0040 ;; 0041 esac 0042 done 0043 0044 shift $((OPTIND-1)) 0045 [ "${1:-}" = "--" ] && shift 0046 0047 git fetch 0048 0049 BRANCHNAME=`git rev-parse --abbrev-ref HEAD` 0050 INITIAL_SHA1=`git rev-parse HEAD` 0051 0052 LOGFILE=`tempfile -p log` 0053 COMMITSLIST=`tempfile -p commits` 0054 PICKCOMMITSLIST=`tempfile -p pick` 0055 0056 if [ $ALL_COMMITS -gt 0 ]; then 0057 # check for **all** commits that were not yet backported from master 0058 git log --right-only --no-merges --pretty=medium --cherry-pick \ 0059 "${ARGS[@]}" \ 0060 HEAD...origin/master > $LOGFILE 0061 else 0062 # check for commits containing BACKPORT keyword that were not 0063 # yet backported from master 0064 git log --right-only --no-merges --pretty=medium --cherry-pick \ 0065 "${ARGS[@]}" \ 0066 --grep="BACKPORT:.*\\b$BRANCHMANE\\b.*" HEAD...origin/master > $LOGFILE 0067 fi 0068 0069 sed -E '/^commit [0-9a-f]+$/!s/^/#/' $LOGFILE > $COMMITSLIST 0070 0071 $EDITOR $COMMITSLIST 0072 0073 sed -nE 's/^commit ([0-9a-f]+)$/\1/p' $COMMITSLIST > $PICKCOMMITSLIST 0074 0075 if [ ! -s $PICKCOMMITSLIST ]; then 0076 echo "List of cherry-picked commits is empty. Aborting..." 0077 else 0078 NUMCOMMITS=$(wc -l $PICKCOMMITSLIST | cut -d' ' -f1) 0079 echo "Start cherry picking $NUMCOMMITS commits" 0080 cat $PICKCOMMITSLIST | xargs git cherry-pick -x 0081 fi 0082 0083 rm $LOGFILE 0084 rm $COMMITSLIST 0085 rm $PICKCOMMITSLIST 0086