param_key: fix container of when no struct member is referenced
[smatch.git] / smatch_scripts / kpatch.sh
blob66cef9581ca0972fab370c37c90394839e95d691
1 #!/bin/bash -e
3 TMP_DIR=/tmp
5 help()
7 echo "Usage: $0 [--no-compile|--amend] <filename>"
8 echo "You must be at the base of the kernel tree to run this."
9 exit 1
12 continue_yn()
14 echo -n "Do you want to fix these issues now? "
15 read ans
16 if ! echo $ans | grep -iq ^n ; then
17 exit 1;
21 qc()
23 local msg=$1
24 local ans
26 echo -n "$msg: "
27 read ans
28 if ! echo $ans | grep -qi ^y ; then
29 exit 1
33 NO_COMPILE=false
34 AMEND=""
36 NAME=$(git config --get user.name)
37 EMAIL=$(git config --get user.email)
38 NAME_EMAIL=$(echo ${NAME} \<${EMAIL}\>)
40 while true ; do
41 if [[ "$1" == "--no-compile" ]] ; then
42 NO_COMPILE=true
43 shift
44 elif [[ "$1" == "--amend" ]] ; then
45 AMEND="--amend"
46 shift
47 else
48 break
50 done
52 if [ ! -f $1 ] ; then
53 help
56 fullname=$1
57 filename=$(basename $fullname)
58 oname=$(echo ${fullname/.c/.o})
60 MSG_FILE=$TMP_DIR/${filename}.msg
61 MAIL_FILE=$TMP_DIR/${filename}.mail
62 WARN_FILE=$TMP_DIR/${filename}.warn
64 # heat up the disk cache
65 #git log --oneline $fullname | head -n 10 > /dev/null &
67 echo "QC checklist"
68 qc "Have you handled all the errors properly?"
69 if git diff $fullname | grep ^+ | grep -qi alloc ; then
70 qc "Have you freed all your mallocs?"
72 if git diff $fullname | grep ^+ | grep -qi alloc ; then
73 qc "Have you check all your mallocs for NULL returns?"
76 if [ "$NO_COMPILE" != "true" ] ; then
77 kchecker --spammy $fullname | tee $WARN_FILE
78 kchecker --sparse --endian $fullname 2>&1 | tee -a $WARN_FILE
79 # rm $oname
80 # make C=1 CHECK="scripts/coccicheck" $oname
83 for file in $(grep -l $fullname ~/var/mail/sent-*) ; do
84 grepmail $fullname $file | grep -i ^subject || echo -n ""
85 done
86 qc "Looks OK?"
88 cat /dev/null > $MSG_FILE
89 if [ "$AMEND" != "" ] ; then
90 git format-patch HEAD^ --stdout >> $MSG_FILE
91 else
92 echo "" >> $MSG_FILE
93 echo "Signed-off-by: ${NAME_EMAIL}" >> $MSG_FILE
94 echo "" >> $MSG_FILE
95 echo "# $sm_err" >> $MSG_FILE
97 git log -10 --oneline --format="%h (\"%s\")" $fullname | sed -e 's/^/# /' >> $MSG_FILE
98 echo "" >> $MSG_FILE
99 egrep '(error|warn|info)' $WARN_FILE | sed -e 's/^/# /' >> $MSG_FILE
100 git diff $fullname | sed -e 's/^/# /' >> $MSG_FILE
101 vim $MSG_FILE
103 grep -v '^#' $MSG_FILE > $MSG_FILE.1
104 mv $MSG_FILE.1 $MSG_FILE
106 git add $fullname
107 git commit $AMEND -F $MSG_FILE
109 git format-patch HEAD^ --stdout >> $MSG_FILE
111 to_addr=$(./scripts/get_maintainer.pl --noroles --norolestats $MSG_FILE | head -n 1)
112 cc_addr=$(./scripts/get_maintainer.pl --noroles --norolestats $MSG_FILE | tail -n +2 | \
113 perl -ne 's/\n$/, /; print')
114 cc_addr="$cc_addr, kernel-janitors@vger.kernel.org"
116 echo -n "To: " > $MAIL_FILE
117 echo "$to_addr" >> $MAIL_FILE
118 echo -n "CC: " >> $MAIL_FILE
119 echo "$cc_addr" >> $MAIL_FILE
120 echo "X-Mailer: git-send-email haha only kidding" >> $MAIL_FILE
122 git format-patch HEAD^ --stdout >> $MAIL_FILE
124 ./scripts/checkpatch.pl $MAIL_FILE || continue_yn
126 echo "Press ENTER to continue"
127 read unused
129 mutt -H $MAIL_FILE
130 rm -f $MSG_FILE
131 rm -f $WARN_FILE