forked from markjdb/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmfctxt
executable file
·119 lines (106 loc) · 3.06 KB
/
mfctxt
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
#!/bin/sh
usage()
{
cat >&2 <<__EOF__
Usage: $(basename $0) [ -o outfile ] revision1 [ revision2 ] ...
Options:
-o outfile -- The file to which the MFC commit message should be
written. Defaults to ./mfc.txt.
revision -- A Subversion commit revision number corresponding to
a commit in HEAD. At least one revision must be
specified.
Environment variables:
SVNSRCBASE -- Root of a checkout of the FreeBSD Subversion repository.
Defaults to \${HOME}/src/freebsd-svn.
__EOF__
exit ${1-1}
}
log()
{
echo "$(basename $0): $1" >&2
}
REVS=
SVNSRCBASE=${SVNSRCBASE-${HOME}/src/freebsd-svn}
while [ $# -gt 0 ]; do
case $1 in
-h|--help)
usage 0
;;
-o)
shift; OUTF="$1"
;;
*)
if [ -z "$REVS" ]; then
REVS="$1"
else
REVS="$REVS $1"
fi
;;
esac
shift
done
OUTF=${OUTF-mfc.txt}
if [ -z "$REVS" ]; then
usage
elif ! which svn >/dev/null 2>&1; then
log "Subversion isn't installed. Exiting."
exit 1
elif [ -f "$OUTF" ] && ! [ -w "$OUTF" ]; then
log "Outfile '$OUTF' exists and isn't writable. Exiting."
exit 1
elif ! svn status "$SVNSRCBASE/head" >/dev/null 2>&1; then
log "Failed to access the FreeBSD Subversion repository. Exiting."
exit 1
fi
if [ -f "$OUTF" ]; then
backup=$(mktemp -t $(basename $0))
if [ -z "$backup" ]; then
log "Failed to create temporary file. Exiting."
exit 1
fi
log "Warning: outfile '$OUTF' already exists. Backing it up to ${backup}."
cp -f "$OUTF" $backup
truncate -s 0 "$OUTF"
fi
TMPREVS=
for rev in $REVS; do
if ! expr $rev : r >/dev/null 2>&1; then
TMPREVS="$TMPREVS r${rev}"
else
TMPREVS="$TMPREVS $rev"
fi
done
REVS=$TMPREVS
if [ $(echo $REVS | awk '{print NF}') -gt 1 ]; then
echo "MFC ${REVS# *}." >> "$OUTF"
echo >> "$OUTF"
fi
for rev in $REVS; do
logf=$(mktemp -t $(basename $0))
if [ -z "$logf" ]; then
log "Failed to create a temporary file. Exiting."
rm -f "$OUTF"
exit 1
fi
svn log -r $rev "$SVNSRCBASE/head" > $logf 2>/dev/null
if [ $? -ne 0 ]; then
log "Warning: couldn't fetch log for revision '$rev', skipping."
rm -f $logf
continue
elif [ "$(wc -l $logf | awk '{print $1}')" = 1 ]; then
log "Warning: it looks like revision '$rev' belongs to another branch, skipping."
rm -f $logf
continue
fi
echo "MFC $rev:" >> "$OUTF"
cat $logf | sed -e 1,3d -e '$d' -e '/^Approved by:/d' \
-e '/^MFC after:/d' \
-e '/^PR:/d' \
-e '/^Reported by:/d' \
-e '/^Reviewed by:/d' \
-e '/^Sponsored by:/d' \
-e '/^Submitted by:/d' \
-e '/^Tested by:/d' >> "$OUTF"
rm -f $logf
done
sed -i '' '$d' "$OUTF"