Whamcloud - gitweb
b=23182 lustre-iokit sgpdd-survey defect
[fs/lustre-release.git] / build / diffatt.sh
1 #!/bin/bash
2 # diffatt.sh - generate inspection template for attachment
3 if [ -z "$1" ]; then
4         cat - 1>&2 <<- USAGE
5         usage: $0 [-k] {attachment} [attachment ...]
6            -k:  keep attachment(s) for editing (delete otherwise)
7            attachment is an attachment number or a local patch filename
8         USAGE
9         exit 1
10 fi
11
12 export LANG=C
13 BUGZILLA=https://bugzilla.lustre.org/attachment.cgi
14 TMP=${TMP:-/tmp}
15
16 [ "$1" = "-k" ] && KEEP=yes && shift
17
18 FILE=$(mktemp -t)
19
20 for ATT in $*; do
21         DO_KEEP=$KEEP
22         if [ -f "$ATT" ]; then
23                 PATCH=$ATT
24                 BUG=N
25                 DO_KEEP=yes
26         else
27                 BUG=$(wget --no-check-certificate -O - \
28                         $BUGZILLA?id=$ATT\&action=edit 2> /dev/null |
29                         perl -nle 'print $1 if /Details for Bug (\d+)/' -)
30                 PATCH=$TMP/att$ATT.patch
31                 wget --no-check-certificate -O $PATCH \
32                         $BUGZILLA?id=$ATT 2> /dev/null
33         fi
34
35         grep "not authorized" $PATCH && continue
36
37         diffstat $PATCH | tee $FILE
38         LOC=$(awk '/insertion/ { print $4 }' $FILE)
39         [ -z "$LOC" ] && LOC=$(awk '/deletion/ { print $4 }' $FILE)
40
41         # if it isn't a patch, just count all of the lines
42         [ -z "$LOC" ] && $(grep -q "0 files changed" $FILE) &&
43                 LOC=$(cat $PATCH | wc -l)
44
45         tee -a $PATCH <<- EOF
46                 Inspection Type: CODE
47                 Defect Count: N
48                 Size: $LOC LOC
49                 Developer: @sun.com
50                 Inspector: $USER@sun.com
51                 Inspection duration: N min
52                 Bug: $BUG
53                 Date: $(date +%Y-%m-%d)
54         EOF
55
56         [ "$DO_KEEP" = "yes" ] || rm $PATCH
57 done