xref: /freebsd/contrib/bmake/import.sh (revision 2e3f49888ec8851bafb22011533217487764fdb0)
1#!/bin/sh
2
3# Import bmake
4
5ECHO=
6GIT=${GIT:-git}
7PAGER=${PAGER:-${LESS:-${MORE:-more}}}
8
9# For consistency...
10Error() {
11    echo ERROR: ${1+"$@"} >&2
12    exit 1
13}
14
15Cd() {
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
21option_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
53option_parsing "$@"
54shift $?
55
56TF=/tmp/.$USER.$$
57Cd `dirname $0`
58test -s ${TARBALL:-/dev/null} || Error need TARBALL
59here=`pwd`
60SB=${SB:-`dirname $here`}
61# thing should match what the TARBALL contains
62thing=`basename $here`
63
64case "$thing" in
65bmake) (cd .. && tar zxf $TARBALL);;
66*) Error "we should be in bmake";;
67esac
68
69VERSION=`grep '^_MAKE_VERSION' VERSION | sed 's,.*=[[:space:]]*,,'`
70
71rm -f *~
72mkdir -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
80grep '^+' $TF.diffs | sed 's,^.,,' | sort > $TF.adds
81grep '^-' $TF.diffs | sed 's,^.,,' | sort > $TF.rms
82comm -13 $TF.adds $TF.rms > $TF.rm
83
84post=$SB/tmp/bmake-post.sh
85
86# this is similar to what generates the mail to bmake-announce
87gen_import_F() {
88    echo Import bmake-$VERSION
89
90    if [ -s $post ]; then
91	last=`sed -n '/ tag/s,.*/,bmake-,p' $post`
92    else
93	last="last import"
94    fi
95    for C in ChangeLog */ChangeLog
96    do
97	$GIT diff --staged $C |
98	    sed -n '/^@@/d;/^\+\+\+/d;/^\+/s,^.,,p' > $TF.C
99	test -s $TF.C || continue
100	echo
101	echo $C since $last
102	echo
103	cat $TF.C
104    done
105}
106
107if [ -z "$ECHO" ]; then
108    test -s $TF.rm && xargs rm -f < $TF.rm
109    $GIT add -A
110    gen_import_F > $SB/tmp/bmake-import.F
111    $GIT diff --staged > $SB/tmp/bmake-import.diff
112    $PAGER $SB/tmp/bmake-import.F $SB/tmp/bmake-import.diff
113    { echo "$GIT tag -a -m \"Tag bmake/$VERSION\" vendor/NetBSD/bmake/$VERSION"
114      echo "echo \"When ready do: $GIT push --follow-tags\""
115    } > $post
116    echo "Edit $SB/tmp/bmake-import.F as needed, then:"
117    echo "$GIT commit -F $SB/tmp/bmake-import.F"
118    echo "After you commit, run $post"
119else
120    comm -23 $TF.adds $TF.rms > $TF.add
121    test -s $TF.rm && { echo Removing:; cat $TF.rm; }
122    test -s $TF.add && { echo Adding:; cat $TF.add; }
123    $GIT diff
124fi
125${RM:-rm} -f $TF.*
126