Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/bmake/import.sh
39478 views
1
#!/bin/sh
2
3
# Import bmake
4
5
ECHO=
6
GIT=${GIT:-git}
7
PAGER=${PAGER:-${LESS:-${MORE:-more}}}
8
9
# For consistency...
10
Error() {
11
echo ERROR: ${1+"$@"} >&2
12
exit 1
13
}
14
15
Cd() {
16
[ $# -eq 1 ] || Error "Cd() takes a single parameter."
17
cd $1 || Error "cannot \"cd $1\" from $PWD"
18
}
19
20
# Call this function and then follow it by any specific import script additions
21
option_parsing() {
22
local _shift=$#
23
# Parse command line options
24
while :
25
do
26
case "$1" in
27
*=*) eval "$1"; shift;;
28
--) shift; break;;
29
-a) TARBALL=$2; shift 2;;
30
-d) RM=echo; shift;;
31
-n) ECHO=echo; shift;;
32
-P) PR=$2; shift 2;;
33
-r) REVIEWER=$2; shift 2;;
34
-u) url=$2; shift 2;;
35
-h) echo "Usage:";
36
echo " "$0 '[-ahnPr] [TARBALL=] [PR=] [REVIEWER=]'
37
echo " "$0 '-a <filename> # (a)rchive'
38
echo " "$0 '-h # print usage'
39
echo " "$0 '-n # do not import, check only.'
40
echo " "$0 '-P <PR Number> # Use PR'
41
echo " "$0 '-r <reviewer(s) list> # (r)eviewed by'
42
echo " "$0 'PR=<PR Number>'
43
echo " "$0 'REVIEWER=<reviewer(s) list>'
44
exit 1;;
45
*) break;;
46
esac
47
done
48
return $(($_shift - $#))
49
}
50
51
###
52
53
option_parsing "$@"
54
shift $?
55
56
TF=/tmp/.$USER.$$
57
Cd `dirname $0`
58
test -s ${TARBALL:-/dev/null} || Error need TARBALL
59
here=`pwd`
60
SB=${SB:-`dirname $here`}
61
# thing should match what the TARBALL contains
62
thing=`basename $here`
63
64
case "$thing" in
65
bmake) (cd .. && tar zxf $TARBALL);;
66
*) Error "we should be in bmake";;
67
esac
68
69
VERSION=`grep '^_MAKE_VERSION' VERSION | sed 's,.*=[[:space:]]*,,'`
70
71
rm -f *~
72
mkdir -p $SB/tmp
73
74
# new files are handled automatically
75
# but we need to rm if needed
76
# FILES are kept sorted so we can determine what was added and deleted
77
# but we need to take care dealing with re-ordering
78
(${GIT} diff FILES | sed -n '/^[+-][^+-]/p'; \
79
${GIT} diff mk/FILES | sed -n '/^[+-][^+-]/s,.,&mk/,p' ) > $TF.diffs
80
grep '^+' $TF.diffs | sed 's,^.,,' | sort > $TF.adds
81
grep '^-' $TF.diffs | sed 's,^.,,' | sort > $TF.rms
82
comm -13 $TF.adds $TF.rms > $TF.rm
83
84
post=$SB/tmp/bmake-post.sh
85
86
# this is similar to what generates the mail to bmake-announce
87
gen_import_F() {
88
echo Import bmake-$VERSION
89
echo
90
91
if [ -s $post ]; then
92
last=`sed -n '/ tag/s,.*/,bmake-,p' $post`
93
else
94
last="last import"
95
fi
96
echo Intersting/relevant changes since $last; echo
97
for C in ChangeLog */ChangeLog
98
do
99
$GIT diff --staged $C |
100
sed -n '/^@@/d;/^\+\+\+/d;/^\+/s,^.,,p' > $TF.C
101
test -s $TF.C || continue
102
echo
103
echo $C since $last
104
echo
105
cat $TF.C
106
done
107
}
108
109
if [ -z "$ECHO" ]; then
110
test -s $TF.rm && xargs rm -f < $TF.rm
111
$GIT add -A
112
gen_import_F > $SB/tmp/bmake-import.F
113
$GIT diff --staged > $SB/tmp/bmake-import.diff
114
$PAGER $SB/tmp/bmake-import.F $SB/tmp/bmake-import.diff
115
{ echo "$GIT tag -a -m \"Tag bmake/$VERSION\" vendor/NetBSD/bmake/$VERSION"
116
echo "echo \"When ready do: $GIT push --follow-tags\""
117
} > $post
118
echo "Edit $SB/tmp/bmake-import.F as needed, then:"
119
echo "$GIT commit -F $SB/tmp/bmake-import.F"
120
echo "After you commit, run $post"
121
else
122
comm -23 $TF.adds $TF.rms > $TF.add
123
test -s $TF.rm && { echo Removing:; cat $TF.rm; }
124
test -s $TF.add && { echo Adding:; cat $TF.add; }
125
$GIT diff
126
fi
127
${RM:-rm} -f $TF.*
128
129