added scripts/{check-cvs-add,lib/Time/Zone.pm,log} to the scripts branch
[opensuse:kernel-source.git] / scripts / log
1 #! /bin/sh
2
3 # Construct a changes entry and commit log from a patch.
4
5 . ${0%/*}/wd-functions.sh
6
7 if ! $using_git; then
8     echo "ERROR: not in a git working directory."
9     exit 1
10 fi
11
12 scripts/check-cvs-add || exit 1
13
14 CHANGES=kernel-source.changes
15
16 message=$(mktemp /tmp/${0##*/}.XXXXXX)
17 trap "rm -f $message" EXIT
18
19 log_entry() {
20     local entry=$1
21
22     echo "$entry" \
23     | fmt --width 65 \
24     | sed -e '1s/^/- /' -e '2,$s/^/  /' \
25     >> $message
26 }
27
28 patch_log_entry() {
29     local patch=$1
30
31     if [ ! -e "$patch" ]; then
32         log_entry "$patch: "
33         return
34     fi
35
36     subject=$(formail -c -x Subject < "$patch" \
37              | sed -e 's, *\[[#/ A-Za-z0-9-]*\],,')
38     subject=${subject## }
39
40     set -- $(formail -c -x Suse-bugzilla < "$patch" \
41              | sed -e 's:\(#\?[0-9]\{5,\}\):#\1:g')
42     suse_bug="$*"
43     set -- $(formail -c -x References -x Reference < "$patch")
44     ref="$*"
45
46     references=${suse_bug}${suse_bug:+, }${ref}${ref:+, }
47     references=${references%, }
48
49     msg="$subject${references:+ ($references)}"
50     log_entry "$patch: $msg${msg:+.}"
51 }
52
53 for file in "$@" $(scripts/cvs-touched-files); do
54     [ "${file:(-8)}" = ".changes" ] && continue
55     files[${#files[@]}]=$file
56 done
57
58 if [ ${#files[@]} -eq 0 ]; then
59     echo "No modified files" >&2
60     exit 1
61 fi
62
63 for file in "${files[@]}"; do
64     if [ "${file:0:1}" = - ]; then
65         log_entry "${file:1}: Delete."
66     else
67         case "$file" in
68             config/*)
69                 if [ -z "$configs_updated" ]; then
70                     log_entry "Update config files."
71                     configs_updated=1
72                 fi
73                 ;;
74                 
75             patches.*)
76                 patch_log_entry "$file"
77                 ;;
78
79             kabi/*/symvers-*)
80                 if [ -z "$symvers_updated" ]; then
81                     log_entry "Update reference module symbol versions."
82                     symvers_updated=1
83                 fi
84                 ;;
85
86             series.conf)
87                 # don't log changes in there
88                 ;;
89
90             *)
91                 log_entry "$file: "
92                 ;;
93         esac
94     fi
95 done
96
97 if [ ! -s $message ]; then
98     echo "- " >> $message
99 fi
100
101 if [ -z "$VC" ]; then
102     VC=vc
103     for search in $HOME/bin /work/src/bin scripts; do
104         if [ -x $search/$VC ]; then
105             VC=$search/$VC
106             break
107         fi
108     done
109 fi
110
111 if $VC $CHANGES $message; then
112     entry=$(sed -ne '1,2d' -e '/^--*$/!p' -e '/^--*$/q' $CHANGES)
113     entry=${entry##$'\n'}
114     entry=${entry%%$'\n'}
115     echo "$entry" > $message
116
117     while :; do
118         echo
119         sed -e 's:^:| :' $message
120         echo
121         echo -n "Commit with the above changelog entry: ([y]es), [n]o, [e]dit? "
122         read yesno && \
123         case "$yesno" in
124             "" | [yY] | yes)
125                 git add $CHANGES
126                 # XXX don't commit -a?
127                 git commit -a -F $message || exit
128                 echo "after testing your changes, run"
129                 echo "    git push origin $(get_branch_name)"
130                 break ;;
131             [nN] | no)
132                 break ;;
133             [eE] | edit)
134                 ${EDITOR:-vi} $message
135                 ;;
136         esac
137     done
138 fi