1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
#! /bin/sh
#############################################################################
# Copyright (c) 2004-2006,2008-2010 Novell, Inc.
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com
#############################################################################
# git commit wrapper, generates unified commit messages from patch headers
. ${0%/*}/wd-functions.sh
if ! $using_git; then
echo "ERROR: not in a git working directory."
exit 1
fi
scripts/check-cvs-add || exit 1
trap 'rm -rf "$tmpdir"' EXIT
tmpdir=$(mktemp -d /tmp/${0##*/}.XXXXXX)
log_entry() {
local entry=$1
echo "$entry" | fmt --width 65 | sed -e '1s/^/- /' -e '2,$s/^/ /'
}
patch_meta() {
local patch=$1
subject=$(formail -c -x Subject < "$patch" \
| sed -e 's, *\[[#/ A-Za-z0-9-]*\],,')
subject=${subject## }
subject=${subject%.}
# allow one blank line before the References: header
set -- $(awk '
/^References?:/ { sub(/^References?:/, ""); print; exit }
/^$/ { if (++blank > 1) exit }' "$patch")
references="$*"
case "$references" in
None | none)
references=
esac
}
patch_log_entry() {
local patch=$1 subject references old_subj old_ref old_patch="$tmpdir/old"
git show "HEAD:$patch" >"$old_patch" 2>/dev/null
patch_meta "$old_patch"
old_subj="$subject"
old_ref="$references"
patch_meta "$patch"
if test -z "$subject"; then
# should not happen
log_entry "$patch: ${references:+($references).}"
elif test "$subject" != "$old_subj"; then
log_entry "$subject${references:+ ($references)}."
elif test "$references" != "$old_ref"; then
# a new bugzilla reference suggest a non-trivial change
log_entry "Update $patch${references:+ ($references)}."
else
log_entry "Refresh $patch."
fi
}
do_commit()
{
local message edit=--edit
if test -z "${added[*]}${modified[*]}${deleted[*]}"; then
echo "No modified files" >&2
exit 1
fi
if test "$1" = "--no-edit"; then
edit=
fi
message=$tmpdir/message
echo >"$message"
for file in "${added[@]}" "${modified[@]}"; do
case "$file" in
config/*)
if [ -z "$configs_updated" ]; then
log_entry "Update config files." >>"$message"
configs_updated=1
fi
;;
patches.*)
patch_log_entry "$file" >>"$message"
;;
kabi/*/symvers-* | kabi/*/symtypes-* | kabi/*/symsets-* )
if [ -z "$symvers_updated" ]; then
log_entry "Update kabi files." >>"$message"
symvers_updated=1
fi
;;
series.conf)
# don't log changes in there
;;
*)
log_entry "$file: " >>"$message"
;;
esac
done
for file in "${deleted[@]}"; do
log_entry "Delete $file." >>"$message"
done
# If there is only one entry, remove the "-" bullet to make the git log
# prettier. If there are multiple entries, we give up, because
# scripts/gitlog2changes wouldn't know where to insert the bullets again
if test $(grep -c '^- ' "$message") = 1; then
sed -i 's/^[- ] //' "$message"
fi
if test -n "$edit" -a -e "$tmpdir/notice"; then
cat "$_" >>"$message"
fi
git commit "$@" -F $message $edit
}
# Check if series.conf contains only patch additions and print the
# added patches in order of appearance.
check_series_diff()
{
awk '
/^\+\+\+ / {
body = 1
next
}
!body || # ignore the patch header
/^[@ ]/ || # ignore line numbers and context
/^[-+][[:blank:]]*(#.*)?$/ { # ignore whitespace and comments
next
}
# added unguarded patches are OK
/^\+[[:blank:]]*patches\.[^[:blank:]]*\// {
print $2
next
}
# anything else is a problem
#{ print >"/dev/stderr" }
{ exit 1 }
'
}
# Check if only new patches are being added and nothing more
only_patches()
{
local file
if test "${modified[*]}" != "series.conf"; then
return 1
fi
if test -n "${deleted[*]}"; then
return 1
fi
for file in "${added[@]}"; do
case "$file" in
patches.*/*)
;;
*)
return 1
esac
done
git diff HEAD -- series.conf | check_series_diff >/dev/null || return
return 0
}
# Delete patches in $@ from series.conf.
filter_series()
{
local re
if test $# -eq 0; then
cat series.conf
return
fi
# escape BRE special characters and colon (used as delimiter)
set -- "${@//\\/\\\\}"
set -- "${@//./\\.}"
set -- "${@//\*/\\*}"
set -- "${@//\[/\\[}"
set -- "${@//\]/\\]}"
set -- "${@//^/\\^}"
set -- "${@//\$/\\\$}"
set -- "${@//:/\\:}"
re=$(printf '\\|%s' "$@")
re="${re:2}"
sed '\:^[[:space:]]*\('"$re"'\)[[:space:]]*\(#.*\)\?$: d' series.conf
}
# Commit patches one by one for better bisectability
commit_single_patches()
{
local saved_index=$(git write-tree) patch series
local added modified=() deleted=() no_edit
# reset the index
git read-tree HEAD
set -- $(git diff HEAD -- series.conf | check_series_diff)
if test $# -gt 1; then
# Fix the author date so that scripts/gitlog2changes can group
# the commits into a single rpm changelog entry
export GIT_AUTHOR_DATE=$(date -R)
for patch in "$@"; do
patch_log_entry "$patch"
done
read -p 'Commit with these changelog messages? [Yn] '
case "$REPLY" in
"" | [Yy] | [Yy][Ee][Ss])
no_edit=--no-edit
esac
fi
while test $# -gt 0; do
patch=$1
shift
# add a series.conf with a single new patch to the index
series=$(filter_series "$@" | git hash-object -w --stdin)
git read-tree $(git ls-tree HEAD | \
sed -r "s/(.*)\\<[0-9a-f]{40}\\>(.*\\<series\.conf)$/\1$series\2/" \
| git mktree)
git add "$patch"
added=("$patch")
if test $# -gt 0; then
cat >"$tmpdir/notice" <<EOF
# Patches are being committed one by one for better bisectability.
# There are $# more patches to commit.
EOF
else
rm -f "$tmpdir/notice"
fi
if ! do_commit $no_edit; then
# restore the index so that the user does not need to git add
# the patches again
git read-tree "$saved_index"
return 1
fi
done
}
if test -e "$(git rev-parse --git-dir)/MERGE_HEAD"; then
# Do not try to fabricate a commit message for merge commits, git itself
# does it better
git commit -a
exit
fi
added=($(git diff --name-only --diff-filter=A HEAD))
modified=($(git diff --name-only --diff-filter=MT HEAD))
deleted=($(git diff --name-only --diff-filter=D HEAD))
if only_patches; then
commit_single_patches || exit
else
# FIXME: -a should not be the default
do_commit -a || exit
fi
branch=$(get_branch_name)
case "$branch" in
master | preload | slert* | SL*_BRANCH | openSUSE-??.? | \
SLE?? | SLE??-SP? | SLE??-SP?-RT)
echo "after testing your changes, run"
echo " git push origin $branch"
esac
# vim: et:sts=4:sw=4
|