blob: 873bb8dda9ec82057e7c3a750ee5f6613b62319c (
plain) (
blame)
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
|
#! /bin/bash
# This script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# See the COPYING and AUTHORS files for more details.
insert_line()
{
PATTERN="$1"
LINE="$2"
FILE="$3"
awk ' BEGIN { found=0; }
/'"$PATTERN"'/ {
print;
if (!found)
printf("%s\n", "'$LINE'");
found=1;
next;
}
{ print; }
' < "$FILE"
}
# extract the description from the top of a patch
# filter stdin
# collapse adjacent blank lines to a single blank line
# remove any lines that look like diffstat output
# stop output on encountering a line beginning with '---' (beginning of patch)
TMPFILE=`mktemp /tmp/xdtmp.XXXXXX` || exit 1
formail -kfcb -X 'From:' -X 'Subject:' |\
awk '
BEGIN { found_end=0; lastone="x"; }
/^ .* [|] +[0-9]+ [+-]+$/ {
#/* we found something like diffstat output... */
if (found_end == 1) {
/* we are past end of diffstat, let it pass */
print;
}
next;
}
/^ [1-9][0-9]* files changed/ {
#/* end of diffstat output, stop filtering diffstat */
found_end=1;
next;
}
/^--- / { exit; }
{
#/* collapse adjacent blank lines to 1 blank line */
if ( $0 == "" && lastone == "" )
next;
else
print;
lastone=$0;
}
' | awk '{ if ($0 == "" && FNR == 1) next; print; }' > "$TMPFILE"
descs=`head -10 $TMPFILE | grep -c '^[ ]*DESC[ ]*$'`
if [ "$descs" = "0" ]
then
# DESC is not 1st non blank line in the file
echo "DESC"
descs=0
fi
edescs=`grep -c '^EDESC$' "$TMPFILE"`
subjects=`grep -c '^[ ]*Subject[:]' "$TMPFILE"`
froms=`grep -c '^[ ]*From[:]' "$TMPFILE"`
if [ "$edescs" = "0" ]
then
if [ "$subjects" != "0" ]
then
insert_line '^Subject[:]' 'EDESC' "$TMPFILE"
else
if [ "$froms" != "0" ]
then
insert_line '^From[:]' 'EDESC' "$TMPFILE"
else
if [ "$descs" = "0" ]
then
# blank DESC line...
echo '(undescribed patch)'
echo EDESC
cat "$TMPFILE"
else
insert_line '^DESC$' "EDESC" "$TMPFILE"
fi
fi
fi
else
cat $TMPFILE
fi
|